class RBTree::Node

A node in the red-black tree.

Nodes should only be manipulated directly by the RedBlackTree class.

Attributes

color[RW]
key[RW]
left[RW]
parent[RW]
right[RW]
value[RW]

Public Class Methods

new(key, value, guard) click to toggle source

Creates a new node.

New tree nodes are red by default.

# File lib/rbtree/node.rb, line 19
def initialize(key, value, guard)
  @color = :red
  @key = key
  @value = value
  @left = @right = @parent = guard
end

Public Instance Methods

black?() click to toggle source

True for black nodes.

# File lib/rbtree/node.rb, line 27
def black?
  @color == :black
end
inspect() click to toggle source
# File lib/rbtree/node.rb, line 50
  def inspect
    <<ENDI
<RBTree::Node (#{@color}) #{@key.inspect} -> #{@value.inspect}
  Left: [#{@left.inspect.gsub!("\n", "\n  ")}]
  Right: [#{@right.inspect.gsub!("\n", "\n  ")}]>
ENDI
  end
red?() click to toggle source

True for red nodes.

# File lib/rbtree/node.rb, line 32
def red?
  @color == :red
end
to_a() click to toggle source

Returns an array of the node’s [key, value].

This method is used for nodes in a RBTree’s tree.

# File lib/rbtree/node.rb, line 39
def to_a
  [@key, @value]
end
to_single_a() click to toggle source

Returns an array of the node’s [key, first value].

This method is used for nodes in a MultiRBTree’s tree.

# File lib/rbtree/node.rb, line 46
def to_single_a
  [@key, @value.first]
end