Module: collections.queue
Source: ./collections/queue.reef
Overview
collections/queue - Generic Queue[T] collection (FIFO)
Provides a first-in, first-out queue with generic type support. Implemented as a circular buffer for efficient operations. Capacity grows automatically on enqueue when full (double capacity, min 1): elements are linearized into a new array with head=0. enqueue returns true on success; false only on hard failure — not "full".
Usage: let q: Queue[int] = create_int_queue() enqueue[:int](q, 42) let value = dequeue:int // Some(42) -- no annotation needed, infers Option[int]
Types
Queue
Queue data structure - circular buffer implementation
Fields:
| Name | Type |
|---|---|
items |
[T] |
head |
int |
tail |
int |
size |
int |
cap |
int |
Functions
fn enqueue(q: Queue[T], item: T): bool
Adds an item to the back of the queue. Auto-grows when full. Returns true on success (false only on hard failure).
fn dequeue(q: Queue[T]): option.Option[T]
Removes and returns the front item from the queue Returns Some(elem) if non-empty, None if empty.
fn queue_peek(q: Queue[T]): option.Option[T]
Returns the front item without removing it Returns Some(elem) if non-empty, None if empty.
fn queue_size(q: Queue[T]): int
Returns the number of items in the queue
fn queue_capacity(q: Queue[T]): int
Returns the capacity of the queue
fn queue_is_empty(q: Queue[T]): bool
Returns true if the queue is empty
fn queue_is_full(q: Queue[T]): bool
Returns true if the queue is full
fn queue_to_array(q: Queue[T], arr: [T], max: int): int
Copies queue elements to an array (front to back order) Returns the number of elements copied
fn create_int_queue(): Queue[int]
Creates an empty int queue with capacity 16
fn create_string_queue(): Queue[string]
Creates an empty string queue with capacity 16
fn create_float_queue(): Queue[float]
Creates an empty float queue with capacity 16
fn create_bool_queue(): Queue[bool]
Creates an empty bool queue with capacity 16
fn create_int_queue_cap(cap: int): Queue[int]
Creates an int queue with specified capacity (8, 16, 32, or 64)
Procedures
proc grow_queue(q: Queue[T])
Grow backing storage to at least 2x current capacity (min 1). Linearizes the ring buffer into [0..size) with head=0, tail=size.
proc queue_clear(q: Queue[T])
Clears all items from the queue
Generated by reefc doc