Module: collections.queue
Source: ./collections/queue.reef
Overview
collections/queue — Queue[T], FIFO ring buffer, method API.
Collections 0.9.2 / D11. Queue keeps its OWN backing rather than wrapping Vec: it is a circular buffer, so dequeue is O(1) instead of the O(n) shift a Vec-backed queue would pay. Growth linearizes the ring into [0..size) and then doubles.
Usage: import collections.queue import core.option as option let q = queue.create:string q.enqueue("boot") match q.dequeue() Option_Some(v) => println(v) end Option_None() => println("empty") end end match
DROPPED (D11): is_full() (it meant "full before the next grow", an implementation detail of a queue that grows), the queue_to_array(arr, max) out-param shape, the queue_ prefixes, and the per-type factories.
Factories: createT -> Queue[T], capacity 16 create_with_capacityT -> Queue[T]; n < 1 clamps to 1 (BUG-062)
Methods: enqueue(value) - proc; auto-grows dequeue(): option.Option[T] - None if empty peek(): option.Option[T] - None if empty len() / capacity() / is_empty() / clear() to_array(): [T] - front-to-back order, linearized
Types
Queue
Fields:
| Name | Type |
|---|---|
items |
[T] |
head |
int |
tail |
int |
size |
int |
cap |
int |
Functions
fn create(): Queue[T]
fn create_with_capacity(cap: int): Queue[T]
cap < 1 clamps to 1 (BUG-062): doubling from 0 stays 0, and the ring arithmetic divides by cap.
Generated by reefc doc