View Source Qu.Circular (qu v0.1.0)

Circular queue implementation.

A circular queue is implemented by delegating to FIFO, but with a change to the logic of how items are inserted. When inserting into a circular queue, if the circular queue is full, the head is first popped before new item is inserted.

Summary

Types

@type item() :: any()
@type max_size() :: pos_integer() | nil
@type size() :: non_neg_integer()
@type t() :: %Qu.Circular{
  max_size: max_size(),
  read: [item()],
  size: non_neg_integer(),
  write: [item()]
}

Functions

@spec new(max_size()) :: t()
@spec peek(t()) :: {:ok, item()} | :error
@spec pop(t()) :: {:ok, item(), t()} | :error
@spec put(t(), item()) :: {:ok, t()} | :error
@spec put(t(), item()) :: {:ok, t()} | :error
@spec size(t()) :: size()