Skip to main content

LinearLinkedBase

data-structure-typed


data-structure-typed / LinearLinkedBase

Abstract Class: LinearLinkedBase<E, R, NODE>

Defined in: data-structures/base/linear-base.ts:397

Linked-list specialized linear container.

Remarks​

Time O(1), Space O(1)

Extends​

Extended by​

Type Parameters​

E​

E

Element type.

R​

R = any

Return type for mapped/derived views.

NODE​

NODE extends LinkedListNode<E> = LinkedListNode<E>

Linked node type.

Properties​

length​

Get Signature​

get abstract length(): number;

Defined in: data-structures/base/linear-base.ts:91

Element count.

Remarks​

Time O(1), Space O(1)

Returns​

number

Number of elements.

Inherited from​

LinearBase.length


maxLen​

Get Signature​

get maxLen(): number;

Defined in: data-structures/base/linear-base.ts:100

Upper bound for length (if positive), or -1 when unbounded.

Remarks​

Time O(1), Space O(1)

Returns​

number

Maximum allowed length.

Inherited from​

LinearBase.maxLen


toElementFn​

Get Signature​

get toElementFn(): ((rawElement) => E) | undefined;

Defined in: data-structures/base/iterable-element-base.ts:48

Exposes the current toElementFn, if configured.

Remarks​

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

Returns​

((rawElement) => E) | undefined

The converter function or undefined when not set.

Inherited from​

LinearBase.toElementFn

Methods​

[iterator]()​

iterator: IterableIterator<E>;

Defined in: data-structures/base/iterable-element-base.ts:61

Returns an iterator over the structure's elements.

Parameters​

args​

...unknown[]

Optional iterator arguments forwarded to the internal iterator.

Returns​

IterableIterator<E>

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

Remarks​

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

Inherited from​

LinearBase.[iterator]


addAfter()​

abstract addAfter(existingElementOrNode, newElementOrNode): boolean;

Defined in: data-structures/base/linear-base.ts:586

Insert new element/node after an existing node.

Parameters​

existingElementOrNode​

E | NODE

Reference element/node.

newElementOrNode​

E | NODE

Element/node to insert.

Returns​

boolean

true if inserted.

Remarks​

Time O(1)~O(n) depending on reference access, Space O(1)


addAt()​

abstract addAt(index, newElementOrNode): boolean;

Defined in: data-structures/base/linear-base.ts:372

Insert an element/node at a position.

Parameters​

index​

number

Position (0-based).

newElementOrNode​

E | NODE

Element or node to insert.

Returns​

boolean

true if inserted.

Remarks​

Time O(1)~O(n) depending on implementation, Space O(1)

Inherited from​

LinearBase.addAt


addBefore()​

abstract addBefore(existingElementOrNode, newElementOrNode): boolean;

Defined in: data-structures/base/linear-base.ts:577

Insert new element/node before an existing node.

Parameters​

existingElementOrNode​

E | NODE

Reference element/node.

newElementOrNode​

E | NODE

Element/node to insert.

Returns​

boolean

true if inserted.

Remarks​

Time O(1)~O(n) depending on reference access, Space O(1)


at()​

abstract at(index): E | undefined;

Defined in: data-structures/base/linear-base.ts:355

Get element at an index.

Parameters​

index​

number

Position (0-based).

Returns​

E | undefined

Element or undefined.

Remarks​

Time O(1)~O(n) depending on implementation, Space O(1)

Inherited from​

LinearBase.at


clear()​

abstract clear(): void;

Defined in: data-structures/base/iterable-element-base.ts:318

Removes all elements from the structure.

Returns​

void

void.

Remarks​

Expected Time O(1) or O(n) depending on the implementation; Space O(1).

Inherited from​

LinearBase.clear


clone()​

abstract clone(): this;

Defined in: data-structures/base/linear-base.ts:305

Deep clone while preserving concrete subtype.

Returns​

this

New list of the same species (this type).

Remarks​

Time O(n), Space O(n)

Inherited from​

LinearBase.clone


concat()​

concat(...items): this;

Defined in: data-structures/base/linear-base.ts:462

Concatenate lists/elements preserving order.

Parameters​

