@ac-essentials/misc-util
    Preparing search index...

    Class DoublyLinkedList<T>

    A doubly linked list implementation.

    Time complexity:

    • Access (by index): O(n)
    • Update (by index): O(n)
    • Insert: O(1) at head and tail, O(n) otherwise
    • Remove: O(1) at head and tail, O(n) otherwise
    • Search: O(n) Space complexity: O(n)

    Type Parameters

    • T

      The type of elements in the list.

    Implements

    Index

    Constructors

    Properties

    capacity: number = Infinity

    The maximum number of elements the collection can hold. If the collection is unbounded, this will be Infinity.

    Methods

    • Concatenates the given items to the end of the collection and returns an iterator over the merged items.

      This method does not mutate the original collection.

      Parameters

      • ...items: T[]

        The items to merge.

      Returns IterableIterator<T>

      An iterator of the merged items.

    • Returns the item at the specified index.

      If the index is negative, it counts from the end of the list. If the index is out of bounds, undefined is returned.

      Parameters

      • index: number

        The index of the item to retrieve.

      Returns undefined | T

      The item at the specified index, or undefined if the index is out of bounds.

    • Replaces all the item matching the given predicate in the collection with a new item.

      Parameters

      • condition: Predicate<[T]>

        A predicate function to identify the items to replace.

      • newItemFactory: Callable<[T], T>

        A function that takes the old item and returns the new item to insert.

      Returns IterableIterator<T>

      An iterable of the replaced items.

    • Replaces the first occurence of the item matching the given predicate in the collection with a new item.

      Parameters

      • condition: Predicate<[T]>

        A predicate function to identify the item to replace.

      • newItem: T

        The new item to insert.

      Returns boolean

      true if the item was found and replaced, false otherwise.

    • Sets the item at the specified index.

      If the index is negative, it counts from the end of the list. If the index is equal to the length of the list, the item is appended to the end. If the index is out of bounds, a RangeError is thrown.

      Parameters

      • index: number

        The index at which to set the item.

      • item: T

        The item to set.

      Returns void

      If the index is out of bounds.

      If the operation would exceed the list's capacity.

    • Slice the list to a new list from start to end.

      This method does not mutate the original list.

      The range is specified by the start and end parameters, which are inclusive and exclusive, respectively. If start is omitted, it defaults to 0. If end is omitted, it defaults to the length of the list.

      If either start or end is negative, they refer to positions from the end of the list. For example, -1 refers to the last element, -2 refers to the second last element, and so on.

      If start is greater than or equal to end, the result is an empty iterator.

      If the start index is out of bounds, a RangeError is thrown. If end is out of bounds, it is clamped to the valid range.

      Parameters

      • start: number = 0

        Optional start index of the range (inclusive).

      • Optionalend: number

        Optional end index of the range (exclusive).

      Returns IterableIterator<T>

      An iterator for the elements in the specified range.

      If the start index is out of bounds.

    • Change the content of the list by removing or replacing existing elements and/or adding new elements in place.

      If the start index is negative, it counts from the end of the list. If the start index is equal to the length of the list, no elements are removed and the items are appended to the end of the list. If the start index is out of bounds, a RangeError is thrown.

      If deleteCount is omitted, it defaults to Infinity, meaning all elements from the start index to the end of the list will be removed. If deleteCount is greater than the number of elements from start to the end of the list, it will remove all elements from start to the end of the list. If deleteCount is 0 or negative, no elements will be removed.

      If items are provided, they will be inserted starting at the start index.

      Parameters

      • start: number

        The index at which to start changing the list.

      • deleteCount: number = Infinity

        The number of elements to remove from the list. Defaults to Infinity

      • ...items: T[]

        The elements to add to the list, beginning at the start index.

      Returns IterableIterator<T>

      An iterable of the removed items.

      If the start index is out of bounds.

      If the operation would exceed the list's capacity.

    • Same as set, but waits for capacity if the operation would exceed it.

      Parameters

      • index: number
      • item: T
      • Optionalsignal: null | AbortSignal

        Optional abort signal to cancel the operation.

      Returns Promise<void>

      IList.set

    • The same as splice, but waits for capacity if the operation would exceed it.

      Parameters

      • start: number
      • deleteCount: number = Infinity
      • items: Iterable<T>
      • Optionalsignal: null | AbortSignal

        Optional abort signal to cancel the operation.

      Returns Promise<IterableIterator<T, any, any>>

      IList.splice