class PairingHeap::SafeChangePriorityQueue

Priority queue with change_priority, that accepts changing to a less prioritary priority

Public Instance Methods

change_priority(elem, priority) click to toggle source

Changes a priority of the element

Time Complexity: O(N)
Amortized Time Complexity: O(log(N))

@raise [ArgumentError] if the element is not in the heap @return [self]

# File lib/pairing_heap.rb, line 475
def change_priority(elem, priority)
  raise ArgumentError, "Provided element is not in heap" unless @nodes.key?(elem)
  if !@order[priority, @nodes[elem].priority]
    delete(elem)
    push(elem, priority)
  else
    super(elem, priority)
  end
end