items​

...( | E | LinearBase<E, R, LinkedListNode<E>>)[]

Elements or LinearBase instances.

Returns​

this

New list with combined elements (this type).

Remarks​

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

Overrides​

LinearBase.concat


delete()​

abstract delete(elementOrNode): boolean;

Defined in: data-structures/base/linear-base.ts:568

Delete by element or node in a linked list.

Parameters​

elementOrNode​

E | NODE | undefined

Element or node.

Returns​

boolean

true if removed.

Remarks​

Time O(1)~O(n) depending on availability of links, Space O(1)

Overrides​

LinearBase.delete


deleteAt()​

abstract deleteAt(pos): E | undefined;

Defined in: data-structures/base/linear-base.ts:363

Remove element at a position.

Parameters​

pos​

number

Position (0-based).

Returns​

E | undefined

Removed element or undefined.

Remarks​

Time O(1)~O(n) depending on implementation, Space O(1)

Inherited from​

LinearBase.deleteAt


entries()​

entries(): IterableIterator<[number, E]>;

Defined in: data-structures/base/iterable-element-base.ts:207

Return an iterator of [index, value] pairs (Array-compatible).

Returns​

IterableIterator<[number, E]>

Remarks​

Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.

Inherited from​

LinearBase.entries


every()​

every(predicate, thisArg?): boolean;

Defined in: data-structures/base/iterable-element-base.ts:87

Tests whether all elements satisfy the predicate.

Parameters​

predicate​

ElementCallback<E, R, boolean>

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

thisArg?​

unknown

Optional this binding for the predicate.

Returns​

boolean

true if every element passes; otherwise false.

Remarks​

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

Inherited from​

LinearBase.every


fill()​

fill(
value,
start?,
end?): this;

Defined in: data-structures/base/linear-base.ts:279

Fill a range with a value.

Parameters​

value​

E

Value to set.

start?​

number = 0

Inclusive start.

end?​

number = ...

Exclusive end.

Returns​

this

This list.

Remarks​

Time O(n), Space O(1)

Inherited from​

LinearBase.fill


filter()​

abstract filter(predicate, thisArg?): this;

Defined in: data-structures/base/iterable-element-base.ts:370

Filters elements using the provided predicate and returns the same concrete structure type.

Parameters​

predicate​

ElementCallback<E, R, boolean>

Function with signature (value, index, self) => boolean.

thisArg?​

unknown

Optional this binding for the predicate.

Returns​

this

A new instance of the same concrete type containing only elements that pass the predicate.

Remarks​

Time O(n), Space O(k) where k is the number of kept elements.

Inherited from​

LinearBase.filter


find()​

Call Signature​

find<S>(predicate, thisArg?): S | undefined;

Defined in: data-structures/base/iterable-element-base.ts:163

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​

S

Parameters​
predicate​

ElementCallback<E, R, S>

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

thisArg?​

unknown

Optional this binding for the predicate.

Returns​

S | undefined

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

Remarks​

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

Inherited from​

LinearBase.find

Call Signature​

find(predicate, thisArg?): E | undefined;

Defined in: data-structures/base/iterable-element-base.ts:164

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.

Parameters​
predicate​

ElementCallback<E, R, unknown>

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

thisArg?​

unknown

Optional this binding for the predicate.

Returns​

E | undefined

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

Remarks​

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

Inherited from​

LinearBase.find


findIndex()​

findIndex(predicate, thisArg?): number;

Defined in: data-structures/base/linear-base.ts:147

Find the first index matching a predicate.

Parameters​

predicate​

ElementCallback<E, R, boolean>

(element, index, self) => boolean.

thisArg?​

unknown

Optional this for callback.

Returns​

number

Index or -1.

Remarks​

Time O(n), Space O(1)

Inherited from​

LinearBase.findIndex


forEach()​

forEach(callbackfn, thisArg?): void;

Defined in: data-structures/base/iterable-element-base.ts:133

Invokes a callback for each element in iteration order.

Parameters​

callbackfn​

ElementCallback<E, R, void>

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

thisArg?​

unknown

Optional this binding for the callback.

Returns​

void

void.

Remarks​

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

Inherited from​

