Home Manual Reference Source

Function

Static Public Summary
public

Node(value: any)

Base node class.

public

concat(x: Node, y: Node): Node

Concatenate two input lists.

public

empty(): Node

Return an empty list.

public

from(iterable: Iterable): Node

Creates a list from an input iterable.

public

* iter(first: Node): IterableIterator<Node>

Generator of nodes in list in order.

public

len(x: Node): number

Compute the length of a list (can be empty).

public

pop(x: Node): [Node, Node]

Removes last Node from a list.

public

push(x: Node, value: any): Node

Push value to list.

public

Do nothing if x is empty or n is zero.

public

Do nothing if x is empty or n is zero.

public

shift(x: Node): [Node, Node]

Removes first Node from a list.

public

unshift(x: Node, value: Object): Node

Unshift value to list.

public

* values(first: Node): IterableIterator<any>

Generator of nodes in list in order.

Static Private Summary
private

_append(a: Node, x: Node)

Optimization of _concat when x contains a single element.

private

_concat(x: Node, y: Node)

Concatenate two input lists.

private

* _iter(first: Node): IterableIterator<Node>

Generator of nodes in list in order.

private

* _iter_fast(first: Node): IterableIterator<Node>

Generator of nodes in list in order.

private

Compute the length of a non-empty list.

private

_pop(x: Node): Node

Removes last Node from a non-empty list.

private

Removes input Node from its list.

private

Rotate list to the left n steps.

private

Rotate list to the right n steps.

private

Removes first Node from a non-empty list.

Static Public

public Node(value: any) source

Base node class.

Params:

NameTypeAttributeDescription
value any

The value to hold.

public concat(x: Node, y: Node): Node source

Concatenate two input lists.

Params:

NameTypeAttributeDescription
x Node

First node of first input list (can be null).

y Node

First node of second input list (can be null).

Return:

Node

First node of the output list (or null if empty).

public empty(): Node source

Return an empty list.

Return:

Node

The empty list.

public from(iterable: Iterable): Node source

Creates a list from an input iterable.

Params:

NameTypeAttributeDescription
iterable Iterable

The input iterable.

Return:

Node

First node of the newly created list (or null if empty list).

public * iter(first: Node): IterableIterator<Node> source

Generator of nodes in list in order.

Params:

NameTypeAttributeDescription
first Node

First node of the list (can be null).

Return:

IterableIterator<Node>

public len(x: Node): number source

Compute the length of a list (can be empty).

Params:

NameTypeAttributeDescription
x Node

First node of the input list (can be null).

Return:

number

The length of the input list.

public pop(x: Node): [Node, Node] source

Removes last Node from a list. Throws if input list is empty.

Params:

NameTypeAttributeDescription
x Node

First node.

Return:

[Node, Node]

New list (possibly null) and removed node.

public push(x: Node, value: any): Node source

Push value to list.

Params:

NameTypeAttributeDescription
x Node

First node of first input list (can be null).

value any

Value to push.

Return:

Node

The node at the front of the list (new node if empty, input node otherwise).

public rotate_left(x: Node, n: number): Node source

Do nothing if x is empty or n is zero. Rotate left n steps if n is positive. Rotate right n steps if n is negative.

Params:

NameTypeAttributeDescription
x Node

The current first node.

n number

Return:

Node

The new first node.

public rotate_right(x: Node, n: number): Node source

Do nothing if x is empty or n is zero. Rotate right n steps if n is positive. Rotate left n steps if n is negative.

Params:

NameTypeAttributeDescription
x Node

The current first node.

n number

Return:

Node

The new first node.

public shift(x: Node): [Node, Node] source

Removes first Node from a list. Throws if input list is empty.

Params:

NameTypeAttributeDescription
x Node

First node .

Return:

[Node, Node]

New list (possibly null) and removed node.

public unshift(x: Node, value: Object): Node source

Unshift value to list.

Params:

NameTypeAttributeDescription
x Node

First node of first input list (can be null).

value Object

Value to unshift.

Return:

Node

The node at the front of the list (hence, the new node).

public * values(first: Node): IterableIterator<any> source

Generator of nodes in list in order.

Params:

NameTypeAttributeDescription
first Node

First node of the list (can be null).

Return:

IterableIterator<any>

Static Private

private _append(a: Node, x: Node) source

Optimization of _concat when x contains a single element. Works even if x has dangling pointers x.next and x.prev.

Params:

NameTypeAttributeDescription
a Node

First node of list.

x Node

Node to be inserted at the end of list.

private _concat(x: Node, y: Node) source

Concatenate two input lists.

Params:

NameTypeAttributeDescription
x Node

First node of first input list.

y Node

First node of second input list.

private * _iter(first: Node): IterableIterator<Node> source

Generator of nodes in list in order. You are allowed to edit the current node.

/!\ Modifying the next pointer of the current node will NOT change which node comes next in the iteration.

Params:

NameTypeAttributeDescription
first Node

First node of the list.

Return:

IterableIterator<Node>

Yields nodes of a list in order.

private * _iter_fast(first: Node): IterableIterator<Node> source

Generator of nodes in list in order. The list cannot be empty. You should not modify the current node's next pointer unless you know what you are doing.

/!\ Modifying the next pointer of the current node will change which node comes next in the iteration.

Params:

NameTypeAttributeDescription
first Node

First node of the list.

Return:

IterableIterator<Node>

Yields nodes of a list in order.

private _len(x: Node): number source

Compute the length of a non-empty list.

Params:

NameTypeAttributeDescription
x Node

First node of the input list.

Return:

number

The length of the input list.

private _pop(x: Node): Node source

Removes last Node from a non-empty list.

Params:

NameTypeAttributeDescription
x Node

First node (not null).

Return:

Node

New list (possibly null).

private _remove(x: Node) source

Removes input Node from its list.

/!\ Pointers in the extracted node are left unchanged. /!\ x will have dangling pointers after removal if not single element.

Params:

NameTypeAttributeDescription
x Node

Node to remove.

private _rotate_left(x: Node, n: number): Node source

Rotate list to the left n steps. The parameter n must be positive.

Params:

NameTypeAttributeDescription
x Node

The current first node.

n number

MUST be positive.

Return:

Node

The new first node.

private _rotate_right(x: Node, n: number): Node source

Rotate list to the right n steps. The parameter n must be positive.

Params:

NameTypeAttributeDescription
x Node

The current first node.

n number

MUST be positive.

Return:

Node

The new first node.

private _shift(x: Node): Node source

Removes first Node from a non-empty list.

Params:

NameTypeAttributeDescription
x Node

First node (not null).

Return:

Node

New list (possibly null).