std1.0.0-beta-7 SafeC docs

Module collections::queue

#include <std/collections/queue.h> source

Queue<T> (FIFO, circular buffer)

struct Queue<int> q = std::Queue::new();
q.enqueue(1); q.enqueue(2);
?int first = q.dequeue();   // 1
q.free();

Amortized O(1) enqueue/dequeue; the ring grows (doubling, power-of-two capacity) when full. front()/back() hand out '?&T' into the ring, valid until the next enqueue()/free().

A Queue owns its elements: it is a Drop type, and T may own something itself (String, Vec, ...). enqueue() takes the element by value (one it can't store is dropped), dequeue() moves it out, and clear()/drop() drop every element still queued.

Structs

Queue