Module: collections.stack
Source: ./collections/stack.reef
Overview
collections/stack — Stack[T], LIFO, method API.
Collections 0.9.2 / D11. Stack and Queue stay DISTINCT types with their own backing (Queue is a ring buffer, which a Vec is not), but both lose the free-function API and the per-type factories.
Usage: import collections.stack import core.option as option let s = stack.create:int s.push(1) match s.pop() Option_Some(v) => println("${v}") end Option_None() => println("empty") end end match
DROPPED (D11): is_full() — it only ever meant "the backing array is full before the next grow", which is an implementation detail, not a property of a stack that grows. stack_to_array(arr, max) — the fill-into-out-param shape: the caller pre-allocated, passed a max, and was told how many it got. to_array() returns a copy sized to len. the stack_ prefixes — the receiver is already a Stack. per-type factories (create_int_stack and friends).
Factories: createT -> Stack[T], capacity 16 create_with_capacityT -> Stack[T]; n < 1 clamps to 1 (BUG-062)
Methods: push(value) - proc; auto-grows pop(): option.Option[T] - None if empty peek(): option.Option[T] - None if empty len() / capacity() / is_empty() / clear() to_array(): [T] - bottom-to-top order, sized to len
Types
Stack
Fields:
| Name | Type |
|---|---|
items |
[T] |
top |
int |
cap |
int |
Functions
fn create(): Stack[T]
fn create_with_capacity(cap: int): Stack[T]
cap < 1 clamps to 1 (BUG-062): doubling from 0 stays 0, so an unclamped zero-capacity stack would never grow.
Generated by reefc doc