/** * PersistentVector — an immutable, structurally-shared vector based on a * 32-way trie (branching factor 32). * * Performance characteristics: * get(i) O(log₃₂ N) ≈ O(1) in practice (max depth ~6 for 1B elements) * set(i, v) O(log₃₂ N) — path-copies the spine, shares all unchanged nodes * append(v) O(log₃₂ N) amortized — O(1) when tail has room (tail holds ≤ 32 elems) * size O(1) * iterate O(N) * * Tail optimisation: the last ≤ 32 elements are kept in a flat array, so * sequential appends and gets near the end never touch the trie. * * Small-collection threshold (future): for size ≤ 32, a flat array bypasses * the trie entirely, eliminating per-node overhead for tiny vectors. Left as * a known future optimization per design intent. */ /** Internal trie node — an array of up to WIDTH children (nodes or leaf values). */ interface INode { readonly array: readonly unknown[]; } /** ------------------------------------------------------------------ */ /** Transient vector — mutable accumulator, converted to persistent. */ /** ------------------------------------------------------------------ */ /** * TransientVector provides O(1) amortized appends during bulk construction. * Obtained via `vec.asTransient()`; converted back via `.persistent()`. * * Do not use after calling `.persistent()`. */ export declare class TransientVector { private _size; private _shift; private _root; private _tail; constructor(size: number, shift: number, root: unknown[], tail: T[]); get size(): number; private tailOffset; append(val: T): void; persistent(): PersistentVector; } /** ------------------------------------------------------------------ */ /** PersistentVector */ /** ------------------------------------------------------------------ */ export declare class PersistentVector implements Iterable { static readonly EMPTY: PersistentVector; readonly size: number; /** Alias for `size` — lets PersistentVector work where `.length` is expected. */ get length(): number; private readonly _shift; private readonly _root; private readonly _tail; constructor(size: number, shift: number, root: INode, tail: readonly T[]); static empty(): PersistentVector; /** Build from a plain JS array. O(N). */ static from(arr: Iterable): PersistentVector; private tailOffset; private nodeFor; /** Returns the element at index `i`, or `undefined` if out of range. */ get(i: number): T | undefined; /** Returns a new vector with `val` at index `i`. Returns `this` if `i` is out of range. */ set(i: number, val: T): PersistentVector; /** Returns a new vector with `val` appended at the end. */ append(val: T): PersistentVector; /** Returns a new vector with `val` prepended at index 0. O(N). */ prepend(val: T): PersistentVector; /** Returns a new transient for bulk mutation. */ asTransient(): TransientVector; /** Iterate over elements in order. */ [Symbol.iterator](): Iterator; /** Convert to a plain JS array. O(N). */ toArray(): T[]; /** Returns true if this vector equals another (structural equality of elements via `eq`). */ equals(other: PersistentVector, eq?: (a: T, b: T) => boolean): boolean; } export {};