Class: Xunch::RBTree::Node
- Inherits:
-
Object
- Object
- Xunch::RBTree::Node
- Defined in:
- lib/xunch/utils/rb_tree_node.rb
Overview
A node in the red-black tree.
Nodes should only be manipulated directly by the RedBlackTree class.
Instance Attribute Summary collapse
-
#color ⇒ Object
Returns the value of attribute color.
-
#key ⇒ Object
Returns the value of attribute key.
-
#left ⇒ Object
Returns the value of attribute left.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#right ⇒ Object
Returns the value of attribute right.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#black? ⇒ Boolean
True for black nodes.
-
#initialize(key, value, parent) ⇒ Node
constructor
Creates a new node.
- #inspect ⇒ Object
-
#red? ⇒ Boolean
True for red nodes.
-
#to_s ⇒ Object
node to string.
Constructor Details
#initialize(key, value, parent) ⇒ Node
Creates a new node.
New tree nodes are red by default.
20 21 22 23 24 25 |
# File 'lib/xunch/utils/rb_tree_node.rb', line 20 def initialize(key, value, parent) @color = :black @key = key @value = value @parent = parent end |
Instance Attribute Details
#color ⇒ Object
Returns the value of attribute color.
12 13 14 |
# File 'lib/xunch/utils/rb_tree_node.rb', line 12 def color @color end |
#key ⇒ Object
Returns the value of attribute key.
9 10 11 |
# File 'lib/xunch/utils/rb_tree_node.rb', line 9 def key @key end |
#left ⇒ Object
Returns the value of attribute left.
13 14 15 |
# File 'lib/xunch/utils/rb_tree_node.rb', line 13 def left @left end |
#parent ⇒ Object
Returns the value of attribute parent.
15 16 17 |
# File 'lib/xunch/utils/rb_tree_node.rb', line 15 def parent @parent end |
#right ⇒ Object
Returns the value of attribute right.
14 15 16 |
# File 'lib/xunch/utils/rb_tree_node.rb', line 14 def right @right end |
#value ⇒ Object
Returns the value of attribute value.
10 11 12 |
# File 'lib/xunch/utils/rb_tree_node.rb', line 10 def value @value end |
Instance Method Details
#black? ⇒ Boolean
True for black nodes.
37 38 39 |
# File 'lib/xunch/utils/rb_tree_node.rb', line 37 def black? @color == :black end |
#inspect ⇒ Object
32 33 34 |
# File 'lib/xunch/utils/rb_tree_node.rb', line 32 def inspect "#{@key}=#{@value},#{@color}" end |
#red? ⇒ Boolean
True for red nodes.
42 43 44 |
# File 'lib/xunch/utils/rb_tree_node.rb', line 42 def red? @color == :red end |
#to_s ⇒ Object
node to string
28 29 30 |
# File 'lib/xunch/utils/rb_tree_node.rb', line 28 def to_s "#{@key}=#{@value},#{@color}" end |