← Standard library

Stack

sealed class Stack<T>
import Stack from Wax;

A last-in, first-out collection.

Stack.wax:14

Inherits from object. Follow these links for inherited members.

Members

constructorconstructor

public constructor ()

Creates an empty collection. No elements are inserted.

Stack.wax:21

WithCapacityconstructor

public constructor WithCapacity (int32 capacity)

Creates an empty collection with reserved storage. Capacity reservation does not change the element count.

Stack.wax:29

sizegetter

public get size() : int32

The number of live elements.

Stack.wax:36

capacitygetter

public get capacity() : int32

The number of elements the current backing storage can hold before growth.

Stack.wax:43

EnsureCapacitymethod

public fn EnsureCapacity(int32 capacity) : void

Grows storage if needed to hold at least the requested total element count. Does not shrink storage or insert elements.

Stack.wax:51

EnsureAdditionalCapacitymethod

public fn EnsureAdditionalCapacity(int32 additional) : void

Reserves space for the current element count plus additional. Does not insert elements.

Stack.wax:58

Pushmethod

public fn Push(T item) : void

Appends an item at the top, growing storage when necessary.

Stack.wax:65

Popmethod

public fn Pop() : T

Removes and returns the most recently pushed item. Panics when empty.

Stack.wax:74

TryPopmethod

public fn TryPop(out T? item) : bool

Returns true and removes the top item, including a stored null. When empty, returns false and writes null to the output.

Stack.wax:86

PopOrNullmethod

public fn PopOrNull() : T?

Removes and returns the top item, or null if empty. A popped null is indistinguishable from an empty stack; use TryPop when that distinction matters.

Stack.wax:100

Peekmethod

public fn Peek() : T

Returns the most recently pushed item without removing it. Panics when empty.

Stack.wax:110

Clearmethod

public fn Clear() : void

Removes all live items while keeping capacity.

Stack.wax:117

ToSpanmethod

public fn ToSpan() : Span<T>

Borrows the current elements in bottom-to-top order. Writes affect the stack storage. The view does not follow reallocation or later size changes.

Stack.wax:125

ToReadOnlySpanmethod

public fn ToReadOnlySpan() : ReadOnlySpan<T>

Borrows the current elements in bottom-to-top order without writes through this view. It still observes mutations through other aliases.

Stack.wax:133

ToArraymethod

public fn ToArray() : T[]

Returns a separate array snapshot in bottom-to-top order. Reference elements still point to the same objects.

Stack.wax:141

Containsmethod

public fn Contains(T item) : bool where T is Equatable

Scans live elements using Equals; returns false for an empty collection.

Stack.wax:148