Class: RBTree::Node Private

Inherits:
Object
  • Object
show all
Defined in:
lib/rbtree.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Internal node structure for RBTree.

Each node stores a key-value pair, color (red or black), and references to parent, left child, and right child nodes.

Since:

  • 0.1.0

Constant Summary collapse

RED =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Red color constant (true)

Since:

  • 0.1.0

true
BLACK =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Black color constant (false)

Since:

  • 0.1.0

false

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key = nil, value = nil, color = BLACK, left = nil, right = nil, parent = nil) ⇒ Node

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Creates a new Node.

Parameters:

  • key (Object) (defaults to: nil)

    the key

  • value (Object) (defaults to: nil)

    the value

  • color (Boolean) (defaults to: BLACK)

    the color (true=red, false=black)

  • left (Node) (defaults to: nil)

    the left child

  • right (Node) (defaults to: nil)

    the right child

  • parent (Node) (defaults to: nil)

    the parent node

Since:

  • 0.1.0



2303
2304
2305
2306
2307
2308
2309
2310
# File 'lib/rbtree.rb', line 2303

def initialize(key = nil, value = nil, color = BLACK, left = nil, right = nil, parent = nil)
  @key = key
  @value = value
  @color = color
  @left = left
  @right = right
  @parent = parent
end

Instance Attribute Details

#colorSymbol

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the color of the node (:red or :black).

Returns:

  • (Symbol)

    the color of the node (:red or :black)

Since:

  • 0.1.0



2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
# File 'lib/rbtree.rb', line 2287

class RBTree::Node
  attr_accessor :key, :value, :color, :left, :right, :parent

  # Red color constant (true)
  RED = true
  # Black color constant (false)
  BLACK = false

  # Creates a new Node.
  #
  # @param key [Object] the key
  # @param value [Object] the value
  # @param color [Boolean] the color (true=red, false=black)
  # @param left [Node] the left child
  # @param right [Node] the right child
  # @param parent [Node] the parent node
  def initialize(key = nil, value = nil, color = BLACK, left = nil, right = nil, parent = nil)
    @key = key
    @value = value
    @color = color
    @left = left
    @right = right
    @parent = parent
  end

  # Returns the key-value pair.
  # @return [Array(Object, Object)] the key-value pair
  def pair = [key, value]
end

#keyObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the key stored in this node.

Returns:

  • (Object)

    the key stored in this node

Since:

  • 0.1.0



2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
# File 'lib/rbtree.rb', line 2287

class RBTree::Node
  attr_accessor :key, :value, :color, :left, :right, :parent

  # Red color constant (true)
  RED = true
  # Black color constant (false)
  BLACK = false

  # Creates a new Node.
  #
  # @param key [Object] the key
  # @param value [Object] the value
  # @param color [Boolean] the color (true=red, false=black)
  # @param left [Node] the left child
  # @param right [Node] the right child
  # @param parent [Node] the parent node
  def initialize(key = nil, value = nil, color = BLACK, left = nil, right = nil, parent = nil)
    @key = key
    @value = value
    @color = color
    @left = left
    @right = right
    @parent = parent
  end

  # Returns the key-value pair.
  # @return [Array(Object, Object)] the key-value pair
  def pair = [key, value]
end

#leftNode

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the left child node.

Returns:

  • (Node)

    the left child node

Since:

  • 0.1.0



2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
# File 'lib/rbtree.rb', line 2287

class RBTree::Node
  attr_accessor :key, :value, :color, :left, :right, :parent

  # Red color constant (true)
  RED = true
  # Black color constant (false)
  BLACK = false

  # Creates a new Node.
  #
  # @param key [Object] the key
  # @param value [Object] the value
  # @param color [Boolean] the color (true=red, false=black)
  # @param left [Node] the left child
  # @param right [Node] the right child
  # @param parent [Node] the parent node
  def initialize(key = nil, value = nil, color = BLACK, left = nil, right = nil, parent = nil)
    @key = key
    @value = value
    @color = color
    @left = left
    @right = right
    @parent = parent
  end

  # Returns the key-value pair.
  # @return [Array(Object, Object)] the key-value pair
  def pair = [key, value]
end

#parentNode

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the parent node.

Returns:

  • (Node)

    the parent node

Since:

  • 0.1.0



2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
# File 'lib/rbtree.rb', line 2287

class RBTree::Node
  attr_accessor :key, :value, :color, :left, :right, :parent

  # Red color constant (true)
  RED = true
  # Black color constant (false)
  BLACK = false

  # Creates a new Node.
  #
  # @param key [Object] the key
  # @param value [Object] the value
  # @param color [Boolean] the color (true=red, false=black)
  # @param left [Node] the left child
  # @param right [Node] the right child
  # @param parent [Node] the parent node
  def initialize(key = nil, value = nil, color = BLACK, left = nil, right = nil, parent = nil)
    @key = key
    @value = value
    @color = color
    @left = left
    @right = right
    @parent = parent
  end

  # Returns the key-value pair.
  # @return [Array(Object, Object)] the key-value pair
  def pair = [key, value]
end

#rightNode

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the right child node.

Returns:

  • (Node)

    the right child node

Since:

  • 0.1.0



2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
# File 'lib/rbtree.rb', line 2287

class RBTree::Node
  attr_accessor :key, :value, :color, :left, :right, :parent

  # Red color constant (true)
  RED = true
  # Black color constant (false)
  BLACK = false

  # Creates a new Node.
  #
  # @param key [Object] the key
  # @param value [Object] the value
  # @param color [Boolean] the color (true=red, false=black)
  # @param left [Node] the left child
  # @param right [Node] the right child
  # @param parent [Node] the parent node
  def initialize(key = nil, value = nil, color = BLACK, left = nil, right = nil, parent = nil)
    @key = key
    @value = value
    @color = color
    @left = left
    @right = right
    @parent = parent
  end

  # Returns the key-value pair.
  # @return [Array(Object, Object)] the key-value pair
  def pair = [key, value]
end

#valueObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the value stored in this node.

Returns:

  • (Object)

    the value stored in this node

Since:

  • 0.1.0



2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
# File 'lib/rbtree.rb', line 2287

class RBTree::Node
  attr_accessor :key, :value, :color, :left, :right, :parent

  # Red color constant (true)
  RED = true
  # Black color constant (false)
  BLACK = false

  # Creates a new Node.
  #
  # @param key [Object] the key
  # @param value [Object] the value
  # @param color [Boolean] the color (true=red, false=black)
  # @param left [Node] the left child
  # @param right [Node] the right child
  # @param parent [Node] the parent node
  def initialize(key = nil, value = nil, color = BLACK, left = nil, right = nil, parent = nil)
    @key = key
    @value = value
    @color = color
    @left = left
    @right = right
    @parent = parent
  end

  # Returns the key-value pair.
  # @return [Array(Object, Object)] the key-value pair
  def pair = [key, value]
end

Instance Method Details

#pairArray(Object, Object)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the key-value pair.

Returns:

  • (Array(Object, Object))

    the key-value pair

Since:

  • 0.1.0



2314
# File 'lib/rbtree.rb', line 2314

def pair = [key, value]