datastructures v0.1.1 Data.Queue.Simple

A simple and performant queue.

Summary

Functions

Dequeue a value from the queue

Dequeue a value from the queue, raising if it's empty

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

Peek the element that should be dequeued, raising if it's empty

Reverse the queue

Get the size of the queue

Convert the queue to a list

Types

t
v :: any

Functions

clear()

Specs

clear(t) :: t
deq(queue, default \\ nil)

Specs

deq(t, v) :: {v, t}

Dequeue a value from the queue.

Examples

iex> Data.Queue.Simple.new |> Data.Queue.enq(42) |> Data.Queue.enq(23) |> Data.Queue.deq
{42,#Queue<[23]>}
iex> Data.Queue.Simple.new |> Data.Queue.deq(:empty)
{:empty,#Queue<[]>}
deq!(queue)

Specs

deq!(t) :: {v, t} | no_return

Dequeue a value from the queue, raising if it's empty.

Examples

iex> Data.Queue.Simple.new |> Data.Queue.enq(42) |> Data.Queue.deq!
{42,#Queue<[]>}
iex> Data.Queue.Simple.new |> Data.Queue.deq!
** (Data.Error.Empty) the queue is empty
empty?(simple)

Specs

empty?(t) :: boolean

Check if the queue is empty.

enq(simple, value)

Specs

enq(t, v) :: t

Enqueue a value in the queue.

Examples

iex> Data.Queue.Simple.new |> Data.Queue.enq(42) |> Data.Queue.enq(23) |> Data.Queue.enq(1337)
#Queue<[42,23,1337]>
foldl(simple, acc, fun)

Specs

foldl(t, any, (v, any -> any)) :: any

Fold the queue from the left.

foldr(simple, acc, fun)

Specs

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)

Specs

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

Specs

new :: t

Creates an empty queue.

new(enum)

Specs

new(Enum.t) :: t

Creates a new queue from the given enumerable.

Examples

iex> Data.Queue.Simple.new(1 .. 4)
#Queue<[1,2,3,4]>
peek(queue, default \\ nil)

Specs

peek(t, v) :: v

Peek the element that would be dequeued.

Examples

iex> Data.Queue.Simple.new |> Data.Queue.enq(42) |> Data.Queue.peek
42
iex> Data.Queue.Simple.new |> Data.Queue.peek(:empty)
:empty
peek!(queue)

Specs

peek!(t) :: v | no_return

Peek the element that should be dequeued, raising if it's empty.

Examples

iex> Data.Queue.Simple.new |> Data.Queue.enq(42) |> Data.Queue.enq(23) |> Data.Queue.peek!
42
iex> Data.Queue.Simple.new |> Data.Queue.peek!
** (Data.Error.Empty) the queue is empty
reverse(simple)

Specs

reverse(t) :: t

Reverse the queue.

Examples

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

Specs

size(t) :: non_neg_integer

Get the size of the queue.

to_list(simple)

Specs

to_list(t) :: [v]

Convert the queue to a list.