Class: RBTree::NodePool Private
- Inherits:
-
NodeAllocator
- Object
- NodeAllocator
- RBTree::NodePool
- 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.
Direct Known Subclasses
Instance Method Summary collapse
-
#allocate(key, value, color, left, right, parent) ⇒ Object
private
Allocates a new node or recycles one from the pool.
-
#initialize ⇒ NodePool
constructor
private
A new instance of NodePool.
-
#release(node) ⇒ Object
private
Releases a node back to the pool.
Constructor Details
#initialize ⇒ NodePool
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.
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.
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.
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 |