Class LinkedListQueue<E, R>

Queue implemented over a singly linked list; preserves head/tail operations with linear scans for queries.

Time O(1), Space O(1)

examples will be generated by unit test

Type Parameters

  • E = any
  • R = any

Hierarchy (view full)

Constructors

Properties

_toElementFn?: ((rawElement: R) => E)

The converter used to transform a raw element (R) into a public element (E).

Time O(1), Space O(1).

Accessors

  • get maxLen(): number
  • Upper bound for length (if positive), or -1 when unbounded.

    Returns number

    Maximum allowed length.

    Time O(1), Space O(1)

  • get toElementFn(): undefined | ((rawElement: R) => E)
  • Exposes the current toElementFn, if configured.

    Returns undefined | ((rawElement: R) => E)

    The converter function or undefined when not set.

    Time O(1), Space O(1).

Methods

  • Returns an iterator over the structure's elements.

    Parameters

    • Rest...args: unknown[]

      Optional iterator arguments forwarded to the internal iterator.

    Returns IterableIterator<E, any, any>

    An IterableIterator<E> that yields the elements in traversal order.

    Producing the iterator is O(1); consuming the entire iterator is Time O(n) with O(1) extra space.

  • Concatenate lists/elements preserving order.

    Parameters

    • Rest...items: LinearBase<E, R, LinkedListNode<E>>[]

      Elements or LinearBase instances.

    Returns this

    New list with combined elements (this type).

    Time O(sum(length)), Space O(sum(length))

  • Delete the first node whose value matches a predicate.

    Parameters

    • predicate: ((value: E, index: number, list: this) => boolean)

      Predicate (value, index, list) → boolean to decide deletion.

        • (value, index, list): boolean
        • Parameters

          • value: E
          • index: number
          • list: this

          Returns boolean

    Returns boolean

    True if a node was removed.

    Time O(N), Space O(1)

  • Tests whether all elements satisfy the predicate.

    Parameters

    • predicate: ElementCallback<E, R, boolean>

      Function invoked for each element with signature (value, index, self).

    • OptionalthisArg: unknown

      Optional this binding for the predicate.

    Returns boolean

    true if every element passes; otherwise false.

    Time O(n) in the worst case; may exit early when the first failure is found. Space O(1).

  • Filter values into a new list of the same class.

    Parameters

    • callback: ElementCallback<E, R, boolean>

      Predicate (value, index, list) → boolean to keep value.

    • OptionalthisArg: any

      Value for this inside the callback.

    Returns this

    A new list with kept values.

    Time O(N), Space O(N)

  • Finds the first element that satisfies the predicate and returns it.

    Finds the first element of type S (a subtype of E) that satisfies the predicate and returns it.

    Type Parameters

    • S

    Parameters

    • predicate: ElementCallback<E, R, S>

      Type-guard predicate: (value, index, self) => value is S.

    • OptionalthisArg: unknown

      Optional this binding for the predicate.

    Returns undefined | S

    The matched element typed as S, or undefined if not found.

    Time O(n) in the worst case; may exit early on the first match. Space O(1).

  • Find the first index matching a predicate.

    Parameters

    • predicate: ElementCallback<E, R, boolean>

      (element, index, self) => boolean.

    • OptionalthisArg: any

      Optional this for callback.

    Returns number

    Index or -1.

    Time O(n), Space O(1)

  • Invokes a callback for each element in iteration order.

    Parameters

    • callbackfn: ElementCallback<E, R, void>

      Function invoked per element with signature (value, index, self).

    • OptionalthisArg: unknown

      Optional this binding for the callback.

    Returns void

    void.

    Time O(n), Space O(1).

  • Checks whether a strictly-equal element exists in the structure.

    Parameters

    • element: E

      The element to test with === equality.

    Returns boolean

    true if an equal element is found; otherwise false.

    Time O(n) in the worst case. Space O(1).

  • Map values into a new list of the same class.

    Parameters

    • callback: ElementCallback<E, R, E>

      Mapping function (value, index, list) → newValue.

    • OptionalthisArg: any

      Value for this inside the callback.

    Returns this

    A new list with mapped values.

    Time O(N), Space O(N)

  • Right-to-left reduction using reverse iterator.

    Type Parameters

    • U

    Parameters

    • callbackfn: ReduceLinearCallback<E, U>

      (acc, element, index, self) => acc.

    • initialValue: U

      Initial accumulator.

    Returns U

    Final accumulator.

    Time O(n), Space O(1)

  • Slice via forward iteration (no random access required).

    Parameters

    • start: number = 0

      Inclusive start (supports negative index).

    • end: number = ...

      Exclusive end (supports negative index).

    Returns this

    New list (this type).

    Time O(n), Space O(n)

  • Tests whether at least one element satisfies the predicate.

    Parameters

    • predicate: ElementCallback<E, R, boolean>

      Function invoked for each element with signature (value, index, self).

    • OptionalthisArg: unknown

      Optional this binding for the predicate.

    Returns boolean

    true if any element passes; otherwise false.

    Time O(n) in the worst case; may exit early on first success. Space O(1).

  • In-place stable order via array sort semantics.

    Parameters

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

      Comparator (a, b) => number.

        • (a, b): number
        • Parameters

          Returns number

    Returns this

    This container.

    Time O(n log n), Space O(n) (materializes to array temporarily)

  • Remove and/or insert elements at a position (array-like behavior).

    Parameters

    • start: number

      Start index (clamped to [0, length]).

    • OptionaldeleteCount: number = 0

      Number of elements to remove (default 0).

    • Optional Rest...items: E[]

      Elements to insert after start.

    Returns this

    A new list containing the removed elements (typed as this).

    Time O(N + M), Space O(M)

  • Returns an iterator over the values (alias of the default iterator).

    Returns IterableIterator<E, any, any>

    An IterableIterator<E> over all elements.

    Creating the iterator is O(1); full iteration is Time O(n), Space O(1).