Stack
sealed class Stack<T>import Stack from Wax;A last-in, first-out collection.
Inherits from object. Follow these links for inherited members.
Members
constructorconstructor
public constructor ()Creates an empty collection. No elements are inserted.
WithCapacityconstructor
public constructor WithCapacity (int32 capacity)Creates an empty collection with reserved storage. Capacity reservation does not change the element count.
sizegetter
public get size() : int32The number of live elements.
capacitygetter
public get capacity() : int32The number of elements the current backing storage can hold before growth.
EnsureCapacitymethod
public fn EnsureCapacity(int32 capacity) : voidGrows storage if needed to hold at least the requested total element count. Does not shrink storage or insert elements.
EnsureAdditionalCapacitymethod
public fn EnsureAdditionalCapacity(int32 additional) : voidReserves space for the current element count plus additional. Does not insert elements.
Pushmethod
public fn Push(T item) : voidAppends an item at the top, growing storage when necessary.
Popmethod
public fn Pop() : TRemoves and returns the most recently pushed item. Panics when empty.
TryPopmethod
public fn TryPop(out T? item) : boolReturns true and removes the top item, including a stored null. When empty, returns false and writes null to the output.
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.
Peekmethod
public fn Peek() : TReturns the most recently pushed item without removing it. Panics when empty.
Clearmethod
public fn Clear() : voidRemoves all live items while keeping capacity.
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.
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.
ToArraymethod
public fn ToArray() : T[]Returns a separate array snapshot in bottom-to-top order. Reference elements still point to the same objects.
Containsmethod
public fn Contains(T item) : bool where T is EquatableScans live elements using Equals; returns false for an empty collection.