Class: Datadog::DI::SnapshotPruner::NodeQueue Private
- Inherits:
-
Object
- Object
- Datadog::DI::SnapshotPruner::NodeQueue
- Defined in:
- lib/datadog/di/snapshot_pruner/node_queue.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.
Priority queue of snapshot objects that yields the object with the greatest pruning priority first, implemented as a binary max-heap over an Array.
Instance Method Summary collapse
-
#initialize ⇒ void
constructor
private
Initializes an empty queue.
-
#pop ⇒ Node?
private
Removes the object with the greatest priority.
-
#push(node) ⇒ void
private
Adds an object to the queue.
-
#size ⇒ Integer
private
Returns the number of queued objects.
Constructor Details
#initialize ⇒ void
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.
Initializes an empty queue.
15 16 17 |
# File 'lib/datadog/di/snapshot_pruner/node_queue.rb', line 15 def initialize @heap = [] end |
Instance Method Details
#pop ⇒ 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.
Removes the object with the greatest priority.
32 33 34 35 36 37 38 39 40 |
# File 'lib/datadog/di/snapshot_pruner/node_queue.rb', line 32 def pop last = heap.pop return last if last.nil? || heap.empty? top = heap.first heap[0] = last sift_down(0) top end |
#push(node) ⇒ void
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.
This method returns an undefined value.
Adds an object to the queue.
23 24 25 26 27 |
# File 'lib/datadog/di/snapshot_pruner/node_queue.rb', line 23 def push(node) heap << node sift_up(heap.size - 1) nil end |
#size ⇒ Integer
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 number of queued objects.
45 46 47 |
# File 'lib/datadog/di/snapshot_pruner/node_queue.rb', line 45 def size heap.size end |