@jiminp/tooltool
    Preparing search index...

    Class Deque<T>

    A double-ended queue with amortized O(1) insertion and removal at both ends.

    Uses a sparse index map so head and tail grow independently without array shifts.

    const deque = new Deque<number>();
    deque.push(1, 2);
    deque.unshift(0);
    deque.pop(); // 2

    Type Parameters

    • T

      Item type.

    Index

    Constructors

    Accessors

    Methods

    Constructors

    • Type Parameters

      • T

        Item type.

      Returns Deque<T>

    Accessors

    Methods

    • Retrieves the item at the given index.

      Supports negative indices (-1 = tail). Non-integers are truncated toward zero.

      Parameters

      • index: number

        Position in the deque.

      Returns T | null

      The item, or null if out of range.

    • Removes and returns the tail item.

      Returns T | null

      The removed item, or null if empty.

      Returns null (not undefined) when empty, diverging from native Array.pop().

    • Appends items to the tail.

      Parameters

      • ...items: T[]

        Items to append (in order).

      Returns number

      The new length.

    • Removes and returns the head item.

      Returns T | null

      The removed item, or null if empty.

      Returns null (not undefined) when empty, diverging from native Array.shift().

    • Inserts items at the head.

      Parameters

      • ...items: T[]

        Items to insert; first argument becomes the new head.

      Returns number

      The new length.