LinearBase.forEach


getNodeAt()​

abstract getNodeAt(index): NODE | undefined;

Defined in: data-structures/base/linear-base.ts:594

Node at index (for random-access emulation).

Parameters​

index​

number

Position (0-based).

Returns​

NODE | undefined

Node or undefined.

Remarks​

Time O(n), Space O(1)


has()​

has(element): boolean;

Defined in: data-structures/base/iterable-element-base.ts:188

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.

Remarks​

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

Inherited from​

LinearBase.has


includes()​

includes(element): boolean;

Defined in: data-structures/base/iterable-element-base.ts:199

Check whether a value exists (Array-compatible alias for has).

Parameters​

element​

E

Element to search for (uses ===).

Returns​

boolean

true if found.

Remarks​

Provided for familiarity when migrating from Array. Time O(n), Space O(1).

Inherited from​

LinearBase.includes


indexOf()​

indexOf(searchElement, fromIndex?): number;

Defined in: data-structures/base/linear-base.ts:417

Linked-list optimized indexOf (forwards scan).

Parameters​

searchElement​

E

Value to match.

fromIndex?​

number = 0

Start position.

Returns​

number

Index or -1.

Remarks​

Time O(n), Space O(1)

Overrides​

LinearBase.indexOf


isEmpty()​

abstract isEmpty(): boolean;

Defined in: data-structures/base/iterable-element-base.ts:309

Indicates whether the structure currently contains no elements.

Returns​

boolean

true if empty; otherwise false.

Remarks​

Expected Time O(1), Space O(1) for most implementations.

Inherited from​

LinearBase.isEmpty


join()​

join(separator?): string;

Defined in: data-structures/base/linear-base.ts:218

Join all elements into a string.

Parameters​

separator?​

string = ','

Separator string.

Returns​

string

Concatenated string.

Remarks​

Time O(n), Space O(n)

Inherited from​

LinearBase.join


keys()​

keys(): IterableIterator<number>;

Defined in: data-structures/base/iterable-element-base.ts:218

Return an iterator of numeric indices (Array-compatible).

Returns​

IterableIterator<number>

Remarks​

Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.

Inherited from​

LinearBase.keys


lastIndexOf()​

lastIndexOf(searchElement, fromIndex?): number;

Defined in: data-structures/base/linear-base.ts:440

Linked-list optimized lastIndexOf (reverse scan).

Parameters​

searchElement​

E

Value to match.

fromIndex?​

number = ...

Start position.

Returns​

number

Index or -1.

Remarks​

Time O(n), Space O(1)

Overrides​

LinearBase.lastIndexOf


map()​

abstract map<EM, RM>(
callback,
options?,
thisArg?): IterableElementBase<EM, RM>;

Defined in: data-structures/base/iterable-element-base.ts:342

Maps each element to a new element and returns a new iterable structure.

Type Parameters​

EM​

EM

The mapped element type.

RM​

RM

The mapped raw element type used internally by the target structure.

Parameters​

callback​

ElementCallback<E, R, EM>

Function with signature (value, index, self) => mapped.

options?​

IterableElementBaseOptions<EM, RM>

Optional options for the returned structure, including its toElementFn.

thisArg?​

unknown

Optional this binding for the callback.

Returns​

IterableElementBase<EM, RM>

A new IterableElementBase<EM, RM> containing mapped elements.

Remarks​

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

Inherited from​

LinearBase.map


mapSame()​

abstract mapSame(callback, thisArg?): this;

Defined in: data-structures/base/iterable-element-base.ts:358

Maps each element to the same element type and returns the same concrete structure type.

Parameters​

callback​

ElementCallback<E, R, E>

Function with signature (value, index, self) => mappedValue.

thisArg?​

unknown

Optional this binding for the callback.

Returns​

this

A new instance of the same concrete type with mapped elements.

Remarks​

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

Inherited from​

LinearBase.mapSame


print()​

print(): void;

Defined in: data-structures/base/iterable-element-base.ts:298

Prints toVisual() to the console. Intended for quick debugging.

Returns​

void

void.

Remarks​

Time O(n) due to materialization, Space O(n) for the intermediate representation.

