priority_queue v1.0.0 PairingHeap
Pairing Heap implementation see:
http://en.wikipedia.org/wiki/Pairing_heap
A Pairing Heap is a type of heap structure with relatively simple implementation and excellent practical amortised performance.
Determining the precise asymptotic running time of pairing heaps has proved difficult, see the Wikipedia page referenced above for a more complete discussion. In particular practical performance of decrease-key is excellent (and initially conjectured to be O(1)), but at present it’s known to be “no worse” then O(log n). However, no tight bound is known.
Operation find-min: Θ(1) delete-min: Θ(log n) insert: Θ(1) decrease-key: Θ(log n) - however, tight bound not known merge: Θ(1)
Guts: pairing heaps A pairing heap is either nil or a term {key, value, [sub_heaps]} where sub_heaps is a list of heaps.
TODO: Allow the comparison function to be specified
Implement decrease_key
Summary
Functions
return the heap with the min item removed
True iff argument is an empty priority queue
Merge (meld) two heaps
Merge (meld) two heaps
min item in the heap
Create new empty heap. Optionally pass in initial key, value
Returns the min item, as well as the heap without the min item Equivalent to: {min(heap), delete_min(heap)}
Add element X to priority queue
Types
Functions
return the heap with the min item removed
iex> PairingHeap.new(1, "first") |> PairingHeap.delete_min |> PairingHeap.empty?
true
iex> PairingHeap.new(1, "first") |> PairingHeap.delete_min |> PairingHeap.delete_min |> PairingHeap.empty?
true
Specs
empty?(t) :: boolean
True iff argument is an empty priority queue
iex> PairingHeap.new |> PairingHeap.empty?
true
iex> PairingHeap.new(1, "first") |> PairingHeap.empty?
false
iex> PairingHeap.new(1, "first") |> PairingHeap.delete_min |> PairingHeap.empty?
true
Returns the min item, as well as the heap without the min item Equivalent to: {min(heap), delete_min(heap)}
iex> PairingHeap.new(1, "first") |> PairingHeap.pop |> elem(0)
{1, "first"}