Quex (Quex v1.0.1)

View Source

Quex

Simple queue implementation, based on Erlang's queue module, which is an efficient implementation of double ended fifo queues

Differences between Quex and Erlang's queue module are a more Elixir friendly API (subject as first argument) and implementations of the Enumerable, Collectable and Inspect protocols.

Examples

iex> q = Quex.new |> Quex.put(1) |> Quex.put(2)
Quex.new([1, 2])
iex> Quex.pop(q)
{1, Quex.new([2])}

iex> Quex.new([1, 2, 3, 4]) |> Enum.take_while(&(&1 < 3))
[1, 2]

iex> for n <- 1..4, into: Quex.new(), do: n * n
Quex.new([1, 4, 9, 16])

Summary

Functions

Remove the first value from the front of the queue

Remove the last value from the rear of the queue

Converts Erlang's queue data type to a queue

Join two queues

Returns true if the given value exists in the queue

Creates a new empty queue

Creates a new queue from a list

Get the first value from the front of the queue without removing it

Get the last value from the rear of the queue without removing it

Pop the first value from the front of the queue

Pop the last value from the rear of the queue

Puts the given value at the end the queue

Puts the given value at the front of the queue

Returns the number of items in the queue

Converts a queue to Erlang's queue data type

Converts a queue to a list

Types

t()

@type t() :: %Quex{front: list(), rear: list()}

Functions

drop(queue)

@spec drop(t()) :: t() | :empty

Remove the first value from the front of the queue

Returns the rest of the queue or :empty if the queue has no items.

drop_rear(queue)

@spec drop_rear(t()) :: t() | :empty

Remove the last value from the rear of the queue

Returns the rest of the queue or :empty if the queue has no items.

from_erl(arg)

@spec from_erl({list(), list()}) :: t()

Converts Erlang's queue data type to a queue

join(q, q)

@spec join(t(), t()) :: t()

Join two queues

It effectively appends the second queue to the first queue.

member?(quex, item)

@spec member?(t(), term()) :: boolean()

Returns true if the given value exists in the queue

new()

@spec new() :: t()

Creates a new empty queue

new(items)

@spec new(list()) :: t()

Creates a new queue from a list

The first element in the list will be the front item of the queue.

peek(quex)

@spec peek(t()) :: {:ok, term()} | :empty

Get the first value from the front of the queue without removing it

Returns the {:ok, value} or :empty if the queue has no items.

peek_rear(quex)

@spec peek_rear(t()) :: {:ok, term()} | :empty

Get the last value from the rear of the queue without removing it

Returns the {:ok, value} or :empty if the queue has no items.

pop(queue)

@spec pop(t()) :: {term(), t()} | :empty

Pop the first value from the front of the queue

Returns the value as well the rest of the queue or :empty if the queue has no items.

pop_rear(queue)

@spec pop_rear(t()) :: {term(), t()} | :empty

Pop the last value from the rear of the queue

Returns the value as well the rest of the queue or :empty if the queue has no items.

put(queue, item)

@spec put(t(), term()) :: t()

Puts the given value at the end the queue

put_front(queue, item)

@spec put_front(t(), term()) :: t()

Puts the given value at the front of the queue

This means that it will be the first item in the queue to pop, peek, or drop.

size(quex)

@spec size(t()) :: non_neg_integer()

Returns the number of items in the queue

to_erl(quex)

@spec to_erl(t()) :: {list(), list()}

Converts a queue to Erlang's queue data type

to_list(quex)

@spec to_list(t()) :: list()

Converts a queue to a list

The front item of the queue will be the first element in the list.