PQueue2 v0.4.1 PQueue2 View Source
Priority queue that wraps pqueue2.
iex> {value, _} = PQueue2.new
iex> |> PQueue2.put(:a, 2)
iex> |> PQueue2.put(:b, 1)
iex> |> PQueue2.put(:c, 1)
iex> |> PQueue2.pop
iex> value
:b
PQueue2 implements Collectable & Enumerable.
iex> [{:a, 2}, {:b, 1}, {:c, 1}, {:d, 2}] |> Enum.into(PQueue2.new) |> Enum.to_list
[:b, :c, :a, :d]
Link to this section Summary
Functions
Create a new priority queue.
Pop the max value.
Pop the first value at the priority.
Pop the max value & priority.
Put the value.
Link to this section Types
Link to this section Functions
Create a new priority queue.
Pop the max value.
iex> PQueue2.new |> PQueue2.put(:a, 2) |> PQueue2.put(:b, 1) |> PQueue2.pop
{:b, %PQueue2{pq: {2, :empty, :empty, :element, :a}}}
iex> PQueue2.pop PQueue2.new
{nil, %PQueue2{pq: :empty}}
iex> PQueue2.pop PQueue2.new, :empty
{:empty, %PQueue2{pq: :empty}}
Link to this function
pop_at(queue, priority, default \\ nil)
View Sourcepop_at(t(), non_neg_integer(), term()) :: {term(), t()}
Pop the first value at the priority.
iex> PQueue2.new |> PQueue2.put(:a, 2) |> PQueue2.put(:b, 1) |> PQueue2.pop_at(2)
{:a, %PQueue2{pq: {1, :empty, :empty, :element, :b}}}
iex> PQueue2.new |> PQueue2.put(:a, 2) |> PQueue2.put(:b, 1) |> PQueue2.pop_at(3)
{nil, %PQueue2{pq: {1, :empty, {2, :empty, :empty, :element, :a}, :element, :b}}}
Pop the max value & priority.
iex> PQueue2.new |> PQueue2.put(:a, 2) |> PQueue2.put(:b, 1) |> PQueue2.pop_with_priority
{{:b, 1}, %PQueue2{pq: {2, :empty, :empty, :element, :a}}}
Link to this function
put(queue, value, priority \\ 0)
View Sourceput(t(), term(), non_neg_integer()) :: t()
Put the value.