FastShiftArray Docs
    Preparing search index...

    Class FastShiftArray<T>

    An O(1)-shift queue that fully satisfies the Array<T> interface.

    A standard Array.shift() is O(n) because one slot must copy down every remaining element. FastQueue avoids that by tracking a headIndex offset into the underlying storage array: shifting simply increments the pointer. All logical indices presented to callers are zero-based and automatically translated to internal indices via + headIndex.

    A Proxy wrapper is returned from the constructor so that bracket notation (queue[i]) also respects the offset. Method bodies are bound to the raw (self) instance to bypass the proxy on every internal property access, preserving the O(1) benefit.

    Because FastQueue<T> implements Array<T>, it can be used anywhere an array is expected — including D3's .data() call, Array.isArray checks (via the iterator protocol), and TypeScript overload resolution.

    const q = FastQueue.fromArray([1, 2, 3]);
    q.push(4); // [1, 2, 3, 4]
    q.shift(); // 1 (O(1))
    console.log(q[0]); // 2

    Type Parameters

    • T

      The element type stored in the queue.

    Implements

    • Array<T>

    Indexable

    • [index: number]: T
    Index

    Properties

    "[unscopables]": {
        "[iterator]"?: boolean;
        "[unscopables]"?: boolean;
        at?: boolean;
        concat?: boolean;
        copyWithin?: boolean;
        entries?: boolean;
        every?: boolean;
        fill?: boolean;
        filter?: boolean;
        find?: boolean;
        findIndex?: boolean;
        findLast?: boolean;
        findLastIndex?: boolean;
        flat?: boolean;
        flatMap?: boolean;
        forEach?: boolean;
        includes?: boolean;
        indexOf?: boolean;
        join?: boolean;
        keys?: boolean;
        lastIndexOf?: boolean;
        length?: boolean;
        map?: boolean;
        pop?: boolean;
        push?: boolean;
        reduce?: boolean;
        reduceRight?: boolean;
        reverse?: boolean;
        shift?: boolean;
        slice?: boolean;
        some?: boolean;
        sort?: boolean;
        splice?: boolean;
        toLocaleString?: boolean;
        toReversed?: boolean;
        toSorted?: boolean;
        toSpliced?: boolean;
        toString?: boolean;
        unshift?: boolean;
        values?: boolean;
        with?: boolean;
        [key: number]: boolean | undefined;
    } = ...

    Required by the Array<T> contract. Marks with as unscopable so that with inside a with statement does not shadow the method.

    Type Declaration

    • [key: number]: boolean | undefined
    • Optional[iterator]?: boolean
    • Optional Readonly[unscopables]?: boolean

      Is an object whose properties have the value 'true' when they will be absent when used in a 'with' statement.

    • Optionalat?: boolean
    • Optionalconcat?: boolean
    • OptionalcopyWithin?: boolean
    • Optionalentries?: boolean
    • Optionalevery?: boolean
    • Optionalfill?: boolean
    • Optionalfilter?: boolean
    • Optionalfind?: boolean
    • OptionalfindIndex?: boolean
    • OptionalfindLast?: boolean
    • OptionalfindLastIndex?: boolean
    • Optionalflat?: boolean
    • OptionalflatMap?: boolean
    • OptionalforEach?: boolean
    • Optionalincludes?: boolean
    • OptionalindexOf?: boolean
    • Optionaljoin?: boolean
    • Optionalkeys?: boolean
    • OptionallastIndexOf?: boolean
    • Optionallength?: boolean

      Gets or sets the length of the array. This is a number one higher than the highest index in the array.

    • Optionalmap?: boolean
    • Optionalpop?: boolean
    • Optionalpush?: boolean
    • Optionalreduce?: boolean
    • OptionalreduceRight?: boolean
    • Optionalreverse?: boolean
    • Optionalshift?: boolean
    • Optionalslice?: boolean
    • Optionalsome?: boolean
    • Optionalsort?: boolean
    • Optionalsplice?: boolean
    • OptionaltoLocaleString?: boolean
    • OptionaltoReversed?: boolean
    • OptionaltoSorted?: boolean
    • OptionaltoSpliced?: boolean
    • OptionaltoString?: boolean
    • Optionalunshift?: boolean
    • Optionalvalues?: boolean
    • Optionalwith?: boolean

    Accessors

    • get length(): number

      The number of logical elements in the queue.

      Does not include the "ghost" slots before headIndex.

      Returns number

      const q = FastQueue.fromArray([1, 2, 3]);
      q.shift();
      console.log(q.length); // 2
    • set length(value: number): void

      Sets the logical length of the queue, truncating or extending it.

      Setting length translates to items.length = value + headIndex so internal accounting stays consistent.

      Parameters

      • value: number

        The new logical length.

      Returns void

      const q = FastQueue.fromArray([1, 2, 3, 4]);
      q.length = 2;
      console.log([...q]); // [1, 2]

    Methods

    • Iterates over the logical elements of the queue in order, skipping the internal "ghost" slots before headIndex.

      Returns ArrayIterator<T>

      const q = FastQueue.fromArray([10, 20, 30]);
      q.shift();
      for (const v of q) console.log(v); // 20, 30
    • Returns the element at the given index, supporting negative indices.

      Negative indices count from the end (-1 is the last element) and bypass the headIndex offset so they always refer to the tail of the logical sequence.

      Parameters

      • index: number

        Zero-based (or negative) index.

      Returns T | undefined

      The element, or undefined if out of range.

      const q = FastQueue.fromArray([10, 20, 30]);
      console.log(q.at(0)); // 10
      console.log(q.at(-1)); // 30
    • Compacts the internal storage by discarding the ghost slots that accumulate after repeated shift() calls.

      This is done automatically when headIndex exceeds 100 000, but you can call it explicitly if memory pressure is a concern.

      Returns void

      const q = FastQueue.fromArray([1, 2, 3]);
      q.shift(); q.shift();
      q.compact(); // internal storage is now [3], headIndex = 0
    • Returns a new FastQueue that is the concatenation of this queue and items.

      Each item in items may be a single element T or a ConcatArray<T> (e.g. another array or FastQueue).

      Parameters

      • ...items: (T | ConcatArray<T>)[]

        Elements or arrays to concatenate.

      Returns FastShiftArray<T>

      A new FastQueue<T>.

      const q = FastQueue.fromArray([1, 2]);
      const r = q.concat([3, 4], 5);
      console.log([...r]); // [1, 2, 3, 4, 5]
    • Copies a segment of the queue to a different position within the same queue.

      All indices are logical (zero-based).

      Parameters

      • target: number

        Zero-based index where the copied section will be pasted.

      • start: number

        Zero-based index of the section start to copy from.

      • Optionalend: number

        Zero-based index of the section end (exclusive).

      Returns this

      this for chaining.

      const q = FastQueue.fromArray([1, 2, 3, 4, 5]);
      q.copyWithin(0, 3);
      console.log([...q]); // [4, 5, 3, 4, 5]
    • Returns an ArrayIterator of [index, value] pairs for the logical elements.

      Returns ArrayIterator<[number, T]>

      const q = FastQueue.fromArray(['a', 'b', 'c']);
      for (const [i, v] of q.entries()) {
      console.log(i, v); // 0 'a', 1 'b', 2 'c'
      }
    • Returns true if every element satisfies predicate.

      Short-circuits on the first failing element. The type-guard overload narrows this to S[] when it returns true.

      Type Parameters

      • S

      Parameters

      • predicate: (value: T, index: number, array: T[]) => value is S

        Test function.

      • OptionalthisArg: any

        Value to use as this inside predicate.

      Returns this is S[]

      const q = FastQueue.fromArray([2, 4, 6]);
      console.log(q.every(x => x % 2 === 0)); // true
    • Determines whether all the members of an array satisfy the specified test.

      Parameters

      • predicate: (value: T, index: number, array: T[]) => unknown

        A function that accepts up to three arguments. The every method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value false, or until the end of the array.

      • OptionalthisArg: any

        An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.

      Returns boolean

    • Fills elements from start (inclusive) to end (exclusive) with value.

      Indices are logical (zero-based); negative values are not supported.

      Parameters

      • value: T

        Value to fill with.

      • Optionalstart: number

        Start index (default 0).

      • Optionalend: number

        End index (default this.length).

      Returns this

      this for chaining.

      const q = FastQueue.fromArray([1, 2, 3, 4]);
      q.fill(0, 1, 3);
      console.log([...q]); // [1, 0, 0, 4]
    • Returns a new FastQueue containing only elements for which predicate returns truthy.

      The type-guard overload narrows the element type to S.

      Type Parameters

      • S

      Parameters

      • predicate: (value: T, index: number, array: T[]) => value is S

        Test function.

      • OptionalthisArg: any

        Value to use as this inside predicate.

      Returns FastShiftArray<S>

      A new FastQueue<S> or FastQueue<T>.

      const q = FastQueue.fromArray([1, 2, 3, 4, 5]);
      const evens = q.filter(x => x % 2 === 0);
      console.log([...evens]); // [2, 4]
    • Returns the elements of an array that meet the condition specified in a callback function.

      Parameters

      • predicate: (value: T, index: number, array: T[]) => unknown

        A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.

      • OptionalthisArg: any

        An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.

      Returns FastShiftArray<T>

    • Returns the first element for which predicate returns truthy, or undefined.

      The type-guard overload narrows the return type to S.

      Type Parameters

      • S

      Parameters

      • predicate: (value: T, index: number, obj: T[]) => value is S

        Test function.

      • OptionalthisArg: any

        Value to use as this inside predicate.

      Returns S | undefined

      const q = FastQueue.fromArray([1, 2, 3, 4]);
      console.log(q.find(x => x > 2)); // 3
    • Returns the first element for which predicate returns truthy, or undefined.

      The type-guard overload narrows the return type to S.

      Parameters

      • predicate: (value: T, index: number, obj: T[]) => unknown

        Test function.

      • OptionalthisArg: any

        Value to use as this inside predicate.

      Returns T | undefined

      const q = FastQueue.fromArray([1, 2, 3, 4]);
      console.log(q.find(x => x > 2)); // 3
    • Returns the zero-based logical index of the first element for which predicate returns truthy, or -1 if none match.

      Parameters

      • predicate: (value: T, index: number, obj: T[]) => unknown

        Test function.

      • Optional_thisArg: any

        Unused.

      Returns number

      const q = FastQueue.fromArray([10, 20, 30]);
      console.log(q.findIndex(x => x > 15)); // 1
    • Returns the last element for which predicate returns truthy, or undefined.

      The type-guard overload narrows the return type to S.

      Type Parameters

      • S

      Parameters

      • predicate: (value: T, index: number, array: T[]) => value is S

        Test function.

      • OptionalthisArg: any

        Value to use as this inside predicate.

      Returns S | undefined

      const q = FastQueue.fromArray([1, 2, 3, 4]);
      console.log(q.findLast(x => x % 2 === 0)); // 4
    • Returns the last element for which predicate returns truthy, or undefined.

      The type-guard overload narrows the return type to S.

      Parameters

      • predicate: (value: T, index: number, array: T[]) => unknown

        Test function.

      • OptionalthisArg: any

        Value to use as this inside predicate.

      Returns T | undefined

      const q = FastQueue.fromArray([1, 2, 3, 4]);
      console.log(q.findLast(x => x % 2 === 0)); // 4
    • Returns the zero-based logical index of the last element for which predicate returns truthy, or -1.

      Parameters

      • predicate: (value: T, index: number, array: T[]) => unknown

        Test function.

      • Optional_thisArg: any

        Unused.

      Returns number

      const q = FastQueue.fromArray([1, 2, 3, 4]);
      console.log(q.findLastIndex(x => x % 2 === 0)); // 3
    • Flattens the queue up to depth levels and returns a plain Array.

      Type Parameters

      • A
      • D extends number = 1

      Parameters

      • this: A
      • Optionaldepth: D

        Maximum depth to flatten (default 1).

      Returns FlatArray<A, D>[]

      A plain FlatArray<A, D>[].

      const q = FastQueue.fromArray([[1, 2], [3, [4, 5]]]);
      console.log(q.flat()); // [1, 2, 3, [4, 5]]
      console.log(q.flat(2)); // [1, 2, 3, 4, 5]
    • Maps each element through callback and flattens the result one level deep.

      Type Parameters

      • U

      Parameters

      • callback: (value: T, index: number, array: T[]) => U | readonly U[]

        Function that returns a value or a readonly array.

      • Optional_thisArg: any

        Unused.

      Returns FastShiftArray<U>

      A new flattened FastQueue<U>.

      const q = FastQueue.fromArray([1, 2, 3]);
      const r = q.flatMap(x => [x, x * 10]);
      console.log([...r]); // [1, 10, 2, 20, 3, 30]
    • Executes callback once for each logical element, in order.

      Parameters

      • callback: (value: T, index: number, array: T[]) => void

        Function to execute for each element.

      • Optional_thisArg: any

        Unused.

      Returns void

      FastQueue.fromArray([1, 2, 3]).forEach(x => console.log(x)); // 1 2 3
      
    • Returns the element at index without going through the Proxy.

      Equivalent to queue[index] but useful when the proxy is disabled or when you want an explicit method call for clarity.

      Parameters

      • index: number

        Zero-based logical index.

      Returns T | undefined

      The element, or undefined if index is out of range.

      const q = FastQueue.fromArray(['a', 'b', 'c']);
      console.log(q.get(1)); // 'b'
      console.log(q.get(9)); // undefined
    • Returns true if searchElement is present in the queue.

      Parameters

      • searchElement: T

        Value to search for.

      • OptionalfromIndex: number

        Optional starting index (default 0).

      Returns boolean

      const q = FastQueue.fromArray([1, 2, NaN]);
      console.log(q.includes(2)); // true
      console.log(q.includes(NaN)); // true (uses SameValueZero)
    • Returns the index of the first occurrence of value, or -1 if not found.

      Parameters

      • value: T

        The value to search for.

      • Optionalindex: number

        Optional starting position (default 0).

      Returns number

      Zero-based logical index, or -1.

      const q = FastQueue.fromArray(['a', 'b', 'c', 'b']);
      console.log(q.indexOf('b')); // 1
      console.log(q.indexOf('b', 2)); // 3
      console.log(q.indexOf('z')); // -1
    • Returns true when the queue contains no elements.

      Returns boolean

      const q = FastQueue.empty<number>();
      console.log(q.isEmpty()); // true
      q.push(1);
      console.log(q.isEmpty()); // false
    • Returns true when the queue contains at least one element.

      Returns boolean

      const q = FastQueue.fromArray([42]);
      console.log(q.isNotEmpty()); // true
    • Joins all logical elements into a string with separator between each pair.

      Parameters

      • separator: string = ','

        String placed between elements (default ',').

      Returns string

      The joined string.

      const q = FastQueue.fromArray([1, 2, 3]);
      console.log(q.join('-')); // '1-2-3'
      console.log(q.join()); // '1,2,3'
    • Returns an ArrayIterator of the zero-based logical indices.

      Returns ArrayIterator<number>

      const q = FastQueue.fromArray(['x', 'y', 'z']);
      console.log([...q.keys()]); // [0, 1, 2]
    • Returns the index of the last occurrence of value, or -1 if not found.

      Parameters

      • value: T

        The value to search for.

      • Optionalindex: number

        Optional starting position for the backward search.

      Returns number

      Zero-based logical index, or -1.

      const q = FastQueue.fromArray([1, 2, 3, 2, 1]);
      console.log(q.lastIndexOf(2)); // 3
      console.log(q.lastIndexOf(9)); // -1
    • Creates a new FastQueue with the results of calling callback on every element.

      Indices passed to callback are zero-based logical indices.

      Type Parameters

      • U

      Parameters

      • callback: (value: T, index: number, array: T[]) => U

        Function called for each element.

      • Optional_thisArg: T

        Unused (bound via arrow function in the caller).

      Returns FastShiftArray<U>

      A new FastQueue<U>.

      const q = FastQueue.fromArray([1, 2, 3]);
      const doubled = q.map(x => x * 2);
      console.log([...doubled]); // [2, 4, 6]
    • Removes and returns the last element of the queue.

      Returns T | undefined

      The last element, or undefined if the queue is empty.

      const q = FastQueue.fromArray([1, 2, 3]);
      console.log(q.pop()); // 3
      console.log([...q]); // [1, 2]
    • Appends one or more elements to the end of the queue.

      Parameters

      • ...item: T[]

        Elements to append.

      Returns number

      The new logical length of the queue.

      const q = FastQueue.fromArray([1, 2]);
      q.push(3, 4);
      console.log([...q]); // [1, 2, 3, 4]
    • Reduces the queue to a single value, processing elements left-to-right.

      When called without initialValue the first element is used as the seed and processing starts at index 1.

      Parameters

      • callback: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T

        Reducer function.

      Returns T

      The accumulated result.

      TypeError if the queue is empty and no initialValue is given.

      const q = FastQueue.fromArray([1, 2, 3, 4]);
      console.log(q.reduce((acc, x) => acc + x, 0)); // 10
      console.log(q.reduce((acc, x) => acc + x)); // 10
    • Reduces the queue to a single value, processing elements left-to-right.

      When called without initialValue the first element is used as the seed and processing starts at index 1.

      Parameters

      • callback: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T

        Reducer function.

      • initial: T

        Optional initial accumulator value.

      Returns T

      The accumulated result.

      TypeError if the queue is empty and no initialValue is given.

      const q = FastQueue.fromArray([1, 2, 3, 4]);
      console.log(q.reduce((acc, x) => acc + x, 0)); // 10
      console.log(q.reduce((acc, x) => acc + x)); // 10
    • Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

      Type Parameters

      • U

      Parameters

      • callback: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U
      • initial: U

      Returns U

    • Reduces the queue to a single value, processing elements right-to-left.

      Parameters

      • callback: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T

        Reducer function.

      Returns T

      The accumulated result.

      TypeError if the queue is empty and no initialValue is given.

      const q = FastQueue.fromArray([1, 2, 3]);
      console.log(q.reduceRight((acc, x) => acc + x, '')); // '321'
    • Reduces the queue to a single value, processing elements right-to-left.

      Parameters

      • callback: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T

        Reducer function.

      • initial: T

        Optional initial accumulator value.

      Returns T

      The accumulated result.

      TypeError if the queue is empty and no initialValue is given.

      const q = FastQueue.fromArray([1, 2, 3]);
      console.log(q.reduceRight((acc, x) => acc + x, '')); // '321'
    • Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

      Type Parameters

      • U

      Parameters

      • callback: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U
      • initial: U

      Returns U

    • Reverses the queue in place and returns this.

      Only the logical elements (from headIndex onward) are reversed; ghost slots are not touched.

      Returns FastShiftArray<T>

      this.

      const q = FastQueue.fromArray([1, 2, 3]);
      q.reverse();
      console.log([...q]); // [3, 2, 1]
    • Removes and returns the first element of the queue in O(1) time.

      After removal, headIndex is incremented rather than copying elements. Ghost slots are cleaned up automatically when headIndex exceeds 100 000.

      Returns T | undefined

      The first element, or undefined if the queue is empty.

      const q = FastQueue.fromArray([10, 20, 30]);
      console.log(q.shift()); // 10 (O(1))
      console.log(q[0]); // 20
    • Returns a section of the queue as a new FastQueue.

      Negative indices are supported: -1 refers to the last element.

      Parameters

      • Optionalstart: number

        Zero-based start index (inclusive, default 0).

      • Optionalend: number

        Zero-based end index (exclusive, default this.length).

      Returns FastShiftArray<T>

      A new FastQueue<T> with fresh backing storage.

      const q = FastQueue.fromArray([0, 1, 2, 3, 4]);
      console.log([...q.slice(1, 3)]); // [1, 2]
      console.log([...q.slice(-2)]); // [3, 4]
    • Returns true if at least one element satisfies predicate.

      Short-circuits on the first matching element.

      Parameters

      • predicate: (value: T, index: number, array: T[]) => unknown

        Test function.

      • Optional_thisArg: any

        Unused.

      Returns boolean

      const q = FastQueue.fromArray([1, 3, 5]);
      console.log(q.some(x => x % 2 === 0)); // false
      q.push(4);
      console.log(q.some(x => x % 2 === 0)); // true
    • Sorts the queue in place using compareFn and returns this.

      Ghost slots are discarded during the sort, so headIndex is reset to 0 afterward.

      Parameters

      • OptionalcompareFn: (a: T, b: T) => number

        Optional comparison function (same semantics as Array.sort).

      Returns this

      this.

      const q = FastQueue.fromArray([3, 1, 2]);
      q.sort();
      console.log([...q]); // [1, 2, 3]

      q.sort((a, b) => b - a);
      console.log([...q]); // [3, 2, 1]
    • Removes and/or inserts elements at start.

      Parameters

      • start: number

        Zero-based logical index at which to start changing the queue.

      • OptionaldeleteCount: number

        Number of elements to remove.

      • ...insertItems: T[]

        Elements to insert in place of the removed elements.

      Returns T[]

      An array of the removed elements.

      const q = FastQueue.fromArray([1, 2, 3, 4]);
      const removed = q.splice(1, 2, 9, 8);
      console.log(removed); // [2, 3]
      console.log([...q]); // [1, 9, 8, 4]
    • Returns a plain Array<T> containing the logical elements from start (inclusive) to end (exclusive).

      Parameters

      • start: number = 0

        Zero-based start index (default 0).

      • end: number = ...

        Zero-based end index (default this.length).

      Returns T[]

      A plain Array<T> — never a FastQueue.

      const q = FastQueue.fromArray([10, 20, 30, 40]);
      console.log(q.toArray(1, 3)); // [20, 30]
    • Returns a locale-sensitive string representation of the logical elements.

      Returns string

      const q = FastQueue.fromArray([1000, 2000]);
      console.log(q.toLocaleString()); // '1,000,2,000' (locale-dependent)
    • Returns a new FastQueue with the elements in reverse order.

      The original queue is not modified.

      Returns FastShiftArray<T>

      A new reversed FastQueue<T>.

      const q = FastQueue.fromArray([1, 2, 3]);
      const r = q.toReversed();
      console.log([...r]); // [3, 2, 1]
      console.log([...q]); // [1, 2, 3]
    • Returns a new sorted FastQueue without modifying the original.

      Parameters

      • OptionalcompareFn: (a: T, b: T) => number

        Optional comparison function.

      Returns FastShiftArray<T>

      A new FastQueue<T> in sorted order.

      const q = FastQueue.fromArray([3, 1, 2]);
      const s = q.toSorted();
      console.log([...s]); // [1, 2, 3]
      console.log([...q]); // [3, 1, 2]
    • Returns a new FastQueue with a splice applied, without modifying the original.

      Parameters

      • start: number

        Zero-based logical start index.

      • deleteCount: number

        Number of elements to remove.

      • ...items: T[]

        Elements to insert.

      Returns FastShiftArray<T>

      A new FastQueue<T>.

      const q = FastQueue.fromArray([1, 2, 3, 4]);
      const r = q.toSpliced(1, 2, 9);
      console.log([...r]); // [1, 9, 4]
      console.log([...q]); // [1, 2, 3, 4]
    • Copies an array and removes elements while returning the remaining elements.

      Parameters

      • start: number

        The zero-based location in the array from which to start removing elements.

      • OptionaldeleteCount: number

        The number of elements to remove.

      Returns FastShiftArray<T>

      A copy of the original array with the remaining elements.

    • Returns a string representation of the logical elements, equivalent to join() with the default comma separator.

      Returns string

      const q = FastQueue.fromArray([1, 2, 3]);
      console.log(q.toString()); // '1,2,3'
    • Inserts one or more elements at the beginning of the queue.

      If headIndex >= elements.length, elements are written into the ghost slots in-place without allocation. Otherwise, a new array is created.

      Parameters

      • ...elements: T[]

        Elements to prepend, in order.

      Returns number

      The new logical length.

      const q = FastQueue.fromArray([3, 4]);
      q.unshift(1, 2);
      console.log([...q]); // [1, 2, 3, 4]
    • Returns an ArrayIterator over the logical element values.

      Returns ArrayIterator<T>

      const q = FastQueue.fromArray([10, 20, 30]);
      console.log([...q.values()]); // [10, 20, 30]
    • Returns a new FastQueue with the element at index replaced by value.

      The original queue is not modified.

      Parameters

      • index: number

        Zero-based logical index.

      • value: T

        Replacement value.

      Returns FastShiftArray<T>

      A new FastQueue<T>.

      const q = FastQueue.fromArray([1, 2, 3]);
      const r = q.with(1, 99);
      console.log([...r]); // [1, 99, 3]
      console.log([...q]); // [1, 2, 3]
    • Creates a FastQueue from a copy of array.

      The queue owns its own storage; mutations do not affect the original.

      Type Parameters

      • T

      Parameters

      • array: T[]

        The array to copy.

      • OptionaluseProxy: boolean = true

        Optional parameter that determines whether to apply the index-offset proxy.

      • OptionalcompactingSize: number = COMPACTING_SIZE

        Optional parameter that determines the number of shifts before compacting the array.

      Returns FastShiftArray<T>

      A new FastQueue<T> with independent storage.

      const src = [1, 2, 3];
      const q = FastQueue.copyFromArray(src);
      q.push(4);
      console.log(src); // [1, 2, 3] — unchanged
      console.log([...q]); // [1, 2, 3, 4]
    • Creates an empty FastQueue<T>.

      Type Parameters

      • T

      Parameters

      • OptionaluseProxy: boolean = true

        Optional parameter that determines whether to apply the index-offset proxy.

      • OptionalcompactingSize: number = COMPACTING_SIZE

        Optional parameter that determines the number of shifts before compacting the array.

      Returns FastShiftArray<T>

      A new empty FastQueue<T>.

      const q = FastQueue.empty<number>();
      q.push(1, 2);
      console.log(q.length); // 2
    • Creates a FastQueue that wraps array directly — no copy is made.

      Pass useProxy = false only when you know you will never use bracket notation to read or write elements.

      Type Parameters

      • T

      Parameters

      • array: T[]

        The array to wrap.

      • OptionaluseProxy: boolean = true

        Optional parameter that determines whether to apply the index-offset proxy.

      • OptionalcompactingSize: number = COMPACTING_SIZE

        Optional parameter that determines the number of shifts before compacting the array.

      Returns FastShiftArray<T>

      A new FastQueue<T> backed by array.

      const src = [1, 2, 3];
      const q = FastQueue.fromArray(src);
      q.push(4);
      console.log(src); // [1, 2, 3, 4] — same backing array