View Source Hold.BankersQueue (hold v0.1.0)

A double ended queue (deque) implementation.

Double ended queues optimize for adding items to one end of the queue and removing from the other - FIFO queues.

Summary

Functions

Removes first item in queue.

Add item to queue.

Create a new queue from a list keepin the same order of the original list; the head item of the list is the first item in the queue.

Create a new queue.

Types

@type sized_list() :: {length :: non_neg_integer(), []}
@type sized_list(a) :: {length :: non_neg_integer(), [a]}
@type t() :: {rear :: sized_list(), front :: sized_list()}
@type t(a) :: {rear :: sized_list(a), front :: sized_list(a)}

Functions

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

Removes first item in queue.

Returns {:value, {item, queu}} where item is what was removed and queue is the remaining queue. In cases where the queue is empty {:empty, queue} is retruned.

iex> queue = Hold.BankersQueue.new()
iex> queue = Hold.BankersQueue.enqueue(queue, 1)
iex> {:value, {1, queue}} = Hold.BankersQueue.dequeue(queue)
iex> Hold.BankersQueue.peek(queue)
:empty
@spec enqueue(t(), term()) :: t()

Add item to queue.

iex> queue = Hold.BankersQueue.new()
iex> queue = Hold.BankersQueue.enqueue(queue, 1)
iex> Hold.BankersQueue.peek(queue)
{:value, 1}
@spec from_list(list()) :: t()

Create a new queue from a list keepin the same order of the original list; the head item of the list is the first item in the queue.

iex> queue = Hold.BankersQueue.from_list([1, 2, 3, 4, 5])
iex> Hold.BankersQueue.peek(queue)
{:value, 1}
@spec new() :: t()

Create a new queue.