Skip to content

Typed API (TypeDoc)


Typed API (TypeDoc) / LinkedList

Class: LinkedList<E>

Defined in: list.ts:535

Since

2.0.0

Type Parameters

E

E

Value type.

Implements

Constructors

Constructor

new LinkedList<E>(elements?, reverse?): LinkedList<E>

Defined in: list.ts:555

Parameters

elements?

Iterable<E, any, any>

reverse?

boolean = false

Returns

LinkedList<E>

Properties

comparator

comparator: Comparator<E>

Defined in: list.ts:551

Comparator used for equality/sort checks.

Implementation of

ILinkedList.comparator


first

first: Node<E>

Defined in: list.ts:539

Head node reference.

Implementation of

ILinkedList.first


last

last: Node<E>

Defined in: list.ts:543

Tail node reference.

Implementation of

ILinkedList.last


size

size: number = 0

Defined in: list.ts:547

Current element count.

Implementation of

ILinkedList.size

Methods

[iterator]()

[iterator](): Iterator<E>

Defined in: list.ts:1008

Iterates through the LinkedList.

Returns

Iterator<E>

Iterator for iterating.

Remarks

Complexity: O(size)

Implementation of

ILinkedList.[iterator]


add()

add(e): void

Defined in: list.ts:572

Append an element.

Parameters

e

E

Returns

void

Remarks

Complexity: Amortized O(1) unless stated otherwise.

Implementation of

ILinkedList.add


addAll()

addAll(c): void

Defined in: list.ts:579

Append every element from another collection.

Parameters

c

Iterable<E>

Returns

void

Remarks

Complexity: O(n + m) where m is collection.size.

Implementation of

ILinkedList.addAll


addFirst()

addFirst(e): void

Defined in: list.ts:588

Insert at the beginning.

Parameters

e

E

Returns

void

Remarks

Complexity: O(1)

Implementation of

ILinkedList.addFirst


addLast()

addLast(e): void

Defined in: list.ts:604

Insert at the end.

Parameters

e

E

Returns

void

Remarks

Complexity: O(1)

Implementation of

ILinkedList.addLast


clear()

clear(): void

Defined in: list.ts:623

Remove all entries.

Returns

void

Remarks

Complexity: O(n)

Implementation of

ILinkedList.clear


contains()

contains(element): boolean

Defined in: list.ts:948

Test membership using the comparator when available.

Parameters

element

E

Returns

boolean

Remarks

Complexity: O(n) worst case

Implementation of

ILinkedList.contains


equals()

equals(l): boolean

Defined in: list.ts:955

Compare equality value-by-value using the comparator.

Parameters

l

IList<E>

List to compare.

Returns

boolean

true when lengths match and all elements compare equal.

Implementation of

ILinkedList.equals


every()

every(predicate): boolean

Defined in: list.ts:772

Test whether every element matches the predicate.

Parameters

predicate

(e) => boolean

Match callback.

Returns

boolean

true when all elements satisfy the predicate.

Remarks

Complexity: O(n)

Implementation of

ILinkedList.every


filter()

filter(predicate): LinkedList<E>

Defined in: list.ts:759

Create a list containing values that satisfy the predicate.

Parameters

predicate

(e) => boolean

Filter callback.

Returns

LinkedList<E>

Filtered list.

Remarks

Complexity: O(n)

Implementation of

ILinkedList.filter


get()

get(index): E

Defined in: list.ts:633

O(size)
Ω(1)

Parameters

index

number

Returns

E

Implementation of

ILinkedList.get


getFirst()

getFirst(): E

Defined in: list.ts:801

Read the first element.

Returns

E

Implementation of

ILinkedList.getFirst


getLast()

getLast(): E

Defined in: list.ts:809

Read the last element.

Returns

E

Implementation of

ILinkedList.getLast


getNode()

getNode(index): Node<E>

Defined in: list.ts:924

Retrieve the internal node at index.

Parameters

index

number

Returns

Node<E>

Remarks

Complexity: O(n)

Implementation of

ILinkedList.getNode


indexOf()

