UNPKG

rc-js-util

Version:

A collection of TS and C++ utilities to help writing performant and correct applications, achieved through strict typing and (removable) invariant checking.

58 lines 1.58 kB
import { IFIFOStack } from "./i-fifo-stack.js"; /** * @public * Sets the behavior of {@link CircularFIFOStack} when a value is pushed which won't fit. * * @remarks * Does not affect underflow, which is always considered exceptional. */ export declare enum ECircularStackOverflowMode { /** * Do nothing. */ NoOp = 1, /** * Throw an error if the buffer overflows. */ Exception = 2, /** * Overwrite the first value. */ Overwrite = 3, /** * Doubles the stack size and copies in place, running in O(size). */ Grow = 4 } /** * @public * Circular first in first out stack. * * @remarks * See {@link ECircularStackOverflowMode} for details of overflow behavior. */ export declare class CircularFIFOStack<TValue> implements IFIFOStack<TValue> { constructor(capacity: number, mode?: ECircularStackOverflowMode); getCapacity(): number; /** * Pushes a value to the top of the stack (depending on `mode`). */ push(value: TValue): void; /** * Remove the bottom element in the stack and return it. * * @remarks * Attempting to pop an empty stack is considered exceptional regardless of `mode`. You can * call `getIsEmpty` or `getRemainingCapacity` to determine if pop is safe to call. */ pop(): TValue; getIsEmpty(): boolean; getRemainingCapacity(): number; private growStack; private buffer; private readonly mode; private capacity; private start; private end; } //# sourceMappingURL=circular-fifo-stack.d.ts.map