Class: Heap

algo.core. Heap

new Heap(options)

A classic heap ( priority queue ) data structure. The heap exists in the graph name space because it uses a binary tree structure to manage itself, but its implementation is array based.
Parameters:
Name Type Description
options
Source:

Methods

<static> isEmpty() → {boolean}

we are empty when n is zero
Source:
Returns:
Type
boolean

dequeue() → {*}

remove an item from the heap, returning a object of the form {value:number, payload: object}
Source:
Returns:
Type
*

element(i) → {algo.render.Element}

getter for the elememt property of a heap item identified by index
Parameters:
Name Type Description
i
Source:
Returns:
Type
algo.render.Element

enqueue(v)

add an item to the heap. The value, v should always be a number but the associated payload can be any object
Parameters:
Name Type Description
v
Source:

isEmpty() → {boolean}

return true if the item is empty
Source:
Returns:
Type
boolean

isNull(i) → {boolean}

true if the index is out of bounds
Parameters:
Name Type Description
i
Source:
Returns:
Type
boolean

leftChild(i) → {number}

return left child of item
Parameters:
Name Type Description
i
Source:
Returns:
Type
number

parent(i) → {*}

return parent item of item
Parameters:
Name Type Description
i
Source:
Returns:
Type
*

payload(i) → {*}

getter for the payload property of a heap item identified by index
Parameters:
Name Type Description
i
Source:
Returns:
Type
*

rightChild(i) → {number}

return right child of item
Parameters:
Name Type Description
i
Source:
Returns:
Type
number

siftDown(i)

move the item at i down the tree until it reaches a suitable resting place.
Parameters:
Name Type Description
i
Source:

siftUp(i)

move the item at i up the tree until it reaches a suitable resting place. We will use the comparator function supplied to the constructor or we will just treat our items as intrinsic types and compare with === <= etc.
Parameters:
Name Type Description
i
Source:

swap(i, j)

swap two items in the heap, used during siftUp and siftDown operations
Parameters:
Name Type Description
i
j
Source:

value(i) → {*}

getter for the value property of a heap item identified by index
Parameters:
Name Type Description
i
Source:
Returns:
Type
*