datastructures v0.2.6 Data.Queue.Simple

A simple and performant queue.

Summary

Functions

Dequeue a value from the queue

Check if the queue is empty

Enqueue a value in the queue

Fold the queue from the left

Fold the queue from the right

Check if the the value is present in the queue

Creates an empty queue

Creates a new queue from the given enumerable

Peek the element that would be dequeued

Reverse the queue

Get the size of the queue

Convert the queue to a list

Types

t()
t
v()
v() :: any

Functions

clear()
clear(t) :: t
deq(simple)
deq(t) :: {:empty | {:value, v}, t}

Dequeue a value from the queue.

Examples

iex> T.new |> Data.Queue.enq(42) |> Data.Queue.enq(23) |> Data.Queue.deq
{42,#Queue<[23]>}
iex> T.new |> Data.Queue.deq(:empty)
{:empty,#Queue<[]>}
empty?(simple)
empty?(t) :: boolean

Check if the queue is empty.

enq(simple, value)
enq(t, v) :: t

Enqueue a value in the queue.

Examples

iex> T.new |> Data.Queue.enq(42) |> Data.Queue.enq(23) |> Data.Queue.enq(1337)
#Queue<[42,23,1337]>
foldl(simple, acc, fun)
foldl(t, any, (v, any -> any)) :: any

Fold the queue from the left.

foldr(simple, acc, fun)
foldr(t, any, (v, any -> any)) :: any

Fold the queue from the right.

member?(simple)

Check if the the value is present in the queue.

member?(simple, value)
member?(t, v) :: boolean
new()
new() :: t

Creates an empty queue.

new(enum)
new(Enum.t) :: t

Creates a new queue from the given enumerable.

Examples

iex> T.new(1 .. 4)
#Queue<[1,2,3,4]>
peek(simple)
peek(t) :: {:ok, any} | :error

Peek the element that would be dequeued.

Examples

iex> T.new |> Data.Queue.enq(42) |> Data.Queue.peek
42
iex> T.new |> Data.Queue.peek(:empty)
:empty
reverse(simple)
reverse(t) :: t

Reverse the queue.

Examples

iex> T.new(1 .. 4) |> Data.Queue.reverse
#Queue<[4,3,2,1]>
size(simple)
size(t) :: non_neg_integer

Get the size of the queue.

to_list(simple)
to_list(t) :: [v]

Convert the queue to a list.