Okasaki.Deque (Okasaki v1.0.1) View Source

Public interface to work with double-ended queue-like structures.

Link to this section Summary

Functions

Returns a new empty deque.

True if the deque does not contain any elements.

Inserts a new element into the leftmost ('front') end of the deque. Returns the new deque.

Inserts a new element into the rightmost ('back') end of the deque. Returns the new deque.

Checks if item is one of the elements inside of deque.

Createas a new deque.

Attempts to remove the leftmost ('front') element of the deque

Attempts to remove the rightmost ('back') element of the deque

Returns the number of elements inside the deque. For most deque implementations, this is a O(1) procedure, because the size is explicitly kept.

A function to remove elements from the front of a deque, until the function returns false.

Transforms the deque into a list.

Link to this section Functions

Returns a new empty deque.

Optionally, the implementation: SomeModuleName can be passed. (See the list of implementations in the module documentation of the Okasaki module.)

This can also be overridden on an application-wide level, by the configuration:

config :okasaki, default_deque_implementation: Deque.Implementation.Module.Name

By default, Okasaki.Implementations.ConstantDeque is used.

True if the deque does not contain any elements.

Link to this function

insert_left(deque, item)

View Source

Inserts a new element into the leftmost ('front') end of the deque. Returns the new deque.

Link to this function

insert_right(deque, item)

View Source

Inserts a new element into the rightmost ('back') end of the deque. Returns the new deque.

Checks if item is one of the elements inside of deque.

Uses Erlang's built-in structural term comparison.

Link to this function

new(enumerable \\ [], opts \\ [])

View Source

Createas a new deque.

The first parameter is an enumerable that the deque will be filled with. The second parameter is a list of options, which are the same as empty/1 expects.

Attempts to remove the leftmost ('front') element of the deque:

  • Returns {:error, :empty} if the deque is empty.
  • Returns {:ok, {item, deque_without_item}} if it succeeded.

Attempts to remove the rightmost ('back') element of the deque:

  • Returns {:error, :empty} if the deque is empty.
  • Returns {:ok, {item, deque_without_item}} if it succeeded.

Returns the number of elements inside the deque. For most deque implementations, this is a O(1) procedure, because the size is explicitly kept.

A function to remove elements from the front of a deque, until the function returns false.

Then, returns {list_of_removed_items, rest_of_deque}

In contrast to Enum.split_while, the unused rest of the deque is not suddenly transformed into a list, but is still a deque.

Transforms the deque into a list.