Class: RedBlackTree::Node
- Inherits:
-
Object
- Object
- RedBlackTree::Node
- Includes:
- Comparable, DataDelegation
- Defined in:
- lib/red_black_tree/node.rb,
lib/red_black_tree/node/left_right_element_referencers.rb
Instance Attribute Summary collapse
-
#data ⇒ any
readonly
The data/value representing the node.
-
#tree ⇒ RedBlackTree::Node?
readonly
The tree this node belongs to.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Needs to be implemented in a subclass of Node.
-
#initialize(data) ⇒ Node
constructor
A new instance of Node.
Methods included from DataDelegation
#method_missing, #respond_to_missing?
Constructor Details
#initialize(data) ⇒ Node
Returns a new instance of Node.
27 28 29 30 31 32 33 34 35 |
# File 'lib/red_black_tree/node.rb', line 27 def initialize data raise ArgumentError, "data cannot be nil" if data.nil? && !(instance_of? RedBlackTree::LeafNode) @data = data @colour = nil @parent = @left = @right = nil validate_free! end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class RedBlackTree::DataDelegation
Instance Attribute Details
#data ⇒ any (readonly)
Returns the data/value representing the node.
20 21 22 |
# File 'lib/red_black_tree/node.rb', line 20 def data @data end |
#tree ⇒ RedBlackTree::Node? (readonly)
Returns the tree this node belongs to.
23 24 25 |
# File 'lib/red_black_tree/node.rb', line 23 def tree @tree end |
Instance Method Details
#<=>(other) ⇒ Object
Needs to be implemented in a subclass of RedBlackTree::Node. Will be used to calculate the ideal position of this node when adding it to a tree.
40 41 42 |
# File 'lib/red_black_tree/node.rb', line 40 def <=> other raise NotImplementedError, "Comparable operator <=> must be implemented in subclass" end |