Options
All
  • Public
  • Public/Protected
  • All
Menu

A doubly-linked list, which is sometimes faster than a singly-linked list but consumes a bit more memory.

import { DoubleLinkedList } from "scl"

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

Property name Worst-case
append() O(1)
at() O(n)
insertAfter() O(1)
insertBefore() O(1)
deleteAt() O(1)
prepend() O(1)
size O(1)
see

SingleLinkedList

Type parameters

  • T

    The type of element in this collection.

Hierarchy

Implements

Index

Constructors

constructor

  • 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

    • Optional iterable: Iterable<T>

    Returns DoubleLinkedList<T>

Accessors

size

  • 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

[Symbol.iterator]

  • [Symbol.iterator](): IterableIterator<T>
  • 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>

add

append

at

clear

  • clear(): void
  • Remove all elements from this collection, effectively setting the collection to the empty collection.

    Returns void

clone

delete

  • delete(el: T): boolean

deleteAll

  • deleteAll(el: T): number

deleteAt

  • deleteAt(position: DLNode<T>): void

first

  • first(): T

getAt

  • getAt(position: number): T
  • 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

has

  • has(el: T): boolean

insertAfter

insertBefore

last

  • last(): T

prepend

rest

toRange

Static empty

Static from

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

    Type parameters

    • T

    Parameters

    • iterable: Iterable<T>

    Returns DoubleLinkedList<T>

Legend

  • Property
  • Method
  • Accessor
  • Property
  • Method
  • Inherited property
  • Inherited method

Generated using TypeDoc