Skip to content

Commit

Permalink
Update API doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyriar committed Nov 15, 2015
1 parent 2899602 commit 1ad7cc7
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 1 deletion.
74 changes: 73 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,76 @@ TODO

## API

TODO
### BinaryHeap

Creates a binary heap.

**Parameters**

- `customCompare` **function** An optional custom node comparison
function.

#### buildHeap

Builds a heap with the provided keys and values, this will discard the
heap's current data.

**Parameters**

- `keys` **Array** An array of keys.
- `values` **Array** An array of values. This must be the same size as the
key array.

#### clear

Clears the heap's data, making it an empty heap.

#### extractMinimum

Extracts and returns the minimum node from the heap.

Returns **Node** node The heap's minimum node or undefined if the heap is
empty.

#### findMinimum

Returns the minimum node from the heap.

Returns **Node** node The heap's minimum node or undefined if the heap is
empty.

#### insert

Inserts a new key-value pair into the heap.

**Parameters**

- `key` **Object** The key to insert.
- `value` **Object** The value to insert.

Returns **Node** node The inserted node.

#### isEmpty

Returns **boolean** Whether the heap is empty.

#### size

Returns **number** The size of the heap.

#### union

Joins another heap to this one.

**Parameters**

- `otherHeap` **BinaryHeap** The other heap.

### Node

Creates a node.

**Parameters**

- `key` **Object** The key of the new node.
- `value` **Object** The value of the new node.
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ BinaryHeap.prototype.union = function (otherHeap) {
/**
* Compares two nodes with each other.
*
* @private
* @param {Object} a The first key to compare.
* @param {Object} b The second key to compare.
* @return -1, 0 or 1 if a < b, a == b or a > b respectively.
Expand All @@ -144,6 +145,7 @@ BinaryHeap.prototype.compare = function (a, b) {
/**
* Heapifies a node.
*
* @private
* @param {BinaryHeap} heap The heap containing the node to heapify.
* @param {number} i The index of the node to heapify.
*/
Expand All @@ -168,6 +170,7 @@ function heapify(heap, i) {
/**
* Builds a heap from a node array, this will discard the heap's current data.
*
* @private
* @param {BinaryHeap} heap The heap to override.
* @param {Node[]} nodeArray The array of nodes for the new heap.
*/
Expand All @@ -181,6 +184,7 @@ function buildHeapFromNodeArray(heap, nodeArray) {
/**
* Swaps two values in an array.
*
* @private
* @param {Array} array The array to swap on.
* @param {number} a The index of the first element.
* @param {number} a The index of the second element.
Expand All @@ -196,6 +200,7 @@ function swap(array, a, b) {
/**
* Gets the index of a node's parent.
*
* @private
* @param {number} i The index of the node to get the parent of.
* @return {number} The index of the node's parent.
*/
Expand All @@ -209,6 +214,7 @@ function getParent(i) {
/**
* Gets the index of a node's left child.
*
* @private
* @param {number} i The index of the node to get the left child of.
* @return {number} The index of the node's left child.
*/
Expand All @@ -219,6 +225,7 @@ function getLeft(i) {
/**
* Gets the index of a node's right child.
*
* @private
* @param {number} i The index of the node to get the right child of.
* @return {number} The index of the node's right child.
*/
Expand Down

0 comments on commit 1ad7cc7

Please sign in to comment.