Leftist heap in Elixir
Version 2.0.0 diverges from 1.x in that all values provided to the heap must now be 2-tuples. The first element of the tuple is used as the 'value' of the second element in the tree.
iex()> h = LHeap.new(%{1 => "one", 2 => "two"})
{{1, {1, "one"}}, {{1, {2, "two"}}, {}, {}}, {}}
iex()> h1 = LHeap.merge(h, LHeap.new(%{2 => "new-two", 3 => "new-three"}))
{{2, {1, "one"}}, {{1, {2, "two"}}, {}, {}},
{{1, {2, "new-two"}}, {{1, {3, "new-three"}}, {}, {}}, {}}}
iex()> LHeap.sort(h1)
[{1, "one"}, {2, "new-two"}, {3, "new-three"}]
iex()> LHeap.min(h1)
{1, "one"}
In your mix.exs:
defp deps do
[
{:lheap, "~> 2.0.0"}
]
endThen run mix deps.get.
Documentation is available in HexDocs.
Creates a new empty heap. When given an enumerable, it will populate the new heap with it.
Puts a new value in a heap.
Returns the minimum element of a heap.
Removes the minimum element from a heap.
Merges two heaps.
Sorts the given heap and returns a list.
MIT © Juan Soto, Simon Zelazny