Class: PairingHeap::SafeChangePriorityQueue
- Inherits:
-
PairingHeap
- Object
- PairingHeap
- PairingHeap::SafeChangePriorityQueue
- Defined in:
- lib/pairing_heap.rb
Overview
Priority queue with change_priority, that accepts changing to a less prioritary priority
Instance Method Summary collapse
-
#change_priority(elem, priority) ⇒ self
Changes a priority of the element Time Complexity: O(N) Amortized Time Complexity: O(log(N)).
Methods inherited from PairingHeap
#any?, #delete, #each, #each_with_priority, #empty?, #get_priority, #get_priority_if_exists, #include?, #initialize, #peek, #peek_priority, #peek_with_priority, #pop, #pop_priority, #pop_with_priority, #push, #size
Constructor Details
This class inherits a constructor from PairingHeap::PairingHeap
Instance Method Details
#change_priority(elem, priority) ⇒ self
Changes a priority of the element
Time Complexity: O(N)
Amortized Time Complexity: O(log(N))
505 506 507 508 509 510 511 512 513 |
# File 'lib/pairing_heap.rb', line 505 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 |