Inherited from​

LinearBase.print


push()​

abstract push(elementOrNode): boolean;

Defined in: data-structures/base/linear-base.ts:331

Append one element or node to the tail.

Parameters​

elementOrNode​

E | NODE

Element or node.

Returns​

boolean

true if appended.

Remarks​

Time O(1) amortized typical, Space O(1)

Inherited from​

LinearBase.push


pushMany()​

abstract pushMany(elements): boolean[];

Defined in: data-structures/base/linear-base.ts:339

Append many elements/nodes at once.

Parameters​

elements​

| Iterable<E, any, any> | Iterable<R, any, any> | Iterable<NODE, any, any>

Iterable of elements or nodes.

Returns​

boolean[]

Array of booleans indicating append success.

Remarks​

Time O(n), Space O(1)

Inherited from​

LinearBase.pushMany


reduce()​

Reduces all elements to a single accumulated value.

Param​

Reducer of signature (acc, value, index, self) => nextAcc. The first element is used as the initial accumulator.

Param​

Reducer of signature (acc, value, index, self) => nextAcc.

Param​

The initial accumulator value of type E.

Template​

The accumulator type when it differs from E.

Param​

Reducer of signature (acc: U, value, index, self) => U.

Param​

The initial accumulator value of type U.

Remarks​

Time O(n), Space O(1). Throws if called on an empty structure without initialValue.

Call Signature​

reduce(callbackfn): E;

Defined in: data-structures/base/iterable-element-base.ts:225

Parameters​
callbackfn​

ReduceElementCallback<E, R>

Returns​

E

Inherited from​

LinearBase.reduce

Call Signature​

reduce(callbackfn, initialValue): E;

Defined in: data-structures/base/iterable-element-base.ts:226

Parameters​
callbackfn​

ReduceElementCallback<E, R>

initialValue​

E

Returns​

E

Inherited from​

LinearBase.reduce

Call Signature​

reduce<U>(callbackfn, initialValue): U;

Defined in: data-structures/base/iterable-element-base.ts:227

Type Parameters​
U​

U

Parameters​
callbackfn​

ReduceElementCallback<E, R, U>

initialValue​

U

Returns​

U

Inherited from​

LinearBase.reduce


reduceRight()​

reduceRight<U>(callbackfn, initialValue): U;

Defined in: data-structures/base/linear-base.ts:552

Right-to-left reduction using reverse iterator.

Type Parameters​

U​

U

Parameters​

callbackfn​

ReduceLinearCallback<E, U>

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

initialValue​

U

Initial accumulator.

Returns​

U

Final accumulator.

Remarks​

Time O(n), Space O(1)

Overrides​

LinearBase.reduceRight


reverse()​

abstract reverse(): this;

Defined in: data-structures/base/linear-base.ts:312

Reverse the order of elements in-place (or equivalent).

Returns​

this

This list.

Remarks​

Time O(n), Space O(1)

Inherited from​

LinearBase.reverse


setAt()​

abstract setAt(index, value): boolean;

Defined in: data-structures/base/linear-base.ts:298

Set the value at an index.

Parameters​

index​

number

Position (0-based).

value​

E

New value.

Returns​

boolean

true if updated.

Remarks​

Time O(1) typical, Space O(1)

Inherited from​

LinearBase.setAt


slice()​

slice(start?, end?): this;

Defined in: data-structures/base/linear-base.ts:481

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).

Remarks​

Time O(n), Space O(n)

Overrides​

LinearBase.slice


some()​

some(predicate, thisArg?): boolean;

Defined in: data-structures/base/iterable-element-base.ts:110

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).

thisArg?​

unknown

Optional this binding for the predicate.

Returns​

boolean

true if any element passes; otherwise false.

Remarks​

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

Inherited from​

LinearBase.some


sort()​

sort(compareFn?): this;

Defined in: data-structures/base/linear-base.ts:179

In-place stable order via array sort semantics.

Parameters​

compareFn?​

(a, b) => number

Comparator (a, b) => number.

Returns​

this

This container.

Remarks​

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

Inherited from​

LinearBase.sort


splice()​

splice(
start,
deleteCount?, ...
items): this;

