Class: RBTree::NodePool Private

Inherits:
NodeAllocator
  • 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 pool for RBTree.

Manages recycling of Node objects to reduce object allocation overhead.

Since:

  • 0.1.0

Direct Known Subclasses

AutoShrinkNodePool

Instance Method Summary collapse

Constructor Details

#initializeNodePool

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 a new instance of NodePool.

Since:

  • 0.1.0



2352
2353
2354
# File 'lib/rbtree.rb', line 2352

def initialize
  @pool = []
end

Instance Method Details

#allocate(key, value, color, left, right, parent) ⇒ 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.

Allocates a new node or recycles one from the pool.

Parameters:

  • key (Object)

    the key

  • value (Object)

    the value

  • color (Boolean)

    the color (true=red, false=black)

  • left (Node)

    the left child

  • right (Node)

    the right child

  • parent (Node)

    the parent node

Since:

  • 0.1.0



2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
# File 'lib/rbtree.rb', line 2364

def allocate(key, value, color, left, right, parent)
  node = @pool.pop
  if node
    node.key = key
    node.value = value
    node.color = color
    node.left = left
    node.right = right
    node.parent = parent
    node
  else
    super
  end
end

#release(node) ⇒ 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.

Releases a node back to the pool.

Parameters:

  • node (Node)

    the node to release

Since:

  • 0.1.0



2382
2383
2384
2385
# File 'lib/rbtree.rb', line 2382

def release(node)
  node.left = node.right = node.parent = node.value = node.key = nil
  @pool << node
end