elixir_ds v0.1.0 ElixirDS.Deque View Source

Double Ended Queue.

Supports O(1) (amortized) insertions and deletions at both ends

TODO: Add usage instructions

API
  • [x] new()
  • [x] from_list(lst)
  • [x] is_empty(q)
  • [x] size(q)
  • [x] push_front(q, elem)
  • [x] push_back(q, elem)
  • [x] pop_front(q)
  • [x] pop_back(q)
  • [x] peek_front(q)
  • [x] peek_back(q)
  • [x] rotate(q, n)

Link to this section Summary

Functions

Create a new deque from a list

Is the deque empty?

Create a new deque

Peek the last element in the queue

Peek the first element in the queue

Removes the value at the back of the deque and retuns the value and the updated deque

Removes the value at the front of the deque and retuns the value and the updated deque

Insert a value at the back of the deque

Insert a value at the front of the deque

Rotates the list by n elements (front to back). In case n is negative, moves the items in the other direction

Get the number of elements in the deque

Link to this section Types

Link to this type

t() View Source
t() :: %ElixirDS.Deque{back: list(), front: list()}

Link to this section Functions

Link to this function

from_list(lst) View Source
from_list(list()) :: t()

Create a new deque from a list.

Link to this function

is_empty?(dq) View Source
is_empty?(t()) :: boolean()

Is the deque empty?

Create a new deque.

Link to this function

peek_back(deque) View Source
peek_back(t()) :: :error | any()

Peek the last element in the queue.

This function does not modify the deque. In case the queue is empty, it will return an :error.

Link to this function

peek_front(deque) View Source
peek_front(t()) :: :error | any()

Peek the first element in the queue.

This function does not modify the deque. In case the queue is empty, it will return an :error.

Link to this function

pop_back(dq) View Source
pop_back(t()) :: {any(), t()} | :error

Removes the value at the back of the deque and retuns the value and the updated deque.

Link to this function

pop_front(dq) View Source
pop_front(t()) :: {any(), t()} | :error

Removes the value at the front of the deque and retuns the value and the updated deque.

Link to this function

push_back(dq, val) View Source
push_back(t(), any()) :: t()

Insert a value at the back of the deque.

Link to this function

push_front(dq, val) View Source
push_front(t(), any()) :: t()

Insert a value at the front of the deque.

Link to this function

rotate(dq, n) View Source
rotate(t(), integer()) :: t()

Rotates the list by n elements (front to back). In case n is negative, moves the items in the other direction

Get the number of elements in the deque.