Defined in: data-structures/base/linear-base.ts:507

Splice by walking node iterators from the start index.

Parameters​

start​

number

Start index.

deleteCount?​

number = 0

How many elements to remove.

items​

...E[]

Elements to insert after the splice point.

Returns​

this

Removed elements as a new list (this type).

Remarks​

Time O(n + m), Space O(min(n, m)) where m = items.length

Overrides​

LinearBase.splice


toArray()​

toArray(): E[];

Defined in: data-structures/base/iterable-element-base.ts:275

Materializes the elements into a new array.

Returns​

E[]

A shallow array copy of the iteration order.

Remarks​

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

Inherited from​

LinearBase.toArray


toReversed()​

toReversed(): this;

Defined in: data-structures/base/linear-base.ts:319

Return a new instance of the same type with elements in reverse order (non-mutating).

Returns​

this

A new reversed instance.

Remarks​

Provided for familiarity when migrating from Array (ES2023 toReversed). Time O(n), Space O(n).

Inherited from​

LinearBase.toReversed


toReversedArray()​

toReversedArray(): E[];

Defined in: data-structures/base/linear-base.ts:227

Snapshot elements into a reversed array.

Returns​

E[]

New reversed array.

Remarks​

Time O(n), Space O(n)

Inherited from​

LinearBase.toReversedArray


toVisual()​

toVisual(): E[];

Defined in: data-structures/base/iterable-element-base.ts:287

Returns a representation of the structure suitable for quick visualization. Defaults to an array of elements; subclasses may override to provide richer visuals.

Returns​

E[]

A visual representation (array by default).

Remarks​

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

Inherited from​

LinearBase.toVisual


values()​

values(): IterableIterator<E>;

Defined in: data-structures/base/iterable-element-base.ts:72

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

Returns​

IterableIterator<E>

An IterableIterator<E> over all elements.

Remarks​

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

Inherited from​

LinearBase.values


Protected Members​

_toElementFn?​

protected optional _toElementFn?: (rawElement) => E;

Defined in: data-structures/base/iterable-element-base.ts:39

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

Parameters​

rawElement​

R

Returns​

E

Remarks​

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

Inherited from​

LinearBase._toElementFn

Accessors​

_createInstance()​

abstract protected _createInstance(options?): this;

Defined in: data-structures/base/linear-base.ts:380

Create an empty list of the same species.

Parameters​

options?​

LinearBaseOptions<E, R>

Runtime options to carry.

Returns​

this

Empty list (this type).

Remarks​

Time O(1), Space O(1)

Inherited from​

LinearBase._createInstance


_getIterator()​

abstract protected _getIterator(...args): IterableIterator<E>;

Defined in: data-structures/base/iterable-element-base.ts:381

Internal iterator factory used by the default iterator.

Parameters​

args​

...unknown[]

Optional iterator arguments.

Returns​

IterableIterator<E>

An iterator over elements.

Remarks​

Implementations should yield in O(1) per element with O(1) extra space when possible.

Inherited from​

LinearBase._getIterator


_getNodeIterator()​

abstract protected _getNodeIterator(...args): IterableIterator<NODE>;

Defined in: data-structures/base/linear-base.ts:601

Iterate linked nodes from head to tail.

Parameters​

args​

...unknown[]

Returns​

IterableIterator<NODE>

Iterator over nodes.

Remarks​

Time O(n), Space O(1)


_getPrevNode()​

abstract protected _getPrevNode(node): NODE | undefined;

Defined in: data-structures/base/linear-base.ts:609

Get previous node of a given node.

Parameters​

node​

NODE

Current node.

Returns​

NODE | undefined

Previous node or undefined.

Remarks​

Time O(1)~O(n) depending on list variant (singly vs doubly), Space O(1)


_getReverseIterator()​

abstract protected _getReverseIterator(...args): IterableIterator<E>;

Defined in: data-structures/base/linear-base.ts:387

Reverse-direction iterator over elements.

Parameters​

args​

...unknown[]

Returns​

IterableIterator<E>

Iterator of elements from tail to head.

Remarks​

Time O(n), Space O(1)

Inherited from​

LinearBase._getReverseIterator