bheap v1.0.0 BHeap
Binomial heaps in Elixir.
For general information about them, see Wikipedia.
The collection of binomial trees satisfies the following conditions:
- Each binomial tree in a heap obeys the minimum-heap property: the key of a node is greater than or equal to the key of its parent
- There can only be either one or zero binomial trees for each order, including zero order
Summary
Functions
Merges two heaps
Returns the minimum element of a heap
Creates a new heap
Creates a new heap from a given enumerable
Puts a new value in a heap
Removes the minimum element from a heap
Sorts the given heap and returns a list
Functions
Merges two heaps.
Example
iex> heap1 = BHeap.new([2, 4, 6])
iex> heap2 = BHeap.new([1, 3, 5])
iex> BHeap.merge(heap1, heap2)
[{1, 5, [{0, 6, []}]}, {2, 1, [{1, 2, [{0, 4, []}]}, {0, 3, []}]}]
Puts a new value in a heap.
Example
iex> BHeap.new() |> BHeap.put(1) |> BHeap.put(2)
[{1, 1, [{0, 2, []}]}]