From 60b63de9f735ff0c2ba996803c51ee316c7c4065 Mon Sep 17 00:00:00 2001 From: Eyas Ranjous Date: Tue, 24 Dec 2019 00:34:32 -0600 Subject: [PATCH 1/9] typo --- src/maxHeap.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/maxHeap.js b/src/maxHeap.js index d1b7e1c..9924e28 100644 --- a/src/maxHeap.js +++ b/src/maxHeap.js @@ -84,7 +84,7 @@ class MaxHeap extends Heap { * returns a shallow copy of a max heap * @public * @override - * @returns {MinHeap} + * @returns {MaxHeap} */ clone() { return super.clone(MaxHeap); From 2a2da2c9e623214aeeb6fef1dfa302b47ce6b296 Mon Sep 17 00:00:00 2001 From: Eyas Ranjous Date: Tue, 24 Dec 2019 00:54:03 -0600 Subject: [PATCH 2/9] add table of content --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index b0878d3..228b357 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,24 @@ a complete javascript implementation for the Min/Max Heap data structures & Heap ![heap](https://user-images.githubusercontent.com/6517308/70871547-bd852900-1f65-11ea-909f-86f4d090f152.jpg) +# Table of Contents +* [Install](#install) +* [API](#build) + * [require](#require) + * [import](#import) + * [Creating a Heap](#create-a-heap) + * [new](#new) + * [.heapify(list)](#heapifylist) + * [.insert(key, value)](#insertkey-value) + * [.root()](#root) + * [.extractRoot()](#extractroot) + * [.serialize()](#serialize) + * [.size()](#size) + * [.clone()](#clone) + * [.sort()](#sort) + * [.clear()](#clear) + * [Build](#build) + ## install ```sh npm install --save @datastructures-js/heap From 75eead319241d6d983897f76d98a62d3d4c47abe Mon Sep 17 00:00:00 2001 From: Eyas Ranjous Date: Tue, 24 Dec 2019 00:58:55 -0600 Subject: [PATCH 3/9] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 228b357..7666e07 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ a complete javascript implementation for the Min/Max Heap data structures & Heap # Table of Contents * [Install](#install) -* [API](#build) +* [API](#api) * [require](#require) * [import](#import) * [Creating a Heap](#create-a-heap) @@ -18,7 +18,7 @@ a complete javascript implementation for the Min/Max Heap data structures & Heap * [.insert(key, value)](#insertkey-value) * [.root()](#root) * [.extractRoot()](#extractroot) - * [.serialize()](#serialize) + * [.serialize()](#serialize-topic) * [.size()](#size) * [.clone()](#clone) * [.sort()](#sort) @@ -189,7 +189,7 @@ console.log(max.serialize()); // { key: 'z', value: null } console.log(maxHeap.root().getKey()); // 'x' ``` -### .serialize() +

.serialize()

converts the heap into a list of serialized nodes. ##### runtime From 319bc14962a90dfd309485a3fce6b0795919f15d Mon Sep 17 00:00:00 2001 From: Eyas Ranjous Date: Tue, 24 Dec 2019 01:53:32 -0600 Subject: [PATCH 4/9] Update README.md --- README.md | 84 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 51 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 7666e07..7088b01 100644 --- a/README.md +++ b/README.md @@ -57,15 +57,20 @@ const maxHeap = new MaxHeap(); #### .heapify(list) converts an array of objects to a heap. -##### runtime -O(n) - -##### params -###### list<{number}|{string}|{object}> : {array} -elements can be number, string or serialized heap node objects. - -##### return : {Heap} -*MinHeap* or *MaxHeap* instance. + + + + + + + + + + + +
runtimeparamsreturn
O(n) + list: {array}
elements can be {number}, {string} or serialized heap node. +
{MinHeap} or {MaxHeap}
##### Example @@ -97,16 +102,20 @@ const maxHeap = MaxHeap.heapify(strList); ### .insert(key, value) insert a node into the heap. - -##### runtime -O(log(n)) - -##### params -###### key : {number} | {string} -the value that is used to compare nodes in the heap. - -###### value : {object} -the value that is associated with a key. + + + + + + + + + +
runtimeparams
O(log(n)) + key: {number} or {string}
the value that is used to compare nodes in the heap +

+ value: {object}
the value that is associated with a key +
##### Example @@ -135,20 +144,29 @@ maxHeap.insert('c', { name: 'test' }); ### .root() peeks on the root without removing it. -##### runtime -O(1) - -##### return : {HeapNode} -the root node in the heap. It implements the following interface - -###### .getKey() -returns the node's key that is used to compare with other nodes. - -###### .getValue() -returns the value that is associated with the key. - -###### .serialize() -returns an object literal of key/value of the node. + + + + + + + + + + + +
runtimeparamsreturn
O(1) + list: {array}
elements can be {number}, {string} or serialized heap node. +
{HeapNode}
the root node in the heap. It implements the following interface +

+ +.getKey() returns the node's key that is used to compare with other nodes. + +.getValue() returns the value that is associated with the key. + +.serialize() returns an object literal of key/value of the node. + +
##### Example From 902ea40b377aa66ab3de4ecbe59e159552e332cb Mon Sep 17 00:00:00 2001 From: Eyas Ranjous Date: Tue, 24 Dec 2019 01:57:12 -0600 Subject: [PATCH 5/9] Update README.md --- README.md | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 7088b01..5f4f25a 100644 --- a/README.md +++ b/README.md @@ -155,7 +155,7 @@ peeks on the root without removing it. list: {array}
elements can be {number}, {string} or serialized heap node. - {HeapNode}
the root node in the heap. It implements the following interface + {HeapNode}

.getKey() returns the node's key that is used to compare with other nodes. @@ -185,11 +185,17 @@ console.log(max.serialize()); // { key: 'z', value: null } ### .extractRoot() removes and returns the root node in the heap. -##### runtime -O(log(n)) - -##### return : {HeapNode} -the root node in the heap. + + + + + + + + + +
runtimereturn
O(log(n)){HeapNode} +
##### Example From 7d2a4e11358ebf5c369f4543b74ccaf46bb37c5a Mon Sep 17 00:00:00 2001 From: Eyas Ranjous Date: Tue, 24 Dec 2019 02:05:19 -0600 Subject: [PATCH 6/9] Update README.md --- README.md | 80 +++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 54 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 5f4f25a..b039c58 100644 --- a/README.md +++ b/README.md @@ -214,14 +214,19 @@ console.log(maxHeap.root().getKey()); // 'x' ```

.serialize()

-converts the heap into a list of serialized nodes. +converts the heap into a list of serialized nodes objects. -##### runtime -O(n) - -##### return : {array\} - -a serialized list of heap nodes + + + + + + + + + +
runtimereturn
O(n){array} +
##### Example @@ -253,11 +258,17 @@ console.log(maxHeap.serialize()); ### .size() -##### runtime -O(1) - -##### return : {number} -the number of nodes in the heap. + + + + + + + + + +
runtimereturn
O(1){number} +
##### Example ```js @@ -268,11 +279,17 @@ console.log(maxHeap.size()); // 6 ### .clone() creates a shallow copy of a heap by slicing the nodes array and passing it to a new heap instance. -##### runtime -O(n) - -##### return : {Heap} -*MinHeap* or *MaxHeap* instance. + + + + + + + + + +
runtimereturn
O(n){MinHeap} or {MaxHeap} +
##### Example @@ -287,11 +304,17 @@ console.log(minHeap.root().getKey()); // 30 ### .sort() implements Heap Sort and sorts a *Max Heap in ascneding order* or a *Min Heap in descending order*. -##### runtime -O(n\*log(n)) - -##### return : {array} -a sorted list by key of the heap nodes. + + + + + + + + + +
runtimereturn
O(n\*log(n)){array}
a sorted list by key of the heap nodes. +
*note : calling .sort() directly on a heap will mutate its nodes location. If you want to avoid that, you can sort a shallow copy of the heap.* @@ -324,8 +347,7 @@ console.log(minHeap.clone().sort()); // does not mutate the heap structure */ console.log(minHeap.root()); // HeapNode { key: 30, value: 'something' } ``` - -If you are using this npm for the purpose of sorting a list of elements using Heap Sort, you can do this: +To sort a list of elements directtly using Heap Sort, it can be done like: ```js const unsortedList = [3, 7, 2, 10, 4, 9, 8, 5, 1, 6]; @@ -340,8 +362,14 @@ const descSorted = MinHeap.heapify(unsortedList).sort().map(n => n.getKey()); ### .clear() clears the nodes in the heap. -##### runtime -O(1) + + + + + + + +
runtime
O(1)
##### Example From dd6a74d2a3dc20659c04bd72f3441ad163d59f11 Mon Sep 17 00:00:00 2001 From: Eyas Ranjous Date: Tue, 24 Dec 2019 02:06:19 -0600 Subject: [PATCH 7/9] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b039c58..9f2233a 100644 --- a/README.md +++ b/README.md @@ -310,7 +310,7 @@ implements Heap Sort and sorts a *Max Heap in ascneding order* or a *Min Heap in return - O(n\*log(n)) + O(n*log(n)) {array}
a sorted list by key of the heap nodes. From 1d82acbda7ca73ff227676990e51b1aaeb1940e8 Mon Sep 17 00:00:00 2001 From: Eyas Ranjous Date: Tue, 24 Dec 2019 02:09:05 -0600 Subject: [PATCH 8/9] v1.1.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d1b5565..3262e2a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@datastructures-js/heap", - "version": "1.1.0", + "version": "1.1.1", "description": "Min/Max Heap & Heap Sort implementation in javascript", "main": "index.js", "scripts": { From 6b863eb9cec26865b98e47c6d9f1e5d82dc9f4fe Mon Sep 17 00:00:00 2001 From: Eyas Ranjous Date: Tue, 24 Dec 2019 02:10:21 -0600 Subject: [PATCH 9/9] v1.1.1 --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index aeecd83..c026abe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.1.1] - 2019-12-24 +### Fixed +- add a table of content to readme + ## [1.1.0] - 2019-12-16 ### Added `.serialize()` to convert a heap to a list of serialized nodes.