Heap.LeftiestTree (Heap v0.1.0) View Source

A leftiest tree/heap implemtation with customizable priority and any type of item.

This tree always enforces the smallest priority at the top node, and the left path of tree is higher than right. See https://en.wikipedia.org/wiki/Leftist_tree for algorithm details.

Link to this section Summary

Functions

Returns true if the leftest tree is empty. NOTE: the nil is an empty leftest tree also.

Merges two leftiest trees into a leftiest tree.

Removes the topest node of tree, rebalances the tree, and returns. Do nothing if tree is empty.

Returns a single node leftest tree, with item and use this item as priority.

Returns a single node leftiest tree, with item and priority.

Returns the number of elements in tree.

Returns the list of %{priority: ..., item:, ...} ordered by priority descendingly.

Returns the top node of tree. If the tree is empty, returns {:error, "empty tree"} Else returns {:ok, %{priority: ..., item: ...}}

Link to this section Functions

Specs

empty?(atom() | %{:item => any(), optional(any()) => any()}) :: boolean()

Returns true if the leftest tree is empty. NOTE: the nil is an empty leftest tree also.

Merges two leftiest trees into a leftiest tree.

Removes the topest node of tree, rebalances the tree, and returns. Do nothing if tree is empty.

Specs

single(any()) :: %Heap.LeftiestTree{
  item: any(),
  left: nil,
  priority: any(),
  right: nil,
  s_value: 1
}

Returns a single node leftest tree, with item and use this item as priority.

Specs

single(any(), any()) :: %Heap.LeftiestTree{
  item: any(),
  left: nil,
  priority: any(),
  right: nil,
  s_value: 1
}

Returns a single node leftiest tree, with item and priority.

Returns the number of elements in tree.

Returns the list of %{priority: ..., item:, ...} ordered by priority descendingly.

Returns the top node of tree. If the tree is empty, returns {:error, "empty tree"} Else returns {:ok, %{priority: ..., item: ...}}