Home Manual Reference Source

Function

Static Public Summary
public

decreasekey(compare: Function, min: Node, node: Node, value: Object): Node

Decrease-key: remove the subtree rooted at the key to be decreased, replace the key with a smaller key, then merge the result back into the heap.

public

merge(compare: Function, A: Node, B: Node): Node

Merge: compare the two root elements, the smaller remains the root of the result, the larger element and its subtree is appended as a child of this root.

public

mergepairs(compare: Function, prev: Node): Node

Recursively builds a heap from an iterator of nodes by merging them pair by pair.

public

prepend(A: Node, B: Node): Node

Set B as the first child of A.

Static Public

public decreasekey(compare: Function, min: Node, node: Node, value: Object): Node source

Decrease-key: remove the subtree rooted at the key to be decreased, replace the key with a smaller key, then merge the result back into the heap.

Params:

NameTypeAttributeDescription
compare Function

Comparison function for keys.

min Node

Current minimum-key node != null with .prev = .next = null.

node Node

Node != null to update with .prev != null.

value Object

The new value for the key of the node to update.

Return:

Node

Returns the node containing the minimum key.

public merge(compare: Function, A: Node, B: Node): Node source

Merge: compare the two root elements, the smaller remains the root of the result, the larger element and its subtree is appended as a child of this root.

/!\ Precondition:

  1. A != null and A.next = A.prev = null
  2. B != null and B.next = B.prev = null

Params:

NameTypeAttributeDescription
compare Function

Comparison functions for keys.

A Node

The first input node.

B Node

The second input node.

Return:

Node

The input node with smallest key with .next = .prev = null.

public mergepairs(compare: Function, prev: Node): Node source

Recursively builds a heap from an iterator of nodes by merging them pair by pair.

Params:

NameTypeAttributeDescription
compare Function

Comparison function for node keys.

prev Node

Last node before first of list. First node is prev.next.

Return:

Node

The root node with .next = .prev = null or null for an empty iterator.

public prepend(A: Node, B: Node): Node source

Set B as the first child of A.

/!\ Precondition:

  1. A != null
  2. B != null
  3. A.next = A.prev = B.next = B.prev = null

Params:

NameTypeAttributeDescription
A Node
B Node

Return:

Node

The input node A with .next = .prev = null.