Class: Datadog::DI::SnapshotPruner::NodeQueue Private

Inherits:
Object
  • Object
show all
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

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.

Returns:

  • (Node, nil) —

    the removed object, nil when the queue is empty



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.

Parameters:

  • node (Node) —

    the object to add



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.

Returns:

  • (Integer)


45
46
47
# File 'lib/datadog/di/snapshot_pruner/node_queue.rb', line 45

def size
  heap.size
end