Class: RedBlackTree::Node
- Inherits:
-
Object
- Object
- RedBlackTree::Node
- Includes:
- Comparable
- 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.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Needs to be implemented in a subclass of Node.
-
#initialize(data) ⇒ Node
constructor
A new instance of Node.
Constructor Details
#initialize(data) ⇒ Node
Returns a new instance of Node.
22 23 24 25 26 27 28 29 30 |
# File 'lib/red_black_tree/node.rb', line 22 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 |
Instance Attribute Details
#data ⇒ any (readonly)
Returns the data/value representing the node.
18 19 20 |
# File 'lib/red_black_tree/node.rb', line 18 def data @data 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.
35 36 37 |
# File 'lib/red_black_tree/node.rb', line 35 def <=> other raise NotImplementedError, "Comparable operator <=> must be implemented in subclass" end |