indexOf(element, startIndex): number

Defined in: list.ts:967

Locate the first matching element starting at startIndex.

Parameters

element

E

Needle value.

startIndex

number = 0

Optional search start.

Returns

number

Index or -1.

Remarks

Complexity: O(n)

Implementation of

ILinkedList.indexOf


isEmpty()

isEmpty(): boolean

Defined in: list.ts:818

Check for emptiness.

Returns

boolean

true when size === 0.

Implementation of

ILinkedList.isEmpty


map()

map<V>(fn): LinkedList<V>

Defined in: list.ts:737

Transform each element.

Type Parameters

V

V

Result type.

Parameters

fn

(e) => V

Mapper invoked per element.

Returns

LinkedList<V>

New list containing mapped values.

Remarks

Complexity: O(n)

Implementation of

ILinkedList.map


reduce()

reduce<V>(fn, initialValue?): V

Defined in: list.ts:748

Reduce the list to a single value.

Type Parameters

V

V

Accumulator type.

Parameters

fn

(accumulator, element) => V

Reducer callback.

initialValue?

V

Optional starting value.

Returns

V

Accumulated result.

Remarks

Complexity: O(n)

Implementation of

ILinkedList.reduce


remove()

remove(target, isIndex): number | E

Defined in: list.ts:846

Remove by value or index.

Parameters

target

Element or index.

number | E

isIndex

boolean = true

When true, treat e as index.

Returns

number | E

Removed element or index of removal.

Remarks

Complexity: O(n) worst case.

Implementation of

ILinkedList.remove


removeFirst()

removeFirst(): E

Defined in: list.ts:856

Remove and return the head value.

Returns

E

Remarks

Complexity: O(1)

Implementation of

ILinkedList.removeFirst


removeLast()

removeLast(): E

Defined in: list.ts:891

Remove and return the tail value.

Returns

E

Remarks

Complexity: O(1)

Implementation of

ILinkedList.removeLast


reverseIterator()

reverseIterator(): Generator<E, void, unknown>

Defined in: list.ts:997

Iterates elements from the most recently added to the earliest.

Returns

Generator<E, void, unknown>

Implementation of

ILinkedList.reverseIterator


set()

set(index, e): boolean

Defined in: list.ts:647

Replace the element at index.

Parameters

index

number

Position to update.

e

E

New value.

Returns

boolean

true when successful.

Implementation of

ILinkedList.set


slice()

slice(startIndex, endIndex): LinkedList<E>

Defined in: list.ts:656

Take a slice using modulo arithmetic for wrap-around indices.

Parameters

startIndex

number

Beginning index (accepts negatives).

endIndex

number

Ending index.

Returns

LinkedList<E>

New list with copied range.

Remarks

Complexity: O(k) where k is slice length.

Implementation of

ILinkedList.slice


slice2()

slice2(startIndex, endIndex): LinkedList<E>

Defined in: list.ts:664

Variant of slice where the sign of endIndex decides direction.

Parameters

startIndex

number

endIndex

number

Returns

LinkedList<E>

New list containing copied range.

Remarks

Complexity: O(k)

Implementation of

ILinkedList.slice2


some()

some(predicate): boolean

Defined in: list.ts:787

Test whether any element matches the predicate.

Parameters

predicate

(e) => boolean

Match callback.

Returns

boolean

true when at least one element matches.

Remarks

Complexity: O(n)

Implementation of

ILinkedList.some


sort()

sort(cmp?): void

Defined in: list.ts:979

Sort the structure using the provided comparator.

Parameters

cmp?

Comparator<E>

Optional comparator; falls back to the internal one.

Returns

void

Implementation of

ILinkedList.sort


splice()

splice(startIndex, deleteCount): LinkedList<E>

Defined in: list.ts:727

Remove and return a consecutive range.

Parameters

startIndex

number

Start position.

deleteCount

number

Number of items to remove (negative => left).

Returns

LinkedList<E>

List containing removed elements.

Remarks

Complexity: O(n)

Implementation of

ILinkedList.splice

Built with VitePress – Released under the MIT License.