A FIFO queue, where the first element pushed into the collection is also the first to be popped out of it.

import { Queue } from "scl"

Pushing and popping an element are both in O(1).

The following table summarises the time complexity of the most commonly used properties.

Property name Worst-case
add() O(1)
peek() O(1)
pop() O(1)
size O(1)

Type Parameters

  • T

    The type of element in this queue.

Hierarchy (View Summary)

Implements

Constructors

  • Creates a singly-linked list, optionally filled with the elements generated by the given iterable.

    const l = new DoubleinkedList();
    

    You can also construct a linked list from any iterable, like so:

    const l = new DoubleLinkedList([1, 2, 3])
    

    Type Parameters

    • T

    Parameters

    • Optionaliterable: Iterable<T, any, any>

    Returns Queue<T>

Accessors

  • get size(): number
  • Count the amount of elements in the collection.

    ⚠️ In most cases, this should be an O(1) operation. However, there are cases where this can be an O(n) operation. Therefore, it is recommended to always cache the result in a local variable.

    Returns number

Methods

  • Returns an object which is able to sift through the values in this collection.

    The order by which the elements are traversed depends on the kind of collection. For unordered collections, the iteration order is unspecified and may even differ between two iterations on the same collection.

    Returns IterableIterator<T, any, any>

  • Remove an element from the collection. If multiple elements are matched, the collection picks one of them.

    Parameters

    • el: T

    Returns boolean

    true if the element was found, false otherwise.

  • Allows taking an element directly out of the collection at a given position.

    This method might be faster than at because it is not forced to construct a cursor object.

    Parameters

    • position: number

    Returns T

  • Will create a doubly-linked list filled with the elements generated by the given iterable.

    Type Parameters

    • T

    Parameters

    • iterable: Iterable<T, any, any>

    Returns Queue<T>