CircularBuffer (CircularBuffer v0.4.0) View Source

Circular Buffer

When creating a circular buffer you must specify the max size:

cb = CircularBuffer.new(10)

CircularBuffers are implemented as Okasaki queues like Erlang's :queue module, but with additional optimizations thanks to the reduced set of operations.

Link to this section Summary

Types

t()

A circular buffer

Functions

Checks the buffer to see if its empty

Inserts a new item into the next location of the circular buffer

Creates a new circular buffer with a given size.

Returns the newest element in the buffer

Returns the oldest element in the buffer

Converts a circular buffer to a list. The list is ordered from oldest to newest elements based on their insertion order.

Link to this section Types

Specs

t()

A circular buffer

Link to this section Functions

Specs

empty?(t()) :: boolean()

Checks the buffer to see if its empty

Specs

insert(t(), any()) :: t()

Inserts a new item into the next location of the circular buffer

Specs

new(pos_integer()) :: t()

Creates a new circular buffer with a given size.

Specs

newest(t()) :: any()

Returns the newest element in the buffer

Specs

oldest(t()) :: any()

Returns the oldest element in the buffer

Specs

to_list(t()) :: list()

Converts a circular buffer to a list. The list is ordered from oldest to newest elements based on their insertion order.