From 7f7784f2be273bb95d9f714968052209f37e2549 Mon Sep 17 00:00:00 2001 From: Travis Clarke Date: Thu, 17 May 2018 15:21:39 -0700 Subject: [PATCH] prepare 0.0.8 --- dist/super.es.js | 2 +- dist/super.js | 2 +- dist/super.min.js | 2 +- docs/README.md | 98 ++ .../Array/src/lib/Array.js~_Array.html | 1 + .../src/lib/BinaryTree.js~BinaryTree.html | 1 + .../lib/BinaryTreeNode.js~BinaryTreeNode.html | 1 + .../src/lib/LinkedList.js~LinkedList.html | 1 + .../src/lib/ListNode.js~ListNode.html | 1 + .../packages/Map/src/lib/Map.js~_Map.html | 1 + .../Number/src/lib/Number.js~_Number.html | 1 + .../Object/src/lib/Object.js~_Object.html | 1 + .../lib/PriorityQueue.js~PriorityQueue.html | 1 + .../src/lib/QueueNode.js~QueueNode.html | 1 + .../Queue/src/lib/Queue.js~Queue.html | 1 + .../String/src/lib/String.js~_String.html | 1 + .../packages/Trie/src/lib/Trie.js~Trie.html | 1 + .../Trie/src/lib/TrieNode.js~TrieNode.html | 1 + docs/coverage.json | 14 +- .../file/packages/Array/src/lib/Array.js.html | 1 + .../BinaryTree/src/lib/BinaryTree.js.html | 1 + .../BinaryTree/src/lib/BinaryTreeNode.js.html | 1 + .../BubbleSort/src/lib/BubbleSort.js.html | 1 + .../src/lib/InsertionSort.js.html | 1 + .../LinkedList/src/lib/LinkedList.js.html | 1 + .../LinkedList/src/lib/ListNode.js.html | 1 + docs/file/packages/Map/src/lib/Map.js.html | 1 + docs/file/packages/Math/src/lib/Math.js.html | 1 + .../MergeSort/src/lib/MergeSort.js.html | 1 + .../packages/Number/src/lib/Number.js.html | 1 + .../packages/Object/src/lib/Object.js.html | 1 + .../src/lib/PriorityQueue.js.html | 1 + .../PriorityQueue/src/lib/QueueNode.js.html | 1 + .../file/packages/Queue/src/lib/Queue.js.html | 1 + .../QuickSort/src/lib/QuickSort.js.html | 1 + .../src/lib/SelectionSort.js.html | 1 + docs/file/packages/Set/src/lib/Set.js.html | 1 + .../packages/String/src/lib/String.js.html | 1 + docs/file/packages/Trie/src/lib/Trie.js.html | 1 + .../packages/Trie/src/lib/TrieNode.js.html | 1 + docs/function/index.html | 1 + docs/identifiers.html | 40 + docs/index.html | 1 + docs/index.json | 839 +++++++++++++++--- docs/script/search_index.js | 144 ++- docs/source.html | 11 +- docs/typedef/index.html | 1 + docs/variable/index.html | 1 + package.json | 2 +- packages/Heap/src/lib/Heap.js | 8 +- 50 files changed, 1037 insertions(+), 164 deletions(-) diff --git a/dist/super.es.js b/dist/super.es.js index dd25188..325efdf 100644 --- a/dist/super.es.js +++ b/dist/super.es.js @@ -4267,7 +4267,7 @@ var Trie = function () { return Trie; }(); -var version = "0.0.7"; +var version = "0.0.8"; var Super = { version: version, diff --git a/dist/super.js b/dist/super.js index 7e6e643..3f2d992 100644 --- a/dist/super.js +++ b/dist/super.js @@ -4273,7 +4273,7 @@ return Trie; }(); - var version = "0.0.7"; + var version = "0.0.8"; var Super = { version: version, diff --git a/dist/super.min.js b/dist/super.min.js index 557504d..a534146 100644 --- a/dist/super.min.js +++ b/dist/super.min.js @@ -17,4 +17,4 @@ for(var i,o=this.entries()[Symbol.iterator]();!(e=(i=o.next()).done);e=!0){var u ;if((void 0===e?"undefined":m(e))!==O.NUMBER)throw Error("Unable to insert non-number priority: "+e);return this._queue.push(new X(t,e)),this._queue.sort(this._comparator),this.size}},{key:"deleteMax",value:function(){return this._queue.shift()}},{key:"deleteHigh",value:function(){return this.deleteMax()}},{key:"deleteMin",value:function(){return this._queue.pop()}},{key:"deleteLow",value:function(){return this.deleteMin()}},{key:"toArray",value:function(){return this._queue.slice(0)}},{key:"size",get:function(){return this._queue.length}},{key:"max",get:function(){return this._queue[0]}},{key:"high",get:function(){return this.max}},{key:"min",get:function(){return this._queue[this._queue.length-1]}},{key:"low",get:function(){return this.min}}],[{key:"_wrapComparator",value:function(t){return function(e,r){return t(e.value,r.value)}}},{key:"_defaultComparator",value:function(t,e){return t.priority0&&void 0!==arguments[0]?arguments[0]:St.ROOT;w(this,t),this._char=e,this._isCompleteWord=!1,this._children=new Map}return j(t,[{key:"has",value:function(t){return this._children.has(t)}},{key:"get",value:function(t){return this._children.get(t)}},{key:"set",value:function(t,e){this._children.set(t,e)}},{key:"delete",value:function(t){this._children.delete(t)}},{key:"count",get:function(){return this._children.size}},{key:"char",get:function(){return this._char}},{key:"isCompleteWord",get:function(){return this._isCompleteWord}},{key:"isLeafNode",get:function(){return 0===this.count}}]),t}(),xt=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];w(this,t),this._root=new At;var r=!0,n=!1,i=void 0;try{for(var o,u=e[Symbol.iterator]();!(r=(o=u.next()).done);r=!0){this.insert(o.value)}}catch(t){n=!0,i=t}finally{try{!r&&u.return&&u.return()}finally{if(n)throw i}}}return j(t,[{key:"insert",value:function(t){if((void 0===t?"undefined":m(t))!==O.STRING)throw Error("Unable to insert non-string value: "+t);var e=this.root,r=!0,n=!1,i=void 0;try{for(var o,u=t[Symbol.iterator]();!(r=(o=u.next()).done);r=!0){var a=o.value;if(e.has(a))e=e.get(a);else{var l=new At(a);e.set(a,l),e=l}}}catch(t){n=!0,i=t}finally{try{!r&&u.return&&u.return()}finally{if(n)throw i}}e._isCompleteWord=!0}},{key:"remove",value:function(t){function e(r){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(!r)return!1;if(n===t.length)return r._isCompleteWord=!1,r.isLeafNode;var i=t[n];return e(r.get(i),n+1)?(r.delete(i),r.isLeafNode):void 0}if((void 0===t?"undefined":m(t))!==O.STRING)throw Error("Unable to remove non-string value: "+t);return e(this.root)}},{key:"search",value:function(t){ -for(var e=this.root,r=0;r lowest priority (min) + +| Name | Type | Attribute | Description | +| --- | --- | --- | --- | +| a | * | nullable: undefined | +| b | * | nullable: undefined | + +### `isEmpty(): boolean` + +Check if heap is empty + +| Name | Type | Attribute | Description | +| --- | --- | --- | --- | + +### `clear(): void` + +Clear the items from the heap + +| Name | Type | Attribute | Description | +| --- | --- | --- | --- | + +### `insert(value: Item): number` + +Insert an item into the heap + +| Name | Type | Attribute | Description | +| --- | --- | --- | --- | +| value | Item | | item to insert | + +### `deleteMax(): Item` + +Remove and return the maximum item + +| Name | Type | Attribute | Description | +| --- | --- | --- | --- | + +### `deleteMin(): Item` + +Remove and return the minimum item + +| Name | Type | Attribute | Description | +| --- | --- | --- | --- | + +### `_percolateDown(index: number)` + +Heapify down + +| Name | Type | Attribute | Description | +| --- | --- | --- | --- | +| index | number | | start index | + +### `_percolateUp(index: number)` + +Heapify up + +| Name | Type | Attribute | Description | +| --- | --- | --- | --- | +| index | number | | start index | + +### `toArray(): Array` + +Convert the heap to an array + +| Name | Type | Attribute | Description | +| --- | --- | --- | --- | + ## `LinkedList` LinkedList with superpowers! 💪 diff --git a/docs/class/packages/Array/src/lib/Array.js~_Array.html b/docs/class/packages/Array/src/lib/Array.js~_Array.html index 6581885..7a9eb0f 100644 --- a/docs/class/packages/Array/src/lib/Array.js~_Array.html +++ b/docs/class/packages/Array/src/lib/Array.js~_Array.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • diff --git a/docs/class/packages/BinaryTree/src/lib/BinaryTree.js~BinaryTree.html b/docs/class/packages/BinaryTree/src/lib/BinaryTree.js~BinaryTree.html index 37e1bcb..a53535d 100644 --- a/docs/class/packages/BinaryTree/src/lib/BinaryTree.js~BinaryTree.html +++ b/docs/class/packages/BinaryTree/src/lib/BinaryTree.js~BinaryTree.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • diff --git a/docs/class/packages/BinaryTree/src/lib/BinaryTreeNode.js~BinaryTreeNode.html b/docs/class/packages/BinaryTree/src/lib/BinaryTreeNode.js~BinaryTreeNode.html index f29067a..d31729d 100644 --- a/docs/class/packages/BinaryTree/src/lib/BinaryTreeNode.js~BinaryTreeNode.html +++ b/docs/class/packages/BinaryTree/src/lib/BinaryTreeNode.js~BinaryTreeNode.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • diff --git a/docs/class/packages/LinkedList/src/lib/LinkedList.js~LinkedList.html b/docs/class/packages/LinkedList/src/lib/LinkedList.js~LinkedList.html index 7978f42..a5723dc 100644 --- a/docs/class/packages/LinkedList/src/lib/LinkedList.js~LinkedList.html +++ b/docs/class/packages/LinkedList/src/lib/LinkedList.js~LinkedList.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • diff --git a/docs/class/packages/LinkedList/src/lib/ListNode.js~ListNode.html b/docs/class/packages/LinkedList/src/lib/ListNode.js~ListNode.html index 2f318de..efeba88 100644 --- a/docs/class/packages/LinkedList/src/lib/ListNode.js~ListNode.html +++ b/docs/class/packages/LinkedList/src/lib/ListNode.js~ListNode.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • diff --git a/docs/class/packages/Map/src/lib/Map.js~_Map.html b/docs/class/packages/Map/src/lib/Map.js~_Map.html index b17a964..67d11fe 100644 --- a/docs/class/packages/Map/src/lib/Map.js~_Map.html +++ b/docs/class/packages/Map/src/lib/Map.js~_Map.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • diff --git a/docs/class/packages/Number/src/lib/Number.js~_Number.html b/docs/class/packages/Number/src/lib/Number.js~_Number.html index fdbde04..9a27e2e 100644 --- a/docs/class/packages/Number/src/lib/Number.js~_Number.html +++ b/docs/class/packages/Number/src/lib/Number.js~_Number.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • diff --git a/docs/class/packages/Object/src/lib/Object.js~_Object.html b/docs/class/packages/Object/src/lib/Object.js~_Object.html index 021407f..0164f86 100644 --- a/docs/class/packages/Object/src/lib/Object.js~_Object.html +++ b/docs/class/packages/Object/src/lib/Object.js~_Object.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • diff --git a/docs/class/packages/PriorityQueue/src/lib/PriorityQueue.js~PriorityQueue.html b/docs/class/packages/PriorityQueue/src/lib/PriorityQueue.js~PriorityQueue.html index 6d729fa..209444d 100644 --- a/docs/class/packages/PriorityQueue/src/lib/PriorityQueue.js~PriorityQueue.html +++ b/docs/class/packages/PriorityQueue/src/lib/PriorityQueue.js~PriorityQueue.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • diff --git a/docs/class/packages/PriorityQueue/src/lib/QueueNode.js~QueueNode.html b/docs/class/packages/PriorityQueue/src/lib/QueueNode.js~QueueNode.html index d5e78fc..5c6c23d 100644 --- a/docs/class/packages/PriorityQueue/src/lib/QueueNode.js~QueueNode.html +++ b/docs/class/packages/PriorityQueue/src/lib/QueueNode.js~QueueNode.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • diff --git a/docs/class/packages/Queue/src/lib/Queue.js~Queue.html b/docs/class/packages/Queue/src/lib/Queue.js~Queue.html index 9111356..440004f 100644 --- a/docs/class/packages/Queue/src/lib/Queue.js~Queue.html +++ b/docs/class/packages/Queue/src/lib/Queue.js~Queue.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • diff --git a/docs/class/packages/String/src/lib/String.js~_String.html b/docs/class/packages/String/src/lib/String.js~_String.html index dad3b8f..9b77cc3 100644 --- a/docs/class/packages/String/src/lib/String.js~_String.html +++ b/docs/class/packages/String/src/lib/String.js~_String.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • diff --git a/docs/class/packages/Trie/src/lib/Trie.js~Trie.html b/docs/class/packages/Trie/src/lib/Trie.js~Trie.html index f5575ee..682c7b3 100644 --- a/docs/class/packages/Trie/src/lib/Trie.js~Trie.html +++ b/docs/class/packages/Trie/src/lib/Trie.js~Trie.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • diff --git a/docs/class/packages/Trie/src/lib/TrieNode.js~TrieNode.html b/docs/class/packages/Trie/src/lib/TrieNode.js~TrieNode.html index 1e3280d..a3443b8 100644 --- a/docs/class/packages/Trie/src/lib/TrieNode.js~TrieNode.html +++ b/docs/class/packages/Trie/src/lib/TrieNode.js~TrieNode.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • diff --git a/docs/coverage.json b/docs/coverage.json index 7cec502..b64d0b0 100644 --- a/docs/coverage.json +++ b/docs/coverage.json @@ -1,7 +1,7 @@ { - "coverage": "85.53%", - "expectCount": 159, - "actualCount": 136, + "coverage": "85.95%", + "expectCount": 178, + "actualCount": 153, "files": { "packages/Array/src/lib/Array.js": { "expectCount": 9, @@ -30,6 +30,14 @@ "actualCount": 1, "undocumentLines": [] }, + "packages/Heap/src/lib/Heap.js": { + "expectCount": 19, + "actualCount": 17, + "undocumentLines": [ + 34, + 35 + ] + }, "packages/InsertionSort/src/lib/InsertionSort.js": { "expectCount": 1, "actualCount": 1, diff --git a/docs/file/packages/Array/src/lib/Array.js.html b/docs/file/packages/Array/src/lib/Array.js.html index 787a856..9c669e8 100644 --- a/docs/file/packages/Array/src/lib/Array.js.html +++ b/docs/file/packages/Array/src/lib/Array.js.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • diff --git a/docs/file/packages/BinaryTree/src/lib/BinaryTree.js.html b/docs/file/packages/BinaryTree/src/lib/BinaryTree.js.html index 468d0d2..1014b96 100644 --- a/docs/file/packages/BinaryTree/src/lib/BinaryTree.js.html +++ b/docs/file/packages/BinaryTree/src/lib/BinaryTree.js.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • diff --git a/docs/file/packages/BinaryTree/src/lib/BinaryTreeNode.js.html b/docs/file/packages/BinaryTree/src/lib/BinaryTreeNode.js.html index 6747236..2e334bd 100644 --- a/docs/file/packages/BinaryTree/src/lib/BinaryTreeNode.js.html +++ b/docs/file/packages/BinaryTree/src/lib/BinaryTreeNode.js.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • diff --git a/docs/file/packages/BubbleSort/src/lib/BubbleSort.js.html b/docs/file/packages/BubbleSort/src/lib/BubbleSort.js.html index 9d3e9a6..41afef9 100644 --- a/docs/file/packages/BubbleSort/src/lib/BubbleSort.js.html +++ b/docs/file/packages/BubbleSort/src/lib/BubbleSort.js.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • diff --git a/docs/file/packages/InsertionSort/src/lib/InsertionSort.js.html b/docs/file/packages/InsertionSort/src/lib/InsertionSort.js.html index 4901d33..b209947 100644 --- a/docs/file/packages/InsertionSort/src/lib/InsertionSort.js.html +++ b/docs/file/packages/InsertionSort/src/lib/InsertionSort.js.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • diff --git a/docs/file/packages/LinkedList/src/lib/LinkedList.js.html b/docs/file/packages/LinkedList/src/lib/LinkedList.js.html index f230897..d9b50e3 100644 --- a/docs/file/packages/LinkedList/src/lib/LinkedList.js.html +++ b/docs/file/packages/LinkedList/src/lib/LinkedList.js.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • diff --git a/docs/file/packages/LinkedList/src/lib/ListNode.js.html b/docs/file/packages/LinkedList/src/lib/ListNode.js.html index 0153676..81feda4 100644 --- a/docs/file/packages/LinkedList/src/lib/ListNode.js.html +++ b/docs/file/packages/LinkedList/src/lib/ListNode.js.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • diff --git a/docs/file/packages/Map/src/lib/Map.js.html b/docs/file/packages/Map/src/lib/Map.js.html index 87dba7c..164c303 100644 --- a/docs/file/packages/Map/src/lib/Map.js.html +++ b/docs/file/packages/Map/src/lib/Map.js.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • diff --git a/docs/file/packages/Math/src/lib/Math.js.html b/docs/file/packages/Math/src/lib/Math.js.html index 3549f00..ebef017 100644 --- a/docs/file/packages/Math/src/lib/Math.js.html +++ b/docs/file/packages/Math/src/lib/Math.js.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • diff --git a/docs/file/packages/MergeSort/src/lib/MergeSort.js.html b/docs/file/packages/MergeSort/src/lib/MergeSort.js.html index 82570d9..c3f83c9 100644 --- a/docs/file/packages/MergeSort/src/lib/MergeSort.js.html +++ b/docs/file/packages/MergeSort/src/lib/MergeSort.js.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • diff --git a/docs/file/packages/Number/src/lib/Number.js.html b/docs/file/packages/Number/src/lib/Number.js.html index bef1bd4..4de33bc 100644 --- a/docs/file/packages/Number/src/lib/Number.js.html +++ b/docs/file/packages/Number/src/lib/Number.js.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • diff --git a/docs/file/packages/Object/src/lib/Object.js.html b/docs/file/packages/Object/src/lib/Object.js.html index e86ee08..74a1f63 100644 --- a/docs/file/packages/Object/src/lib/Object.js.html +++ b/docs/file/packages/Object/src/lib/Object.js.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • diff --git a/docs/file/packages/PriorityQueue/src/lib/PriorityQueue.js.html b/docs/file/packages/PriorityQueue/src/lib/PriorityQueue.js.html index 0577597..1ffdee9 100644 --- a/docs/file/packages/PriorityQueue/src/lib/PriorityQueue.js.html +++ b/docs/file/packages/PriorityQueue/src/lib/PriorityQueue.js.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • diff --git a/docs/file/packages/PriorityQueue/src/lib/QueueNode.js.html b/docs/file/packages/PriorityQueue/src/lib/QueueNode.js.html index d4b49cc..a83bbee 100644 --- a/docs/file/packages/PriorityQueue/src/lib/QueueNode.js.html +++ b/docs/file/packages/PriorityQueue/src/lib/QueueNode.js.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • diff --git a/docs/file/packages/Queue/src/lib/Queue.js.html b/docs/file/packages/Queue/src/lib/Queue.js.html index 7bec47f..abdbcdc 100644 --- a/docs/file/packages/Queue/src/lib/Queue.js.html +++ b/docs/file/packages/Queue/src/lib/Queue.js.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • diff --git a/docs/file/packages/QuickSort/src/lib/QuickSort.js.html b/docs/file/packages/QuickSort/src/lib/QuickSort.js.html index 0dac6c8..8fd905c 100644 --- a/docs/file/packages/QuickSort/src/lib/QuickSort.js.html +++ b/docs/file/packages/QuickSort/src/lib/QuickSort.js.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • diff --git a/docs/file/packages/SelectionSort/src/lib/SelectionSort.js.html b/docs/file/packages/SelectionSort/src/lib/SelectionSort.js.html index 1cd2d1a..d3a991c 100644 --- a/docs/file/packages/SelectionSort/src/lib/SelectionSort.js.html +++ b/docs/file/packages/SelectionSort/src/lib/SelectionSort.js.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • diff --git a/docs/file/packages/Set/src/lib/Set.js.html b/docs/file/packages/Set/src/lib/Set.js.html index 5d16d89..06c7b56 100644 --- a/docs/file/packages/Set/src/lib/Set.js.html +++ b/docs/file/packages/Set/src/lib/Set.js.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • diff --git a/docs/file/packages/String/src/lib/String.js.html b/docs/file/packages/String/src/lib/String.js.html index 8920c72..ab90755 100644 --- a/docs/file/packages/String/src/lib/String.js.html +++ b/docs/file/packages/String/src/lib/String.js.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • diff --git a/docs/file/packages/Trie/src/lib/Trie.js.html b/docs/file/packages/Trie/src/lib/Trie.js.html index c3cfe56..d996eb6 100644 --- a/docs/file/packages/Trie/src/lib/Trie.js.html +++ b/docs/file/packages/Trie/src/lib/Trie.js.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • diff --git a/docs/file/packages/Trie/src/lib/TrieNode.js.html b/docs/file/packages/Trie/src/lib/TrieNode.js.html index ff2da7f..5d75af4 100644 --- a/docs/file/packages/Trie/src/lib/TrieNode.js.html +++ b/docs/file/packages/Trie/src/lib/TrieNode.js.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • diff --git a/docs/function/index.html b/docs/function/index.html index 98879fb..4a2b74c 100644 --- a/docs/function/index.html +++ b/docs/function/index.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • diff --git a/docs/identifiers.html b/docs/identifiers.html index 83dc191..5831bab 100644 --- a/docs/identifiers.html +++ b/docs/identifiers.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • @@ -267,6 +268,44 @@

    BubbleSort/src/lib

    + + + + + + +
    +

    Heap/src/lib

    +
    + + + + + + + @@ -1222,6 +1261,7 @@

    Trie/src/lib

    + diff --git a/docs/index.html b/docs/index.html index a890cd9..23b5891 100644 --- a/docs/index.html +++ b/docs/index.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • diff --git a/docs/index.json b/docs/index.json index f6b4bb3..9be2a86 100644 --- a/docs/index.json +++ b/docs/index.json @@ -1161,6 +1161,565 @@ { "__docId__": 48, "kind": "file", + "name": "packages/Heap/src/lib/Heap.js", + "content": "/**\n * @flow\n * @module super/heap\n */\n\nimport type { Comparator, Item } from \"../../../shared/src/types\";\nimport { _compare, swap } from \"../../../shared/src/helpers\";\n\n/**\n *\n * Heap with superpowers! 💪\n *\n * @public\n *\n */\nclass Heap {\n // static HeapType = {\n // MIN: (a: Item, b: Item): number => a - b,\n // MAX: (a: Item, b: Item): number => b - a\n // };\n\n /** @private */\n _heap: Array;\n\n /** @private */\n _compare: Comparator;\n\n /**\n * @public\n *\n * @desc Construct a Heap\n *\n * @param {Array} iterable\n * @param {Comparator} comparator\n */\n constructor(iterable: Array = [], comparator: Comparator) {\n this._heap = [...iterable];\n this._compare = _compare(comparator || Heap._defaultComparator);\n\n for (let i = Math.floor(iterable.length / 2); i >= 0; i--) {\n this._percolateDown(i);\n }\n }\n\n /**\n * @private\n *\n * @desc Get the parent item in the heap (i.e. (i-1)/2)\n *\n * @param {number} index\n * @returns {Item} _parent item\n */\n static _parent(index: number): Item {\n return Math.floor((index - 1) / 2);\n }\n\n /**\n * @private\n *\n * @desc Get the left child (i.e. 2*i+1)\n *\n * @param {number} index\n * @returns {Item} _left child\n */\n static _left(index: number): Item {\n return 2 * index + 1;\n }\n\n /**\n * @private\n *\n * @desc Get the right child (i.e. 2*i+2)\n *\n * @param {number} index\n * @returns {Item} _left child\n */\n static _right(index: number): Item {\n return 2 * index + 2;\n }\n\n /**\n * @private\n *\n * @desc Default comparator function to sort from:\n * highest priority (max) -> lowest priority (min)\n *\n * @returns {number} size of the queue\n */\n static _defaultComparator(a: any, b: any): number | boolean {\n return a - b;\n }\n\n /**\n * @public\n *\n * @desc Get the current size of the heap\n *\n * @returns {number} size of the heap\n */\n get size(): number {\n return this._heap.length;\n }\n\n /**\n * @public\n *\n * @desc Get the maximum item in heap\n *\n * @returns {Item} maximum item\n */\n get max(): Item {\n return this._heap[0];\n }\n\n /**\n * @public\n *\n * @alias max\n *\n * @desc Get the minimum item in heap\n *\n * @returns {Item} minimum item\n */\n get min(): Item {\n return this.max;\n }\n\n /**\n * @public\n *\n * @desc Check if heap is empty\n *\n * @returns {boolean} is heap empty\n */\n isEmpty(): boolean {\n return this._heap.length === 0;\n }\n\n /**\n * @public\n *\n * @desc Clear the items from the heap\n *\n * @returns {void}\n */\n clear() {\n this._heap.length = 0;\n }\n\n /**\n * @public\n *\n * @desc Insert an item into the heap\n *\n * @param {Item} value - item to insert\n * @returns {number} size after insert\n */\n insert(value: Item): number {\n this._heap.push(value);\n this._percolateUp(this.size - 1);\n return this.size;\n }\n\n /**\n * @public\n *\n * @desc Remove and return the maximum item\n *\n * @returns {Item} maximum item\n */\n deleteMax() {\n let _return = this._heap[0];\n this._heap[0] = this._heap.pop();\n this._percolateDown(0);\n return _return;\n }\n\n /**\n * @public\n *\n * @alias deleteMax\n *\n * @desc Remove and return the minimum item\n *\n * @returns {Item} minimum item\n */\n deleteMin() {\n return this.deleteMax();\n }\n\n /**\n * @private\n *\n * @desc Heapify down\n *\n * @param {number} index - start index\n */\n _percolateDown(index: number) {\n let left = Heap._left(index);\n let right = Heap._right(index);\n let root = index;\n\n if (left < this.size && this._compare(this._heap[left], this._heap[index])) {\n root = left;\n }\n\n if (right < this.size && this._compare(this._heap[right], this._heap[root])) {\n root = right;\n }\n\n if (root !== index) {\n swap(this._heap, index, root);\n this._percolateDown(root);\n }\n }\n\n /**\n * @private\n *\n * @desc Heapify up\n *\n * @param {number} index - start index\n */\n _percolateUp(index: number) {\n while (Heap._parent(index) >= 0) {\n let parent = Heap._parent(index);\n if (this._compare(this._heap[index], this._heap[parent])) {\n swap(this._heap, index, parent);\n }\n index = parent;\n }\n }\n\n /**\n * @public\n *\n * @desc Convert the heap to an array\n *\n * @returns {Array} array representation of the heap\n */\n toArray(): Array {\n return this._heap.slice(0);\n }\n}\n\nexport { Heap };\n", + "static": true, + "longname": "/Users/clarketm/js/super/packages/Heap/src/lib/Heap.js", + "access": "public", + "description": null, + "lineNumber": 1 + }, + { + "__docId__": 49, + "kind": "class", + "name": "Heap", + "memberof": "packages/Heap/src/lib/Heap.js", + "static": true, + "longname": "packages/Heap/src/lib/Heap.js~Heap", + "access": "public", + "export": true, + "importPath": "@clarketm/super/packages/Heap/src/lib/Heap.js", + "importStyle": "{Heap}", + "description": "", + "lineNumber": 16, + "unknown": [ + { + "tagName": "@module", + "tagValue": "super/heap" + } + ], + "interface": false + }, + { + "__docId__": 50, + "kind": "constructor", + "name": "constructor", + "memberof": "packages/Heap/src/lib/Heap.js~Heap", + "generator": false, + "async": false, + "static": false, + "longname": "packages/Heap/src/lib/Heap.js~Heap#constructor", + "access": "private", + "description": null, + "lineNumber": 33 + }, + { + "__docId__": 51, + "kind": "member", + "name": "_heap", + "memberof": "packages/Heap/src/lib/Heap.js~Heap", + "static": false, + "longname": "packages/Heap/src/lib/Heap.js~Heap#_heap", + "access": "private", + "description": null, + "lineNumber": 34, + "undocument": true, + "type": { + "types": [ + "undefined[]" + ] + } + }, + { + "__docId__": 52, + "kind": "member", + "name": "_compare", + "memberof": "packages/Heap/src/lib/Heap.js~Heap", + "static": false, + "longname": "packages/Heap/src/lib/Heap.js~Heap#_compare", + "access": "private", + "description": null, + "lineNumber": 35, + "undocument": true, + "type": { + "types": [ + "*" + ] + } + }, + { + "__docId__": 53, + "kind": "method", + "name": "_parent", + "memberof": "packages/Heap/src/lib/Heap.js~Heap", + "generator": false, + "async": false, + "static": true, + "longname": "packages/Heap/src/lib/Heap.js~Heap._parent", + "access": "private", + "description": null, + "lineNumber": 53, + "params": [ + { + "name": "index", + "types": [ + "*" + ] + } + ], + "return": { + "types": [ + "*" + ] + } + }, + { + "__docId__": 54, + "kind": "method", + "name": "_left", + "memberof": "packages/Heap/src/lib/Heap.js~Heap", + "generator": false, + "async": false, + "static": true, + "longname": "packages/Heap/src/lib/Heap.js~Heap._left", + "access": "private", + "description": "Get the left child (i.e. 2*i+1)", + "lineNumber": 65, + "unknown": [ + { + "tagName": "@returns", + "tagValue": "{Item} _left child" + } + ], + "params": [ + { + "nullable": null, + "types": [ + "number" + ], + "spread": false, + "optional": false, + "name": "index", + "description": "" + } + ], + "return": { + "nullable": null, + "types": [ + "Item" + ], + "spread": false, + "description": "_left child" + } + }, + { + "__docId__": 55, + "kind": "method", + "name": "_right", + "memberof": "packages/Heap/src/lib/Heap.js~Heap", + "generator": false, + "async": false, + "static": true, + "longname": "packages/Heap/src/lib/Heap.js~Heap._right", + "access": "private", + "description": "Get the right child (i.e. 2*i+2)", + "lineNumber": 77, + "unknown": [ + { + "tagName": "@returns", + "tagValue": "{Item} _left child" + } + ], + "params": [ + { + "nullable": null, + "types": [ + "number" + ], + "spread": false, + "optional": false, + "name": "index", + "description": "" + } + ], + "return": { + "nullable": null, + "types": [ + "Item" + ], + "spread": false, + "description": "_left child" + } + }, + { + "__docId__": 56, + "kind": "method", + "name": "_defaultComparator", + "memberof": "packages/Heap/src/lib/Heap.js~Heap", + "generator": false, + "async": false, + "static": true, + "longname": "packages/Heap/src/lib/Heap.js~Heap._defaultComparator", + "access": "private", + "description": "Default comparator function to sort from:\n highest priority (max) -> lowest priority (min)", + "lineNumber": 89, + "unknown": [ + { + "tagName": "@returns", + "tagValue": "{number} size of the queue" + } + ], + "return": { + "nullable": null, + "types": [ + "number" + ], + "spread": false, + "description": "size of the queue" + }, + "params": [ + { + "name": "a", + "types": [ + "*" + ] + }, + { + "name": "b", + "types": [ + "*" + ] + } + ] + }, + { + "__docId__": 57, + "kind": "get", + "name": "size", + "memberof": "packages/Heap/src/lib/Heap.js~Heap", + "generator": false, + "async": false, + "static": false, + "longname": "packages/Heap/src/lib/Heap.js~Heap#size", + "access": "public", + "description": "Get the current size of the heap", + "lineNumber": 100, + "unknown": [ + { + "tagName": "@returns", + "tagValue": "{number} size of the heap" + } + ], + "return": { + "nullable": null, + "types": [ + "number" + ], + "spread": false, + "description": "size of the heap" + }, + "type": { + "types": [ + "*" + ] + } + }, + { + "__docId__": 58, + "kind": "get", + "name": "max", + "memberof": "packages/Heap/src/lib/Heap.js~Heap", + "generator": false, + "async": false, + "static": false, + "longname": "packages/Heap/src/lib/Heap.js~Heap#max", + "access": "public", + "description": "Get the maximum item in heap", + "lineNumber": 111, + "unknown": [ + { + "tagName": "@returns", + "tagValue": "{Item} maximum item" + } + ], + "return": { + "nullable": null, + "types": [ + "Item" + ], + "spread": false, + "description": "maximum item" + }, + "type": { + "types": [ + "*" + ] + } + }, + { + "__docId__": 59, + "kind": "get", + "name": "min", + "memberof": "packages/Heap/src/lib/Heap.js~Heap", + "generator": false, + "async": false, + "static": false, + "longname": "packages/Heap/src/lib/Heap.js~Heap#min", + "access": "public", + "description": "Get the minimum item in heap", + "lineNumber": 124, + "unknown": [ + { + "tagName": "@alias", + "tagValue": "max" + }, + { + "tagName": "@returns", + "tagValue": "{Item} minimum item" + } + ], + "return": { + "nullable": null, + "types": [ + "Item" + ], + "spread": false, + "description": "minimum item" + }, + "type": { + "types": [ + "*" + ] + } + }, + { + "__docId__": 60, + "kind": "method", + "name": "isEmpty", + "memberof": "packages/Heap/src/lib/Heap.js~Heap", + "generator": false, + "async": false, + "static": false, + "longname": "packages/Heap/src/lib/Heap.js~Heap#isEmpty", + "access": "public", + "description": "Check if heap is empty", + "lineNumber": 135, + "unknown": [ + { + "tagName": "@returns", + "tagValue": "{boolean} is heap empty" + } + ], + "return": { + "nullable": null, + "types": [ + "boolean" + ], + "spread": false, + "description": "is heap empty" + }, + "params": [] + }, + { + "__docId__": 61, + "kind": "method", + "name": "clear", + "memberof": "packages/Heap/src/lib/Heap.js~Heap", + "generator": false, + "async": false, + "static": false, + "longname": "packages/Heap/src/lib/Heap.js~Heap#clear", + "access": "public", + "description": "Clear the items from the heap", + "lineNumber": 146, + "unknown": [ + { + "tagName": "@returns", + "tagValue": "{void}" + } + ], + "return": { + "nullable": null, + "types": [ + "void" + ], + "spread": false, + "description": "" + }, + "params": [] + }, + { + "__docId__": 62, + "kind": "method", + "name": "insert", + "memberof": "packages/Heap/src/lib/Heap.js~Heap", + "generator": false, + "async": false, + "static": false, + "longname": "packages/Heap/src/lib/Heap.js~Heap#insert", + "access": "public", + "description": "Insert an item into the heap", + "lineNumber": 158, + "unknown": [ + { + "tagName": "@returns", + "tagValue": "{number} size after insert" + } + ], + "params": [ + { + "nullable": null, + "types": [ + "Item" + ], + "spread": false, + "optional": false, + "name": "value", + "description": "item to insert" + } + ], + "return": { + "nullable": null, + "types": [ + "number" + ], + "spread": false, + "description": "size after insert" + } + }, + { + "__docId__": 63, + "kind": "method", + "name": "deleteMax", + "memberof": "packages/Heap/src/lib/Heap.js~Heap", + "generator": false, + "async": false, + "static": false, + "longname": "packages/Heap/src/lib/Heap.js~Heap#deleteMax", + "access": "public", + "description": "Remove and return the maximum item", + "lineNumber": 171, + "unknown": [ + { + "tagName": "@returns", + "tagValue": "{Item} maximum item" + } + ], + "return": { + "nullable": null, + "types": [ + "Item" + ], + "spread": false, + "description": "maximum item" + }, + "params": [] + }, + { + "__docId__": 64, + "kind": "method", + "name": "deleteMin", + "memberof": "packages/Heap/src/lib/Heap.js~Heap", + "generator": false, + "async": false, + "static": false, + "longname": "packages/Heap/src/lib/Heap.js~Heap#deleteMin", + "access": "public", + "description": "Remove and return the minimum item", + "lineNumber": 187, + "unknown": [ + { + "tagName": "@alias", + "tagValue": "deleteMax" + }, + { + "tagName": "@returns", + "tagValue": "{Item} minimum item" + } + ], + "return": { + "nullable": null, + "types": [ + "Item" + ], + "spread": false, + "description": "minimum item" + }, + "params": [] + }, + { + "__docId__": 65, + "kind": "method", + "name": "_percolateDown", + "memberof": "packages/Heap/src/lib/Heap.js~Heap", + "generator": false, + "async": false, + "static": false, + "longname": "packages/Heap/src/lib/Heap.js~Heap#_percolateDown", + "access": "private", + "description": "Heapify down", + "lineNumber": 198, + "params": [ + { + "nullable": null, + "types": [ + "number" + ], + "spread": false, + "optional": false, + "name": "index", + "description": "start index" + } + ], + "return": null + }, + { + "__docId__": 66, + "kind": "method", + "name": "_percolateUp", + "memberof": "packages/Heap/src/lib/Heap.js~Heap", + "generator": false, + "async": false, + "static": false, + "longname": "packages/Heap/src/lib/Heap.js~Heap#_percolateUp", + "access": "private", + "description": "Heapify up", + "lineNumber": 224, + "params": [ + { + "nullable": null, + "types": [ + "number" + ], + "spread": false, + "optional": false, + "name": "index", + "description": "start index" + } + ], + "return": null + }, + { + "__docId__": 67, + "kind": "method", + "name": "toArray", + "memberof": "packages/Heap/src/lib/Heap.js~Heap", + "generator": false, + "async": false, + "static": false, + "longname": "packages/Heap/src/lib/Heap.js~Heap#toArray", + "access": "public", + "description": "Convert the heap to an array", + "lineNumber": 241, + "unknown": [ + { + "tagName": "@returns", + "tagValue": "{Array} array representation of the heap" + } + ], + "return": { + "nullable": null, + "types": [ + "Array" + ], + "spread": false, + "description": "array representation of the heap" + }, + "params": [] + }, + { + "__docId__": 68, + "kind": "file", "name": "packages/InsertionSort/src/lib/InsertionSort.js", "content": "/**\n * @flow\n * @module super/insertionsort\n */\n\nimport type { Comparator, Item } from \"../../../shared/src/types\";\nimport { _compare, _defaultComparator, swap } from \"../../../shared/src/helpers\";\n\n/**\n *\n * InsertionSort with superpowers! 💪\n *\n * time: O(n^2)\n * space: O(1)\n *\n * @public\n *\n * @param {Array} arr - array to sort\n * @param {Comparator} comparator\n * @returns {Array} sorted array\n */\nfunction insertionSort(arr: Array, comparator: Comparator = _defaultComparator) {\n if (!(this instanceof Array) && !(arr instanceof Array)) {\n throw new Error(\"Array type is required\");\n }\n\n let target = this instanceof Array ? this : arr.slice(0);\n let compare = _compare(comparator);\n\n /**\n *\n * InsertionSort helper\n *\n * @private\n *\n * @param {Array} arr - array target\n * @returns {Array} sorted array\n */\n function _insertionSort(arr: Array): Array {\n for (let i = 0; i < arr.length - 1; i++) {\n for (let j = i; j >= 0 && compare(arr[j + 1], arr[j]); j--) {\n swap(arr, j, j + 1);\n }\n }\n\n return arr;\n }\n\n return _insertionSort(target);\n}\n\nexport { insertionSort };\n", "static": true, @@ -1170,7 +1729,7 @@ "lineNumber": 1 }, { - "__docId__": 49, + "__docId__": 69, "kind": "function", "name": "insertionSort", "memberof": "packages/InsertionSort/src/lib/InsertionSort.js", @@ -1214,7 +1773,7 @@ } }, { - "__docId__": 50, + "__docId__": 70, "kind": "file", "name": "packages/LinkedList/src/lib/LinkedList.js", "content": "/**\n * @flow\n * @module super/linkedlist\n */\n\nimport { ListNode } from \"./ListNode\";\nimport type { Item } from \"../../../shared/src/types\";\n\n/**\n *\n * LinkedList with superpowers! 💪\n *\n * @public\n *\n */\nclass LinkedList {\n /** @private */\n _size: number;\n\n /** @private */\n _head: ?ListNode;\n\n /** @private */\n _tail: ?ListNode;\n\n /**\n * @public\n *\n * @desc Construct a LinkedList\n *\n * @param {Array} iterable\n */\n constructor(iterable: Array = []) {\n let head = new ListNode(0);\n let prev = null;\n let curr = head;\n let size = 0;\n\n for (let item: Item of iterable) {\n curr.next = new ListNode(item);\n curr = curr.next;\n\n curr.prev = prev;\n prev = curr;\n\n size++;\n }\n\n this._size = size;\n this._head = head.next;\n this._tail = curr;\n }\n\n /**\n * @public\n *\n * @desc Get the head of the list\n *\n * @returns {ListNode} head node\n */\n get head(): ?ListNode {\n return this._head;\n }\n\n /**\n * @public\n *\n * @desc Get the tail of the list\n *\n * @returns {ListNode} tail node\n */\n get tail(): ?ListNode {\n return this._tail;\n }\n\n /**\n * @public\n *\n * @desc Get the size of the list\n *\n * @returns {number} number of nodes in the list\n */\n get size(): number {\n return this._size;\n }\n\n /**\n * @public\n *\n * @desc Insert a node at a given position\n *\n * @param {number} position - position to insert node\n * @param {Item} value - value to insert into list\n * @returns {number} size after insertion\n */\n // TODO: insert by value\n insert(position: number, value: Item): number {\n if (position < 0) {\n return this.insert(Math.max(0, this.size + 1 - Math.abs(position)), value);\n }\n\n let prev = null;\n let curr = this.head;\n\n let p = 0;\n while (p < position && curr) {\n prev = curr;\n curr = curr.next;\n p++;\n }\n\n let node = new ListNode(value);\n node.prev = prev;\n node.next = curr;\n\n if (prev) prev.next = node;\n else this._head = node;\n\n if (curr) curr.prev = node;\n else this._tail = node;\n\n this._size++;\n\n return this._size;\n }\n\n /**\n * @public\n *\n * @alias insert(0, value)\n *\n * @desc Prepend a node to the front of the list\n *\n * @param {Item} value - value to prepend to list\n * @returns {number} size after insertion\n */\n prepend(value: Item): number {\n return this.insert(0, value);\n }\n\n /**\n * @public\n *\n * @alias insert(0, value)\n *\n * @desc Unshift a node to the front of the list\n *\n * @param {Item} value - value to unshift to list\n * @returns {number} size after insertion\n */\n unshift(value: Item): number {\n return this.prepend(value);\n }\n\n /**\n * @public\n *\n * @alias insert(list.size, value)\n *\n * @desc Append a node to the rear of the list\n *\n * @param {Item} value - value to append to list\n * @returns {number} size after insertion\n */\n append(value: Item): number {\n return this.insert(this.size, value);\n }\n\n /**\n * @public\n *\n * @alias insert(list.size, value)\n *\n * @desc Push a node to the rear of the list\n *\n * @param {Item} value - value to push to list\n * @returns {number} size after insertion\n */\n push(value: Item): number {\n return this.append(value);\n }\n\n /**\n * @public\n *\n * @desc Remove a node at a given position\n *\n * @param {number} position - position to remove node\n * @returns {Item} removed item\n */\n // TODO: remove by value\n remove(position: number): Item {\n if (position < 0) {\n return this.remove(Math.max(0, this.size - Math.abs(position)));\n }\n\n let prev = null;\n let curr = this.head;\n\n let p = 0;\n while (p < position && curr) {\n prev = curr;\n curr = curr.next;\n p++;\n }\n\n if (prev && curr && curr.next) {\n prev.next = curr.next;\n // $FlowFixMe\n curr.next.prev = prev;\n this._size--;\n } else if (prev && curr) {\n prev.next = null;\n this._tail = prev;\n this._size--;\n } else if (curr && curr.next) {\n curr.next.prev = null;\n this._head = curr.next;\n this._size--;\n }\n\n return curr;\n }\n\n /**\n * @public\n *\n * @alias remove(0)\n *\n * @desc Shift a node from the front of list\n *\n * @returns {Item} shifted item\n */\n shift(): Item {\n return this.remove(0);\n }\n\n /**\n * @public\n *\n * @alias remove(list.size - 1)\n *\n * @desc Pop a node from the rear of list\n *\n * @returns {Item} shifted item\n */\n pop(): Item {\n return this.remove(this.size - 1);\n }\n\n // TODO:\n // searchNodeAt (position: number)\n\n /**\n * @public\n *\n * @desc Convert the node and next nodes (recursively) to an array\n *\n * @returns {Array} array representation of the list\n */\n toArray(): Array {\n let array = [];\n let node = this.head;\n\n while (node) {\n array.push(node.value);\n node = node.next;\n }\n\n return array;\n }\n}\n\nexport { LinkedList };\n", @@ -1225,7 +1784,7 @@ "lineNumber": 1 }, { - "__docId__": 51, + "__docId__": 71, "kind": "class", "name": "LinkedList", "memberof": "packages/LinkedList/src/lib/LinkedList.js", @@ -1240,7 +1799,7 @@ "interface": false }, { - "__docId__": 52, + "__docId__": 72, "kind": "constructor", "name": "constructor", "memberof": "packages/LinkedList/src/lib/LinkedList.js~LinkedList", @@ -1253,7 +1812,7 @@ "lineNumber": 28 }, { - "__docId__": 53, + "__docId__": 73, "kind": "member", "name": "_size", "memberof": "packages/LinkedList/src/lib/LinkedList.js~LinkedList", @@ -1270,7 +1829,7 @@ } }, { - "__docId__": 54, + "__docId__": 74, "kind": "member", "name": "_head", "memberof": "packages/LinkedList/src/lib/LinkedList.js~LinkedList", @@ -1287,7 +1846,7 @@ } }, { - "__docId__": 55, + "__docId__": 75, "kind": "member", "name": "_tail", "memberof": "packages/LinkedList/src/lib/LinkedList.js~LinkedList", @@ -1304,7 +1863,7 @@ } }, { - "__docId__": 56, + "__docId__": 76, "kind": "get", "name": "head", "memberof": "packages/LinkedList/src/lib/LinkedList.js~LinkedList", @@ -1322,7 +1881,7 @@ } }, { - "__docId__": 57, + "__docId__": 77, "kind": "get", "name": "tail", "memberof": "packages/LinkedList/src/lib/LinkedList.js~LinkedList", @@ -1354,7 +1913,7 @@ } }, { - "__docId__": 58, + "__docId__": 78, "kind": "get", "name": "size", "memberof": "packages/LinkedList/src/lib/LinkedList.js~LinkedList", @@ -1386,7 +1945,7 @@ } }, { - "__docId__": 59, + "__docId__": 79, "kind": "method", "name": "insert", "memberof": "packages/LinkedList/src/lib/LinkedList.js~LinkedList", @@ -1435,7 +1994,7 @@ } }, { - "__docId__": 62, + "__docId__": 82, "kind": "method", "name": "prepend", "memberof": "packages/LinkedList/src/lib/LinkedList.js~LinkedList", @@ -1478,7 +2037,7 @@ } }, { - "__docId__": 63, + "__docId__": 83, "kind": "method", "name": "unshift", "memberof": "packages/LinkedList/src/lib/LinkedList.js~LinkedList", @@ -1521,7 +2080,7 @@ } }, { - "__docId__": 64, + "__docId__": 84, "kind": "method", "name": "append", "memberof": "packages/LinkedList/src/lib/LinkedList.js~LinkedList", @@ -1564,7 +2123,7 @@ } }, { - "__docId__": 65, + "__docId__": 85, "kind": "method", "name": "push", "memberof": "packages/LinkedList/src/lib/LinkedList.js~LinkedList", @@ -1607,7 +2166,7 @@ } }, { - "__docId__": 66, + "__docId__": 86, "kind": "method", "name": "remove", "memberof": "packages/LinkedList/src/lib/LinkedList.js~LinkedList", @@ -1646,7 +2205,7 @@ } }, { - "__docId__": 69, + "__docId__": 89, "kind": "method", "name": "shift", "memberof": "packages/LinkedList/src/lib/LinkedList.js~LinkedList", @@ -1678,7 +2237,7 @@ "params": [] }, { - "__docId__": 70, + "__docId__": 90, "kind": "method", "name": "pop", "memberof": "packages/LinkedList/src/lib/LinkedList.js~LinkedList", @@ -1710,7 +2269,7 @@ "params": [] }, { - "__docId__": 71, + "__docId__": 91, "kind": "method", "name": "toArray", "memberof": "packages/LinkedList/src/lib/LinkedList.js~LinkedList", @@ -1738,7 +2297,7 @@ "params": [] }, { - "__docId__": 72, + "__docId__": 92, "kind": "file", "name": "packages/LinkedList/src/lib/ListNode.js", "content": "/**\n * @flow\n * @module super/linkedlist\n */\n\nimport type { Item } from \"../../../shared/src/types\";\n\n/**\n *\n * ListNode\n *\n * @public\n *\n */\nclass ListNode {\n /** @private */\n _value: Item;\n\n /** @private */\n _next: ?ListNode;\n\n /** @private */\n _prev: ?ListNode;\n\n /**\n * @public\n *\n * @desc Construct a ListNode\n *\n * @param {Item} item - node value\n */\n constructor(item: Item) {\n this._value = item;\n }\n\n /**\n * @public\n *\n * @desc Get the value of the node\n *\n * @returns {Item} node value\n */\n get value(): Item {\n return this._value;\n }\n\n /**\n * @public\n *\n * @desc Set the value of the node\n *\n */\n set value(value: Item) {\n this._value = value;\n }\n\n /**\n * @public\n *\n * @desc Get the next node in list\n *\n * @returns {ListNode} next node\n */\n get next(): ?ListNode {\n return this._next;\n }\n\n /**\n * @public\n *\n * @desc Set the next node in list\n *\n */\n set next(next: ?ListNode) {\n this._next = next;\n }\n\n /**\n * @public\n *\n * @desc Get the previous node in list\n *\n * @returns {ListNode} previous node\n */\n get prev(): ?ListNode {\n return this._prev;\n }\n\n /**\n * @public\n *\n * @desc Set the next node in list\n *\n */\n set prev(prev: ?ListNode) {\n this._prev = prev;\n }\n}\n\nexport { ListNode };\n", @@ -1749,7 +2308,7 @@ "lineNumber": 1 }, { - "__docId__": 73, + "__docId__": 93, "kind": "class", "name": "ListNode", "memberof": "packages/LinkedList/src/lib/ListNode.js", @@ -1764,7 +2323,7 @@ "interface": false }, { - "__docId__": 74, + "__docId__": 94, "kind": "constructor", "name": "constructor", "memberof": "packages/LinkedList/src/lib/ListNode.js~ListNode", @@ -1777,7 +2336,7 @@ "lineNumber": 22 }, { - "__docId__": 75, + "__docId__": 95, "kind": "member", "name": "_value", "memberof": "packages/LinkedList/src/lib/ListNode.js~ListNode", @@ -1794,7 +2353,7 @@ } }, { - "__docId__": 76, + "__docId__": 96, "kind": "get", "name": "value", "memberof": "packages/LinkedList/src/lib/ListNode.js~ListNode", @@ -1812,7 +2371,7 @@ } }, { - "__docId__": 77, + "__docId__": 97, "kind": "set", "name": "value", "memberof": "packages/LinkedList/src/lib/ListNode.js~ListNode", @@ -1825,7 +2384,7 @@ "lineNumber": 48 }, { - "__docId__": 79, + "__docId__": 99, "kind": "get", "name": "next", "memberof": "packages/LinkedList/src/lib/ListNode.js~ListNode", @@ -1857,7 +2416,7 @@ } }, { - "__docId__": 80, + "__docId__": 100, "kind": "set", "name": "next", "memberof": "packages/LinkedList/src/lib/ListNode.js~ListNode", @@ -1870,7 +2429,7 @@ "lineNumber": 69 }, { - "__docId__": 81, + "__docId__": 101, "kind": "member", "name": "_next", "memberof": "packages/LinkedList/src/lib/ListNode.js~ListNode", @@ -1887,7 +2446,7 @@ } }, { - "__docId__": 82, + "__docId__": 102, "kind": "get", "name": "prev", "memberof": "packages/LinkedList/src/lib/ListNode.js~ListNode", @@ -1919,7 +2478,7 @@ } }, { - "__docId__": 83, + "__docId__": 103, "kind": "set", "name": "prev", "memberof": "packages/LinkedList/src/lib/ListNode.js~ListNode", @@ -1932,7 +2491,7 @@ "lineNumber": 90 }, { - "__docId__": 84, + "__docId__": 104, "kind": "member", "name": "_prev", "memberof": "packages/LinkedList/src/lib/ListNode.js~ListNode", @@ -1949,7 +2508,7 @@ } }, { - "__docId__": 85, + "__docId__": 105, "kind": "file", "name": "packages/Map/src/lib/Map.js", "content": "/**\n * @flow\n * @module super/map\n */\n\nimport type { Item } from \"../../../shared/src/types\";\nimport { PrimitiveType } from \"../../../shared/src/constants\";\n\n/**\n * @typedef {Function} Callback\n */\ntype Callback = (value: any, key: any, map: Map) => boolean;\n\n/**\n *\n * Map with superpowers! 💪\n *\n * @public\n *\n */\nclass _Map extends Map {\n /**\n * @public\n *\n * @desc Construct a Map\n *\n * @param {Array} iterable\n */\n constructor(iterable: Array) {\n super(iterable);\n }\n /**\n * @public\n *\n * @desc Tests whether at least one element in the map passes the test implemented by the provided function\n *\n * @param {Callback} callback - callback function\n * @returns {boolean} true if the callback function returns a truthy value for any map element; otherwise, false\n */\n some(callback: (value: any, key: any, map: Map) => boolean): boolean {\n let result;\n\n for (let [key, value] of this.entries()) {\n result = callback(value, key, this);\n if (result) return true;\n }\n return false;\n }\n /**\n * @public\n *\n * @desc Test whether all elements in the map pass the test implemented by the provided function\n *\n * @param {Callback} callback - callback function\n * @returns {boolean} true if the callback function returns a truthy value for every map element; otherwise, false\n */\n every(callback: (value: any, key: any, map: Map) => boolean): boolean {\n let result;\n\n for (let [key, value] of this.entries()) {\n result = callback(value, key, this);\n if (!result) return false;\n }\n return true;\n }\n /**\n * @public\n *\n * @desc Similar to get(), but will set key to defaultValue if key is not already in Map.\n *\n * @param {Item} key - Map key\n * @param {Item} defaultValue - the default value to set in Map if the key is not defined\n * @returns {Item} The value if the key is defined in Map; otherwise, the default value\n */\n setDefault(key: Item, defaultValue: Item): Item {\n if (this.has(key)) {\n return this.get(key);\n } else {\n this.set(key, defaultValue);\n return defaultValue;\n }\n }\n /**\n * @public\n *\n * @desc Convert Map to an Object\n *\n * @returns {object} Object representation of Map\n */\n toObject() {\n return Array.from(this).reduce((obj, [key, value]) => {\n if (typeof key !== PrimitiveType.OBJECT) {\n obj[key] = value;\n }\n return obj;\n }, {});\n }\n}\nexport { _Map as Map };\n", @@ -1960,7 +2519,7 @@ "lineNumber": 1 }, { - "__docId__": 86, + "__docId__": 106, "kind": "typedef", "name": "Callback", "memberof": "packages/Map/src/lib/Map.js", @@ -1977,7 +2536,7 @@ } }, { - "__docId__": 87, + "__docId__": 107, "kind": "class", "name": "_Map", "memberof": "packages/Map/src/lib/Map.js", @@ -1995,7 +2554,7 @@ ] }, { - "__docId__": 88, + "__docId__": 108, "kind": "constructor", "name": "constructor", "memberof": "packages/Map/src/lib/Map.js~_Map", @@ -2020,7 +2579,7 @@ ] }, { - "__docId__": 89, + "__docId__": 109, "kind": "method", "name": "some", "memberof": "packages/Map/src/lib/Map.js~_Map", @@ -2059,7 +2618,7 @@ } }, { - "__docId__": 90, + "__docId__": 110, "kind": "method", "name": "every", "memberof": "packages/Map/src/lib/Map.js~_Map", @@ -2098,7 +2657,7 @@ } }, { - "__docId__": 91, + "__docId__": 111, "kind": "method", "name": "setDefault", "memberof": "packages/Map/src/lib/Map.js~_Map", @@ -2147,7 +2706,7 @@ } }, { - "__docId__": 92, + "__docId__": 112, "kind": "method", "name": "toObject", "memberof": "packages/Map/src/lib/Map.js~_Map", @@ -2175,7 +2734,7 @@ "params": [] }, { - "__docId__": 93, + "__docId__": 113, "kind": "file", "name": "packages/Math/src/lib/Math.js", "content": "/**\n * @flow\n * @module super/math\n */\n\n/**\n *\n * Math with superpowers! 💪\n *\n * @public\n *\n * @alias Math\n */\nexport const _Math = Object.create(Math);\n\n/**\n * @public\n *\n * @desc Factorial\n *\n * @param {number} num - integral number\n * @returns {number} factorial of num\n */\n_Math.factorial = function(num: number): number {\n if (num < 0) throw new Error(\"Factorial not defined for negative values\");\n if (num === 0) return 1;\n return num * _Math.factorial(num - 1);\n};\n\nexport { _Math as Math };\n", @@ -2186,7 +2745,7 @@ "lineNumber": 1 }, { - "__docId__": 94, + "__docId__": 114, "kind": "variable", "name": "_Math", "memberof": "packages/Math/src/lib/Math.js", @@ -2211,7 +2770,7 @@ } }, { - "__docId__": 95, + "__docId__": 115, "kind": "function", "name": "factorial", "memberof": "packages/Math/src/lib/Math.js", @@ -2253,7 +2812,7 @@ } }, { - "__docId__": 96, + "__docId__": 116, "kind": "file", "name": "packages/MergeSort/src/lib/MergeSort.js", "content": "/**\n * @flow\n * @module super/mergesort\n */\n\nimport type { Comparator, Item } from \"../../../shared/src/types\";\nimport { _compare, _defaultComparator } from \"../../../shared/src/helpers\";\n\n/**\n *\n * MergeSort with superpowers! 💪\n *\n * time: O(nlogn)\n * space: O(n)\n *\n * @public\n *\n * @param {Array} arr - array to sort\n * @param {Comparator} comparator\n * @returns {Array} sorted array\n */\nfunction mergeSort(arr: Array, comparator: Comparator = _defaultComparator) {\n if (!(this instanceof Array) && !(arr instanceof Array)) {\n throw new Error(\"Array type is required\");\n }\n\n let target = this instanceof Array ? this : arr.slice(0);\n let compare = _compare(comparator);\n\n /**\n *\n * MergeSort helper\n *\n * @private\n *\n * @param {Array} arr - array target\n * @returns {Array} merged array\n */\n function _mergeSort(arr: Array) {\n if (arr.length <= 1) return arr;\n\n let mid = Math.trunc(arr.length / 2);\n let leftArr = arr.slice(0, mid);\n let rightArr = arr.slice(mid);\n\n _mergeSort(leftArr);\n _mergeSort(rightArr);\n\n return merge(arr, leftArr, rightArr, compare);\n }\n\n return _mergeSort(target);\n}\n\n/**\n *\n * Merge helper\n *\n * @private\n *\n * @param {Array} arr - array merge target\n * @param {Array} leftArr - left array to merge\n * @param {Array} rightArr - right array to merge\n * @param {Comparator} compare\n * @returns {Array} merged array\n */\nfunction merge(\n arr: Array,\n leftArr: Array,\n rightArr: Array,\n compare: Comparator\n): Array {\n let i: number = 0;\n let j: number = 0;\n let k: number = 0;\n\n while (i < leftArr.length && j < rightArr.length) {\n if (compare(leftArr[i], rightArr[j])) {\n arr[k] = leftArr[i];\n i++;\n } else {\n arr[k] = rightArr[j];\n j++;\n }\n k++;\n }\n\n while (i < leftArr.length) {\n arr[k] = leftArr[i];\n i++;\n k++;\n }\n\n while (j < rightArr.length) {\n arr[k] = rightArr[j];\n j++;\n k++;\n }\n\n return arr;\n}\n\nexport { mergeSort };\n", @@ -2264,7 +2823,7 @@ "lineNumber": 1 }, { - "__docId__": 97, + "__docId__": 117, "kind": "function", "name": "merge", "memberof": "packages/MergeSort/src/lib/MergeSort.js", @@ -2336,7 +2895,7 @@ } }, { - "__docId__": 98, + "__docId__": 118, "kind": "function", "name": "mergeSort", "memberof": "packages/MergeSort/src/lib/MergeSort.js", @@ -2380,7 +2939,7 @@ } }, { - "__docId__": 99, + "__docId__": 119, "kind": "file", "name": "packages/Number/src/lib/Number.js", "content": "/**\n * @flow\n * @module super/number\n */\n\nconst RomanNumeralToIntegerMap = new Map([\n [\"M\", 1000],\n [\"CM\", 900],\n [\"D\", 500],\n [\"CD\", 400],\n [\"C\", 100],\n [\"XC\", 90],\n [\"L\", 50],\n [\"XL\", 40],\n [\"X\", 10],\n [\"IX\", 9],\n [\"V\", 5],\n [\"IV\", 4],\n [\"I\", 1]\n]);\n\nconst IntegerToRomanNumeralMap = new Map([\n [1000, \"M\"],\n [900, \"CM\"],\n [500, \"D\"],\n [400, \"CD\"],\n [100, \"C\"],\n [90, \"XC\"],\n [50, \"L\"],\n [40, \"XL\"],\n [10, \"X\"],\n [9, \"IX\"],\n [5, \"V\"],\n [4, \"IV\"],\n [1, \"I\"]\n]);\n\n/**\n *\n * Number with superpowers! 💪\n *\n * @public\n *\n */\nclass _Number extends Number {\n /**\n * @public\n *\n * @desc Construct a Number\n *\n * @param {number} number\n */\n constructor(number: number) {\n super(number);\n }\n /**\n * @public\n *\n * @desc Convert a roman numeral to number\n *\n * @param {string} str - Roman numeral\n * @returns {number} Number representation of a roman numeral\n */\n static fromRomanNumeral(str: string): number {\n function _romanToInteger(num: string, result: number = 0) {\n // TODO: reduce iterations\n for (let [roman, int] of RomanNumeralToIntegerMap) {\n if (num.slice(0, roman.length) === roman) {\n return _romanToInteger(num.slice(roman.length), result + int);\n }\n }\n return result;\n }\n return _romanToInteger(str);\n }\n /**\n * @public\n *\n * @desc Convert a number to roman numeral\n *\n * @returns {string} Roman numeral representation of number\n */\n toRomanNumeral(): string {\n function _integerToRoman(num: number, result: string = \"\") {\n // TODO: reduce iterations\n for (let [int, roman] of IntegerToRomanNumeralMap) {\n if (num >= int) return _integerToRoman(num - int, result + roman);\n }\n return result;\n }\n // $FlowFixMe\n return _integerToRoman(this);\n }\n}\nexport { _Number as Number };\n", @@ -2391,7 +2950,7 @@ "lineNumber": 1 }, { - "__docId__": 100, + "__docId__": 120, "kind": "variable", "name": "RomanNumeralToIntegerMap", "memberof": "packages/Number/src/lib/Number.js", @@ -2416,7 +2975,7 @@ } }, { - "__docId__": 101, + "__docId__": 121, "kind": "variable", "name": "IntegerToRomanNumeralMap", "memberof": "packages/Number/src/lib/Number.js", @@ -2436,7 +2995,7 @@ } }, { - "__docId__": 102, + "__docId__": 122, "kind": "class", "name": "_Number", "memberof": "packages/Number/src/lib/Number.js", @@ -2454,7 +3013,7 @@ ] }, { - "__docId__": 103, + "__docId__": 123, "kind": "constructor", "name": "constructor", "memberof": "packages/Number/src/lib/Number.js~_Number", @@ -2479,7 +3038,7 @@ ] }, { - "__docId__": 104, + "__docId__": 124, "kind": "method", "name": "fromRomanNumeral", "memberof": "packages/Number/src/lib/Number.js~_Number", @@ -2518,7 +3077,7 @@ } }, { - "__docId__": 105, + "__docId__": 125, "kind": "method", "name": "toRomanNumeral", "memberof": "packages/Number/src/lib/Number.js~_Number", @@ -2546,7 +3105,7 @@ "params": [] }, { - "__docId__": 106, + "__docId__": 126, "kind": "file", "name": "packages/Object/src/lib/Object.js", "content": "/**\n * @flow\n * @module super/object\n */\n\nimport { InstanceType, PrimitiveType } from \"../../../shared/src/constants\";\nimport type { Item } from \"../../../shared/src/types\";\n\n/**\n * @typedef {object} Config\n * @property {boolean} [includeNonEnumerable=false]\n */\n\ntype Config = {\n includeNonEnumerable: ?boolean\n};\n\n/**\n *\n * Object with superpowers! 💪\n *\n * @public\n *\n */\nclass _Object extends Object {\n /**\n * @public\n *\n * @desc Construct an Object\n *\n * @param {Object} object\n */\n constructor(object: Object) {\n // $FlowFixMe\n super(object);\n }\n\n /**\n * @public\n *\n * @desc Check for nested value from string key\n *\n * @param {string} path\n * @return {boolean} property value exists\n */\n hasNested(path: string): boolean {\n let item = this;\n // TODO: throw error on invalid path\n path = path.replace(/\\[(\\w+)\\]/, \".$1\").replace(/^\\./, \"\");\n\n const keys = path.split(\".\");\n for (let key of keys) {\n if (typeof item === PrimitiveType.OBJECT && key in item) item = item[key];\n else return false;\n }\n return true;\n }\n\n /**\n * @public\n *\n * @desc Get nested JavaScript object value from string key\n *\n * @param {string} path\n * @return {Item} property value\n */\n getNested(path: string): Item {\n let item = this;\n // TODO: throw error on invalid path\n path = path.replace(/\\[(\\w+)\\]/, \".$1\").replace(/^\\./, \"\");\n\n const keys = path.split(\".\");\n for (let key of keys) {\n if (typeof item === PrimitiveType.OBJECT && key in item) item = item[key];\n else return;\n }\n return item;\n }\n\n /**\n * @public\n *\n * @desc Deep clone an Object\n *\n * @param {Config} [config={}] Configuration object\n * @returns {object} Deep cloned Object\n *\n * @example\n *\n * const obj = new SuperObject({ key1: [\"1\", 1, true, (a, b) => a+b], [Symbol(\"key2\")]: {s: \"s\"} });\n * const clone = obj.clone();\n *\n * console.log(clone);\n * // { key1: [\"1\", 1, true, (a, b) => a+b], Symbol(\"key2\"): {s: \"s\"} }\n *\n */\n // $FlowFixMe\n clone(config: Config = {}): Object {\n const { includeNonEnumerable = false } = config;\n\n /**\n * @private\n *\n * @desc Deep clone helper\n *\n * @param {Item} item\n * @returns {any} cloned item\n */\n function _clone(item: Item): Item {\n if (item === null || typeof item !== PrimitiveType.OBJECT) {\n return item;\n }\n\n if (item instanceof InstanceType.DATE) {\n return new Date(item.valueOf());\n }\n\n if (item instanceof InstanceType.ARRAY) {\n let copy = [];\n\n item.forEach((_, i) => (copy[i] = _clone(item[i])));\n\n return copy;\n }\n\n if (item instanceof InstanceType.OBJECT) {\n let copy = {};\n\n // $FlowFixMe\n Object.getOwnPropertySymbols(item).forEach(s => (copy[s] = _clone(item[s])));\n\n if (includeNonEnumerable) {\n Object.getOwnPropertyNames(item).forEach(k => (copy[k] = _clone(item[k])));\n } else {\n Object.keys(item).forEach(k => (copy[k] = _clone(item[k])));\n }\n\n return copy;\n }\n\n throw new Error(`Unable to copy object: ${item}`);\n }\n\n return _clone(this);\n }\n}\n\nexport { _Object as Object };\n", @@ -2557,7 +3116,7 @@ "lineNumber": 1 }, { - "__docId__": 107, + "__docId__": 127, "kind": "typedef", "name": "Config", "memberof": "packages/Object/src/lib/Object.js", @@ -2588,7 +3147,7 @@ } }, { - "__docId__": 108, + "__docId__": 128, "kind": "class", "name": "_Object", "memberof": "packages/Object/src/lib/Object.js", @@ -2606,7 +3165,7 @@ ] }, { - "__docId__": 109, + "__docId__": 129, "kind": "constructor", "name": "constructor", "memberof": "packages/Object/src/lib/Object.js~_Object", @@ -2631,7 +3190,7 @@ ] }, { - "__docId__": 110, + "__docId__": 130, "kind": "method", "name": "hasNested", "memberof": "packages/Object/src/lib/Object.js~_Object", @@ -2664,7 +3223,7 @@ } }, { - "__docId__": 111, + "__docId__": 131, "kind": "method", "name": "getNested", "memberof": "packages/Object/src/lib/Object.js~_Object", @@ -2697,7 +3256,7 @@ } }, { - "__docId__": 112, + "__docId__": 132, "kind": "method", "name": "clone", "memberof": "packages/Object/src/lib/Object.js~_Object", @@ -2741,7 +3300,7 @@ } }, { - "__docId__": 113, + "__docId__": 133, "kind": "file", "name": "packages/PriorityQueue/src/lib/PriorityQueue.js", "content": "/**\n * @flow\n * @module super/priorityqueue\n */\n\nimport type { Comparator, Item } from \"../../../shared/src/types\";\nimport { PrimitiveType } from \"../../../shared/src/constants\";\nimport { QueueNode } from \"./QueueNode\";\nimport { isIterable } from \"../../../shared/src/helpers\";\n// $FlowFixMe\nimport isPlainObject from \"lodash/isPlainObject\";\n\ntype PriorityQueueItem1 = [Item];\ntype PriorityQueueItem2 = [[number, Item]];\ntype PriorityQueueItem3 = [{ priority: number, value: Item }];\n\ntype PriorityQueueIterable =\n | Map\n | PriorityQueueItem1\n | PriorityQueueItem2\n | PriorityQueueItem3;\n\n/**\n *\n * PriorityQueue with superpowers! 💪\n *\n * @public\n *\n */\nclass PriorityQueue {\n /** @private */\n _queue: Array;\n\n /** @private */\n _comparator: Comparator;\n\n /**\n * @public\n *\n * @desc Construct a PriorityQueue\n *\n * @param {PriorityQueueIterable} iterable\n * @param {Comparator} comparator\n */\n constructor(iterable: PriorityQueueIterable = new Map(), comparator: Comparator) {\n this._queue = [];\n this._comparator = comparator\n ? PriorityQueue._wrapComparator(comparator)\n : PriorityQueue._defaultComparator;\n\n if (!(iterable instanceof Map)) {\n if (isIterable(iterable)) {\n if (Array.isArray(iterable[0])) {\n // $FlowFixMe\n iterable = new Map(iterable);\n } else if (isPlainObject(iterable[0])) {\n iterable = new Map(iterable.map(({ value, priority }) => [priority, value]));\n } else {\n return iterable.forEach(v => this.insert(v));\n }\n } else {\n throw new Error(\"Unable to construct from non-iterable\");\n }\n }\n\n for (let [priority, value] of iterable.entries()) {\n this.insert(value, priority);\n }\n }\n\n static _wrapComparator(comparator: Comparator): Comparator {\n return (a, b) => comparator(a.value, b.value);\n }\n\n /**\n * @private\n *\n * @desc Default comparator function to sort from:\n * highest priority (max) -> lowest priority (min)\n *\n * @returns {number} size of the queue\n */\n static _defaultComparator(a: any, b: any): number | boolean {\n return a.priority < b.priority;\n }\n\n /**\n * @public\n *\n * @desc Get the current size of the queue\n *\n * @returns {number} size of the queue\n */\n get size(): number {\n return this._queue.length;\n }\n\n /**\n * @public\n *\n * @desc Get the item with the highest priority\n *\n * @returns {Item} highest priority item\n */\n get max(): Item {\n return this._queue[0];\n }\n\n /**\n * @public\n *\n * @alias max\n *\n * @desc Get the item with the highest priority\n *\n * @returns {Item} highest priority item\n */\n get high(): Item {\n return this.max;\n }\n\n /**\n * @public\n *\n * @desc Get the item with the lowest priority\n *\n * @returns {Item} lowest priority item\n */\n get min(): Item {\n return this._queue[this._queue.length - 1];\n }\n\n /**\n * @public\n *\n * @alias min\n *\n * @desc Get the item with the lowest priority\n *\n * @returns {Item} lowest priority item\n */\n get low(): Item {\n return this.min;\n }\n\n /**\n * @public\n *\n * @desc Check if queue is empty\n *\n * @returns {boolean} is queue empty\n */\n isEmpty(): boolean {\n return this._queue.length === 0;\n }\n\n /**\n * @public\n *\n * @desc Clear the items from the queue\n *\n * @returns {void}\n */\n clear() {\n this._queue.length = 0;\n }\n\n /**\n * @public\n *\n * @desc Enqueue an item into the queue\n *\n * @param {Item} value - item to insert\n * @param {number} [priority = 0] - priority of item (higher value === higher priority)\n * @returns {number} size after insert\n */\n insert(value: Item, priority: number = 0): number {\n if (typeof priority !== PrimitiveType.NUMBER) {\n throw new Error(`Unable to insert non-number priority: ${priority}`);\n }\n\n // TODO: use a heap\n this._queue.push(new QueueNode(value, priority));\n this._queue.sort(this._comparator);\n\n return this.size;\n }\n\n /**\n * @public\n *\n * @desc Remove and return the item with the highest priority\n *\n * @returns {Item} highest priority item\n */\n deleteMax(): Item {\n return this._queue.shift();\n }\n\n /**\n * @public\n *\n * @alias deleteMax\n *\n * @desc Remove and return the item with the highest priority\n *\n * @returns {Item} highest priority item\n */\n deleteHigh(): Item {\n return this.deleteMax();\n }\n\n /**\n * @public\n *\n * @desc Remove and return the item with the lowest priority\n *\n * @returns {Item} lowest priority item\n */\n deleteMin(): Item {\n return this._queue.pop();\n }\n\n /**\n * @public\n *\n * @alias deleteMin\n *\n * @desc Remove and return the item with the lowest priority\n *\n * @returns {Item} lowest priority item\n */\n deleteLow(): Item {\n return this.deleteMin();\n }\n\n /**\n * @public\n *\n * @desc Convert the queue to an array\n *\n * @returns {Array} array representation of the queue\n */\n toArray(): Array {\n return this._queue.slice(0);\n }\n}\n\nexport { PriorityQueue };\n", @@ -2752,7 +3311,7 @@ "lineNumber": 1 }, { - "__docId__": 114, + "__docId__": 134, "kind": "class", "name": "PriorityQueue", "memberof": "packages/PriorityQueue/src/lib/PriorityQueue.js", @@ -2767,7 +3326,7 @@ "interface": false }, { - "__docId__": 115, + "__docId__": 135, "kind": "constructor", "name": "constructor", "memberof": "packages/PriorityQueue/src/lib/PriorityQueue.js~PriorityQueue", @@ -2780,7 +3339,7 @@ "lineNumber": 31 }, { - "__docId__": 116, + "__docId__": 136, "kind": "member", "name": "_queue", "memberof": "packages/PriorityQueue/src/lib/PriorityQueue.js~PriorityQueue", @@ -2797,7 +3356,7 @@ } }, { - "__docId__": 117, + "__docId__": 137, "kind": "member", "name": "_comparator", "memberof": "packages/PriorityQueue/src/lib/PriorityQueue.js~PriorityQueue", @@ -2814,7 +3373,7 @@ } }, { - "__docId__": 118, + "__docId__": 138, "kind": "method", "name": "_wrapComparator", "memberof": "packages/PriorityQueue/src/lib/PriorityQueue.js~PriorityQueue", @@ -2840,7 +3399,7 @@ } }, { - "__docId__": 119, + "__docId__": 139, "kind": "method", "name": "_defaultComparator", "memberof": "packages/PriorityQueue/src/lib/PriorityQueue.js~PriorityQueue", @@ -2881,7 +3440,7 @@ ] }, { - "__docId__": 120, + "__docId__": 140, "kind": "get", "name": "size", "memberof": "packages/PriorityQueue/src/lib/PriorityQueue.js~PriorityQueue", @@ -2913,7 +3472,7 @@ } }, { - "__docId__": 121, + "__docId__": 141, "kind": "get", "name": "max", "memberof": "packages/PriorityQueue/src/lib/PriorityQueue.js~PriorityQueue", @@ -2945,7 +3504,7 @@ } }, { - "__docId__": 122, + "__docId__": 142, "kind": "get", "name": "high", "memberof": "packages/PriorityQueue/src/lib/PriorityQueue.js~PriorityQueue", @@ -2981,7 +3540,7 @@ } }, { - "__docId__": 123, + "__docId__": 143, "kind": "get", "name": "min", "memberof": "packages/PriorityQueue/src/lib/PriorityQueue.js~PriorityQueue", @@ -3013,7 +3572,7 @@ } }, { - "__docId__": 124, + "__docId__": 144, "kind": "get", "name": "low", "memberof": "packages/PriorityQueue/src/lib/PriorityQueue.js~PriorityQueue", @@ -3049,7 +3608,7 @@ } }, { - "__docId__": 125, + "__docId__": 145, "kind": "method", "name": "isEmpty", "memberof": "packages/PriorityQueue/src/lib/PriorityQueue.js~PriorityQueue", @@ -3077,7 +3636,7 @@ "params": [] }, { - "__docId__": 126, + "__docId__": 146, "kind": "method", "name": "clear", "memberof": "packages/PriorityQueue/src/lib/PriorityQueue.js~PriorityQueue", @@ -3105,7 +3664,7 @@ "params": [] }, { - "__docId__": 127, + "__docId__": 147, "kind": "method", "name": "insert", "memberof": "packages/PriorityQueue/src/lib/PriorityQueue.js~PriorityQueue", @@ -3156,7 +3715,7 @@ } }, { - "__docId__": 128, + "__docId__": 148, "kind": "method", "name": "deleteMax", "memberof": "packages/PriorityQueue/src/lib/PriorityQueue.js~PriorityQueue", @@ -3184,7 +3743,7 @@ "params": [] }, { - "__docId__": 129, + "__docId__": 149, "kind": "method", "name": "deleteHigh", "memberof": "packages/PriorityQueue/src/lib/PriorityQueue.js~PriorityQueue", @@ -3216,7 +3775,7 @@ "params": [] }, { - "__docId__": 130, + "__docId__": 150, "kind": "method", "name": "deleteMin", "memberof": "packages/PriorityQueue/src/lib/PriorityQueue.js~PriorityQueue", @@ -3244,7 +3803,7 @@ "params": [] }, { - "__docId__": 131, + "__docId__": 151, "kind": "method", "name": "deleteLow", "memberof": "packages/PriorityQueue/src/lib/PriorityQueue.js~PriorityQueue", @@ -3276,7 +3835,7 @@ "params": [] }, { - "__docId__": 132, + "__docId__": 152, "kind": "method", "name": "toArray", "memberof": "packages/PriorityQueue/src/lib/PriorityQueue.js~PriorityQueue", @@ -3304,7 +3863,7 @@ "params": [] }, { - "__docId__": 133, + "__docId__": 153, "kind": "file", "name": "packages/PriorityQueue/src/lib/QueueNode.js", "content": "/**\n * @flow\n * @module super/priorityqueue\n */\n\nimport type { Item } from \"../../../shared/src/types\";\n\n/**\n *\n * QueueNode\n *\n * @public\n *\n */\nclass QueueNode {\n /** @private */\n _value: Item;\n\n /** @private */\n _priority: number;\n\n /**\n * @public\n *\n * @desc Construct a PriorityQueue\n *\n * @param {Item} value - item value\n * @param {number} priority - priority of item\n */\n constructor(value: Item, priority: number) {\n this._value = value;\n this._priority = priority;\n }\n\n /**\n * @public\n *\n * @desc Get the value of the node\n *\n * @returns {Item} node value\n */\n get value(): Item {\n return this._value;\n }\n\n /**\n * @public\n *\n * @desc Get the priority of the node\n *\n * @returns {number} priority of item\n */\n get priority(): number {\n return this._priority;\n }\n}\n\nexport { QueueNode };\n", @@ -3315,7 +3874,7 @@ "lineNumber": 1 }, { - "__docId__": 134, + "__docId__": 154, "kind": "class", "name": "QueueNode", "memberof": "packages/PriorityQueue/src/lib/QueueNode.js", @@ -3330,7 +3889,7 @@ "interface": false }, { - "__docId__": 135, + "__docId__": 155, "kind": "constructor", "name": "constructor", "memberof": "packages/PriorityQueue/src/lib/QueueNode.js~QueueNode", @@ -3343,7 +3902,7 @@ "lineNumber": 22 }, { - "__docId__": 136, + "__docId__": 156, "kind": "member", "name": "_value", "memberof": "packages/PriorityQueue/src/lib/QueueNode.js~QueueNode", @@ -3360,7 +3919,7 @@ } }, { - "__docId__": 137, + "__docId__": 157, "kind": "member", "name": "_priority", "memberof": "packages/PriorityQueue/src/lib/QueueNode.js~QueueNode", @@ -3377,7 +3936,7 @@ } }, { - "__docId__": 138, + "__docId__": 158, "kind": "get", "name": "value", "memberof": "packages/PriorityQueue/src/lib/QueueNode.js~QueueNode", @@ -3395,7 +3954,7 @@ } }, { - "__docId__": 139, + "__docId__": 159, "kind": "get", "name": "priority", "memberof": "packages/PriorityQueue/src/lib/QueueNode.js~QueueNode", @@ -3427,7 +3986,7 @@ } }, { - "__docId__": 140, + "__docId__": 160, "kind": "file", "name": "packages/Queue/src/lib/Queue.js", "content": "/**\n * @flow\n * @module super/queue\n */\n\nimport type { Item } from \"../../../shared/src/types\";\n\n/**\n *\n * Queue with superpowers! 💪\n *\n * @public\n *\n */\nclass Queue {\n /** @private */\n _queue: Array;\n\n /**\n * @public\n *\n * @desc Construct a Queue\n *\n * @param {Array} iterable\n */\n constructor(iterable: Array = []) {\n this._queue = [...iterable];\n }\n\n /**\n * @public\n *\n * @desc Get the current size of the queue\n *\n * @returns {number} size of the queue\n */\n get size(): number {\n return this._queue.length;\n }\n\n /**\n * @public\n *\n * @desc Get the front item in the queue\n *\n * @returns {Item} front item\n */\n get front(): Item {\n return this._queue[0];\n }\n\n /**\n * @public\n *\n * @desc Get the rear item in the queue\n *\n * @returns {Item} rear item\n */\n get rear(): Item {\n return this._queue[this._queue.length - 1];\n }\n\n /**\n * @public\n *\n * @desc Check if queue is empty\n *\n * @returns {boolean} is queue empty\n */\n isEmpty(): boolean {\n return this._queue.length === 0;\n }\n\n /**\n * @public\n *\n * @desc Clear the items from the queue\n *\n * @returns {void}\n */\n clear() {\n this._queue.length = 0;\n }\n\n /**\n * @public\n *\n * @desc Enqueue an item into the queue\n *\n * @param {Item} item - item to enqueue\n * @returns {number} size after enqueue\n */\n enqueue(item: Item): number {\n return this._queue.push(item);\n }\n\n /**\n * @public\n *\n * @desc Dequeue an item from the queue\n *\n * @returns {Item} dequeued item\n */\n dequeue(): Item {\n return this._queue.shift();\n }\n\n /**\n * @public\n *\n * @desc Convert the queue to an array\n *\n * @returns {Array} array representation of the queue\n */\n toArray(): Array {\n return this._queue.slice(0);\n }\n}\n\nexport { Queue };\n", @@ -3438,7 +3997,7 @@ "lineNumber": 1 }, { - "__docId__": 141, + "__docId__": 161, "kind": "class", "name": "Queue", "memberof": "packages/Queue/src/lib/Queue.js", @@ -3453,7 +4012,7 @@ "interface": false }, { - "__docId__": 142, + "__docId__": 162, "kind": "constructor", "name": "constructor", "memberof": "packages/Queue/src/lib/Queue.js~Queue", @@ -3478,7 +4037,7 @@ ] }, { - "__docId__": 143, + "__docId__": 163, "kind": "member", "name": "_queue", "memberof": "packages/Queue/src/lib/Queue.js~Queue", @@ -3495,7 +4054,7 @@ } }, { - "__docId__": 144, + "__docId__": 164, "kind": "get", "name": "size", "memberof": "packages/Queue/src/lib/Queue.js~Queue", @@ -3513,7 +4072,7 @@ } }, { - "__docId__": 145, + "__docId__": 165, "kind": "get", "name": "front", "memberof": "packages/Queue/src/lib/Queue.js~Queue", @@ -3545,7 +4104,7 @@ } }, { - "__docId__": 146, + "__docId__": 166, "kind": "get", "name": "rear", "memberof": "packages/Queue/src/lib/Queue.js~Queue", @@ -3577,7 +4136,7 @@ } }, { - "__docId__": 147, + "__docId__": 167, "kind": "method", "name": "isEmpty", "memberof": "packages/Queue/src/lib/Queue.js~Queue", @@ -3605,7 +4164,7 @@ "params": [] }, { - "__docId__": 148, + "__docId__": 168, "kind": "method", "name": "clear", "memberof": "packages/Queue/src/lib/Queue.js~Queue", @@ -3633,7 +4192,7 @@ "params": [] }, { - "__docId__": 149, + "__docId__": 169, "kind": "method", "name": "enqueue", "memberof": "packages/Queue/src/lib/Queue.js~Queue", @@ -3672,7 +4231,7 @@ } }, { - "__docId__": 150, + "__docId__": 170, "kind": "method", "name": "dequeue", "memberof": "packages/Queue/src/lib/Queue.js~Queue", @@ -3700,7 +4259,7 @@ "params": [] }, { - "__docId__": 151, + "__docId__": 171, "kind": "method", "name": "toArray", "memberof": "packages/Queue/src/lib/Queue.js~Queue", @@ -3728,7 +4287,7 @@ "params": [] }, { - "__docId__": 152, + "__docId__": 172, "kind": "file", "name": "packages/QuickSort/src/lib/QuickSort.js", "content": "/**\n * @flow\n * @module super/quicksort\n */\n\nimport type { Comparator, Item } from \"../../../shared/src/types\";\nimport { _compare, _defaultComparator, swap, randInt } from \"../../../shared/src/helpers\";\n\nconst PartitionType = {\n LOMUTO: \"lomuto\",\n HOARE: \"hoare\"\n};\n\nconst PivotType = {\n LOW: \"low\",\n HIGH: \"high\",\n MID: \"mid\",\n RANDOM: \"rand\"\n};\n\ntype Partition = $Values;\n\ntype Pivot = $Values;\n\n/**\n *\n * QuickSort with superpowers! 💪\n *\n * time: O(nlogn)\n * space: O(nlogn)\n *\n * @public\n *\n * @param {Array} arr - array to sort\n * @param {Comparator} comparator\n * @returns {Array} sorted array\n */\nfunction quickSort(arr: Array, comparator: Comparator = _defaultComparator) {\n if (!(this instanceof Array) && !(arr instanceof Array)) {\n throw new Error(\"Array type is required\");\n }\n\n let target = this instanceof Array ? this : arr.slice(0);\n let compare = _compare(comparator);\n\n // TODO: make customizable?\n let partitionType: Partition = PartitionType.HOARE;\n let pivotType: Pivot = PivotType.RANDOM;\n\n /**\n *\n * QuickSort helper\n *\n * @private\n *\n * @param {Array} arr - array target\n * @param {number} low\n * @param {number} high\n * @returns {Array} sorted partition\n */\n function _quickSort(\n arr: Array,\n low: number = 0,\n high: number = arr.length - 1\n ): Array {\n if (low < high) {\n let pivot;\n\n switch (partitionType) {\n case PartitionType.LOMUTO:\n pivot = partitionLomuto(arr, low, high, pivotType, compare);\n _quickSort(arr, low, pivot - 1);\n break;\n case PartitionType.HOARE:\n default:\n pivot = partitionHoare(arr, low, high, pivotType, compare);\n _quickSort(arr, low, pivot);\n break;\n }\n\n _quickSort(arr, pivot + 1, high);\n }\n return arr;\n }\n\n return _quickSort(target);\n}\n\n/**\n *\n * Partition (Lomuto)\n *\n * @param {Array} arr\n * @param {number} low\n * @param {number} high\n * @param {PivotType} pivotType\n * @param {Comparator} compare\n * @return {number} pivot\n */\n\nfunction partitionLomuto(\n arr: Array,\n low: number,\n high: number,\n pivotType: Pivot,\n compare: Comparator\n): Item {\n function _partitionLomutoLow(arr: Array, low: number, high: number): Item {\n let pivot = low;\n let i = low + 1;\n\n for (let j = low + 1; j <= high; j++) {\n if (compare(arr[j], arr[pivot])) {\n swap(arr, i, j);\n i++;\n }\n }\n swap(arr, i - 1, low);\n return i - 1;\n }\n function _partitionLomutoHigh(arr: Array, low: number, high: number): Item {\n let pivot = high;\n let i = low - 1;\n\n for (let j = low; j < high; j++) {\n if (compare(arr[j], arr[pivot])) {\n i++;\n swap(arr, i, j);\n }\n }\n swap(arr, i + 1, high);\n return i + 1;\n }\n\n switch (pivotType) {\n case PivotType.LOW:\n return _partitionLomutoLow(arr, low, high);\n\n case PivotType.HIGH:\n default:\n return _partitionLomutoHigh(arr, low, high);\n }\n}\n\n/**\n *\n * Partition (Hoare)\n * it is more efficient than the Lomuto partition scheme\n * because it does three times fewer swaps on average\n *\n * @param {Array} arr\n * @param {number} low\n * @param {number} high\n * @param {string} pivotType\n * @param {Comparator} compare\n * @return {number} pivot\n */\nfunction partitionHoare(\n arr: Array,\n low: number,\n high: number,\n pivotType: Pivot,\n compare: Comparator\n): Item {\n let pivot;\n\n switch (pivotType) {\n case PivotType.LOW:\n pivot = low;\n break;\n\n case PivotType.RANDOM:\n let random = randInt(low, high);\n swap(arr, random, low);\n pivot = low;\n break;\n\n case PivotType.MID:\n default:\n pivot = Math.trunc((low + high) / 2);\n break;\n }\n\n let i = low - 1;\n let j = high + 1;\n\n while (true) {\n do {\n i++;\n } while (compare(arr[i], arr[pivot]));\n do {\n j--;\n } while (compare(arr[pivot], arr[j]));\n if (i >= j) {\n return j;\n }\n swap(arr, i, j);\n }\n}\n\nexport { quickSort };\n", @@ -3739,7 +4298,7 @@ "lineNumber": 1 }, { - "__docId__": 153, + "__docId__": 173, "kind": "variable", "name": "PartitionType", "memberof": "packages/QuickSort/src/lib/QuickSort.js", @@ -3764,7 +4323,7 @@ } }, { - "__docId__": 154, + "__docId__": 174, "kind": "variable", "name": "PivotType", "memberof": "packages/QuickSort/src/lib/QuickSort.js", @@ -3784,7 +4343,7 @@ } }, { - "__docId__": 155, + "__docId__": 175, "kind": "function", "name": "partitionLomuto", "memberof": "packages/QuickSort/src/lib/QuickSort.js", @@ -3860,7 +4419,7 @@ } }, { - "__docId__": 156, + "__docId__": 176, "kind": "function", "name": "partitionHoare", "memberof": "packages/QuickSort/src/lib/QuickSort.js", @@ -3936,7 +4495,7 @@ } }, { - "__docId__": 157, + "__docId__": 177, "kind": "function", "name": "quickSort", "memberof": "packages/QuickSort/src/lib/QuickSort.js", @@ -3988,7 +4547,7 @@ } }, { - "__docId__": 158, + "__docId__": 178, "kind": "file", "name": "packages/SelectionSort/src/lib/SelectionSort.js", "content": "/**\n * @flow\n * @module super/selectionsort\n */\n\nimport type { Comparator, Item } from \"../../../shared/src/types\";\nimport { _compare, _defaultComparator, swap } from \"../../../shared/src/helpers\";\n\n/**\n *\n * SelectionSort with superpowers! 💪\n *\n * time: O(n^2)\n * space: O(1)\n *\n * @public\n *\n * @param {Array} arr - array to sort\n * @param {Comparator} comparator\n * @returns {Array} sorted array\n */\nfunction selectionSort(arr: Array, comparator: Comparator = _defaultComparator) {\n if (!(this instanceof Array) && !(arr instanceof Array)) {\n throw new Error(\"Array type is required\");\n }\n\n let target = this instanceof Array ? this : arr.slice(0);\n let compare = _compare(comparator);\n\n /**\n *\n * SelectionSort helper\n *\n * @private\n *\n * @param {Array} arr - array target\n * @returns {Array} sorted array\n */\n function _selectionSort(arr: Array): Array {\n for (let i = 0; i < arr.length - 1; i++) {\n let min = i;\n\n for (let j = i + 1; j < arr.length; j++) {\n if (compare(arr[j], arr[min])) {\n min = j;\n }\n }\n swap(arr, i, min);\n }\n\n return arr;\n }\n\n return _selectionSort(target);\n}\n\nexport { selectionSort };\n", @@ -3999,7 +4558,7 @@ "lineNumber": 1 }, { - "__docId__": 159, + "__docId__": 179, "kind": "function", "name": "selectionSort", "memberof": "packages/SelectionSort/src/lib/SelectionSort.js", @@ -4043,7 +4602,7 @@ } }, { - "__docId__": 160, + "__docId__": 180, "kind": "file", "name": "packages/Set/src/lib/Set.js", "content": "/**\n * @flow\n * @module super/set\n */\n\n/**\n * @typedef {Function} Callback\n */\nimport type { Item } from \"../../../shared/src/types\";\n\ntype Callback = (value1: any, value2: any, set: Set) => boolean;\n\n/**\n *\n * Set with superpowers! 💪\n *\n * @public\n *\n */\nclass _Set extends Set {\n /**\n * @public\n *\n * @desc Construct a Set\n *\n * @param {Array} iterable\n */\n constructor(iterable: Array) {\n super(iterable);\n }\n\n /**\n * @public\n *\n * @desc Tests whether at least one element in the set passes the test implemented by the provided function\n *\n * @param {Callback} callback - callback function\n * @returns {boolean} true if the callback function returns a truthy value for any set element; otherwise, false\n */\n some(callback: (value1: any, value2: any, set: Set) => boolean): boolean {\n let result;\n\n for (let [value1, value2] of this.entries()) {\n result = callback(value1, value2, this);\n if (result) return true;\n }\n\n return false;\n }\n\n /**\n * @public\n *\n * @desc Test whether all elements in the set pass the test implemented by the provided function\n *\n * @param {Callback} callback - callback function\n * @returns {boolean} true if the callback function returns a truthy value for every set element; otherwise, false\n */\n every(callback: (value1: any, value2: any, set: Set) => boolean): boolean {\n let result;\n\n for (let [value1, value2] of this.entries()) {\n result = callback(value1, value2, this);\n if (!result) return false;\n }\n\n return true;\n }\n\n /**\n * @public\n *\n * @desc Subset of a set\n *\n * @param {Set} setB - SetB\n * @returns {boolean} setA is subset of setB\n */\n isSubset(setB: Set): boolean {\n let setA = this;\n\n for (let v of setA) {\n if (!setB.has(v)) return false;\n }\n return true;\n }\n\n /**\n * @public\n *\n * @desc Superset of a set\n *\n * @param {Set} setB - SetB\n * @returns {boolean} setA is superset of setB\n */\n isSuperset(setB: Set): boolean {\n let setA = this;\n\n for (let v of setB) {\n if (!setA.has(v)) return false;\n }\n return true;\n }\n\n /**\n * @public\n *\n * @desc Union of setA and setB\n *\n * @param {Set} setB - SetB\n * @returns {Set} setC - union between setA and setB\n */\n union(setB: Set): Set {\n let setA = this;\n let setC = new Set(setA);\n\n for (let v of setB) {\n setC.add(v);\n }\n\n return setC;\n }\n\n /**\n * @public\n *\n * @desc Intersection of setA and setB\n *\n * @param {Set} setB - SetB\n * @returns {Set} setC - intersection between setA and setB\n */\n intersection(setB: Set): Set {\n let setA = this;\n let setC = new Set();\n\n for (let v of setB) {\n if (setA.has(v)) setC.add(v);\n }\n\n return setC;\n }\n\n /**\n * @public\n *\n * @desc Difference of setA and setB\n *\n * @param {Set} setB - SetB\n * @returns {Set} setC - difference between setA and setB\n */\n difference(setB: Set): Set {\n let setA = this;\n let setC = new Set(setA);\n\n for (let v of setB) {\n setC.delete(v);\n }\n\n return setC;\n }\n\n /**\n * @public\n *\n * @desc Symmetric difference of setA and setB\n *\n * @param {Set} setB - SetB\n * @returns {Set} setC - difference difference between setA and setB\n */\n symmetricDifference(setB: Set): Set {\n let setA = this;\n let setC = new Set(setA);\n\n for (let v of setB) {\n if (setA.has(v)) setC.delete(v);\n else setC.add(v);\n }\n\n return setC;\n }\n}\n\nexport { _Set as Set };\n", @@ -4054,7 +4613,7 @@ "lineNumber": 1 }, { - "__docId__": 161, + "__docId__": 181, "kind": "typedef", "name": "Callback", "memberof": "packages/Set/src/lib/Set.js", @@ -4072,7 +4631,7 @@ } }, { - "__docId__": 162, + "__docId__": 182, "kind": "file", "name": "packages/String/src/lib/String.js", "content": "/**\n * @flow\n * @module super/string\n */\n\n/**\n *\n * String with superpowers! 💪\n *\n * @public\n *\n */\nclass _String extends String {\n /**\n * @public\n *\n * @desc Construct a String\n *\n * @param {string} string\n */\n constructor(string: string) {\n super(string);\n }\n\n /**\n * @public\n *\n * @desc Transposes the ordering of all characters in the string\n *\n * @returns {string} String reversed\n */\n reverse(): string {\n return this.split(\"\")\n .filter(s => s)\n .reverse()\n .join(\"\");\n }\n\n /**\n * @public\n *\n * @desc Transposes the ordering of the words in the string\n *\n * @returns {string} String with words reversed\n */\n reverseWords(): string {\n return this.split(\" \")\n .filter(s => s)\n .reverse()\n .join(\" \");\n }\n\n /**\n * @public\n *\n * @desc Convert a string to title case\n *\n * @returns {string} Title cased string representation\n */\n toTitleCase(): string {\n return this.split(\" \")\n .map(v => v && v.charAt(0).toUpperCase() + v.substr(1).toLowerCase())\n .join(\" \");\n }\n}\n\nexport { _String as String };\n", @@ -4083,7 +4642,7 @@ "lineNumber": 1 }, { - "__docId__": 163, + "__docId__": 183, "kind": "class", "name": "_String", "memberof": "packages/String/src/lib/String.js", @@ -4101,7 +4660,7 @@ ] }, { - "__docId__": 164, + "__docId__": 184, "kind": "constructor", "name": "constructor", "memberof": "packages/String/src/lib/String.js~_String", @@ -4126,7 +4685,7 @@ ] }, { - "__docId__": 165, + "__docId__": 185, "kind": "method", "name": "reverse", "memberof": "packages/String/src/lib/String.js~_String", @@ -4154,7 +4713,7 @@ "params": [] }, { - "__docId__": 166, + "__docId__": 186, "kind": "method", "name": "reverseWords", "memberof": "packages/String/src/lib/String.js~_String", @@ -4182,7 +4741,7 @@ "params": [] }, { - "__docId__": 167, + "__docId__": 187, "kind": "method", "name": "toTitleCase", "memberof": "packages/String/src/lib/String.js~_String", @@ -4210,7 +4769,7 @@ "params": [] }, { - "__docId__": 168, + "__docId__": 188, "kind": "file", "name": "packages/Trie/src/lib/Trie.js", "content": "/**\n * @flow\n * @module super/trie\n */\n\nimport { TrieNode } from \"./TrieNode\";\nimport { PrimitiveType } from \"../../../shared/src/constants\";\nimport type { character } from \"../../../shared/src/types\";\n\ntype Match = {\n query: string,\n matchedChars: number,\n isMatch: boolean,\n isCompleteWord: boolean,\n node: ?TrieNode\n};\n\n/**\n *\n * Trie with superpowers! 💪\n *\n * @public\n *\n */\nclass Trie {\n /** @private */\n _root: TrieNode;\n\n /**\n * @public\n *\n * @desc Construct a Trie\n *\n * @param {Array} iterable\n */\n constructor(iterable: Array = []) {\n this._root = new TrieNode();\n\n for (let word of iterable) {\n this.insert(word);\n }\n }\n\n /**\n * @public\n *\n * @desc Get the root of the trie\n *\n * @returns {TrieNode} root node\n */\n get root(): TrieNode {\n return this._root;\n }\n\n /**\n * @public\n *\n * @desc Insert a string into the trie\n *\n * @param {string} word - string to insert\n */\n insert(word: string) {\n if (typeof word !== PrimitiveType.STRING) {\n throw new Error(`Unable to insert non-string value: ${word}`);\n }\n\n let curr: TrieNode = this.root;\n\n for (const char: character of word) {\n if (curr.has(char)) {\n // $FlowFixMe\n curr = curr.get(char);\n } else {\n let node = new TrieNode(char);\n curr.set(char, node);\n curr = node;\n }\n }\n\n curr._isCompleteWord = true;\n }\n\n /**\n * @public\n *\n * @desc Remove a string from the trie\n *\n * @param {string} word - string to remove\n */\n remove(word: string) {\n if (typeof word !== PrimitiveType.STRING) {\n throw new Error(`Unable to remove non-string value: ${word}`);\n }\n\n /**\n * @public\n *\n * @desc Remove helper\n *\n * @param {TrieNode} curr - trie node\n * @param {number} level - level in trie (0 -> height)\n * @return {boolean} true if node is a leaf node and should be deleted; otherwise false\n */\n // $FlowFixMe\n function _remove(curr: ?TrieNode, level: number = 0): boolean {\n if (!curr) return false;\n\n if (level === word.length) {\n curr._isCompleteWord = false;\n return curr.isLeafNode;\n }\n\n let char = word[level];\n\n if (_remove(curr.get(char), level + 1)) {\n curr.delete(char);\n return curr.isLeafNode;\n }\n }\n\n return _remove(this.root);\n }\n\n /**\n * @public\n *\n * @desc Search for a node in the trie matching the query\n *\n * @param {string} query - string query to search for\n * @returns {Match} match object\n */\n search(query: string): Match {\n let node = this.root;\n let index = 0;\n\n while (index < query.length) {\n node = node.get(query[index]);\n if (!node) break;\n index++;\n }\n\n return {\n query,\n matchedChars: index,\n isMatch: query.length === index,\n // $FlowFixMe\n isCompleteWord: query.length === index && node.isCompleteWord,\n node\n };\n }\n\n /**\n * @public\n *\n * @desc Check if the trie includes a word\n *\n * @param {string} word - full word to search for\n * @returns {boolean} contains the word\n */\n includes(word: string): boolean {\n let { isCompleteWord } = this.search(word);\n return isCompleteWord;\n }\n\n /**\n * @public\n *\n * @alias includes(word)\n *\n * @desc Check if the trie contains a word\n *\n * @param {string} word - full word to search for\n * @returns {boolean} contains the word\n */\n contains(word: string): boolean {\n return this.includes(word);\n }\n\n /**\n * @public\n *\n * @desc Check if the trie contains a prefix\n *\n * @param {string} prefix - prefix (i.e. partial word) to search for\n * @returns {boolean} contains the prefix\n */\n startsWith(prefix: string): boolean {\n let { isMatch } = this.search(prefix);\n return isMatch;\n }\n}\n\nexport { Trie };\n", @@ -4221,7 +4780,7 @@ "lineNumber": 1 }, { - "__docId__": 169, + "__docId__": 189, "kind": "class", "name": "Trie", "memberof": "packages/Trie/src/lib/Trie.js", @@ -4236,7 +4795,7 @@ "interface": false }, { - "__docId__": 170, + "__docId__": 190, "kind": "constructor", "name": "constructor", "memberof": "packages/Trie/src/lib/Trie.js~Trie", @@ -4261,7 +4820,7 @@ ] }, { - "__docId__": 171, + "__docId__": 191, "kind": "member", "name": "_root", "memberof": "packages/Trie/src/lib/Trie.js~Trie", @@ -4278,7 +4837,7 @@ } }, { - "__docId__": 172, + "__docId__": 192, "kind": "get", "name": "root", "memberof": "packages/Trie/src/lib/Trie.js~Trie", @@ -4296,7 +4855,7 @@ } }, { - "__docId__": 173, + "__docId__": 193, "kind": "method", "name": "insert", "memberof": "packages/Trie/src/lib/Trie.js~Trie", @@ -4322,7 +4881,7 @@ "return": null }, { - "__docId__": 174, + "__docId__": 194, "kind": "method", "name": "remove", "memberof": "packages/Trie/src/lib/Trie.js~Trie", @@ -4352,7 +4911,7 @@ } }, { - "__docId__": 175, + "__docId__": 195, "kind": "method", "name": "search", "memberof": "packages/Trie/src/lib/Trie.js~Trie", @@ -4391,7 +4950,7 @@ } }, { - "__docId__": 176, + "__docId__": 196, "kind": "method", "name": "includes", "memberof": "packages/Trie/src/lib/Trie.js~Trie", @@ -4430,7 +4989,7 @@ } }, { - "__docId__": 177, + "__docId__": 197, "kind": "method", "name": "contains", "memberof": "packages/Trie/src/lib/Trie.js~Trie", @@ -4473,7 +5032,7 @@ } }, { - "__docId__": 178, + "__docId__": 198, "kind": "method", "name": "startsWith", "memberof": "packages/Trie/src/lib/Trie.js~Trie", @@ -4512,7 +5071,7 @@ } }, { - "__docId__": 179, + "__docId__": 199, "kind": "file", "name": "packages/Trie/src/lib/TrieNode.js", "content": "/**\n * @flow\n * @module super/trie\n */\n\nimport type { character } from \"../../../shared/src/types\";\n\nconst SpecialChar = {\n ROOT: \"√\"\n};\n\n/**\n *\n * TrieNode\n *\n * @public\n *\n */\nclass TrieNode {\n /** @private */\n _char: character;\n\n /** @private */\n _isCompleteWord: boolean;\n\n /** @private */\n _children: Map;\n\n /**\n * @public\n *\n * @desc Construct a TrieNode\n *\n * @param {character} char - node character value\n */\n constructor(char: character = SpecialChar.ROOT) {\n this._char = char;\n this._isCompleteWord = false;\n this._children = new Map();\n }\n\n /**\n * @public\n *\n * @desc Get children count of the node\n *\n * @returns {number} child count\n */\n // INFO: count or size?\n get count(): number {\n return this._children.size;\n }\n\n /**\n * @public\n *\n * @desc Get character value of node\n *\n * @returns {character} character\n */\n // INFO: char or value?\n get char(): character {\n return this._char;\n }\n\n /**\n * @public\n *\n * @desc Checks if node is a complete word\n *\n * @returns {boolean} is complete word\n */\n get isCompleteWord(): boolean {\n return this._isCompleteWord;\n }\n\n /**\n * @public\n *\n * @desc Checks if node is a leaf node\n *\n * @returns {boolean} is leaf node\n */\n get isLeafNode(): boolean {\n return this.count === 0;\n }\n\n /**\n * @public\n *\n * @desc Check if node has a specific character as a child\n *\n * @param {character} char - character to check\n * @returns {boolean} node has child\n */\n has(char: character): boolean {\n return this._children.has(char);\n }\n\n /**\n * @public\n *\n * @desc Get child node with specific character value\n *\n * @param {character} char - character to get\n * @returns {TrieNode} node with character value\n */\n get(char: character): ?TrieNode {\n return this._children.get(char);\n }\n\n /**\n * @public\n *\n * @desc Set child node with specific character value\n *\n * @param {character} char - character to set\n * @param {TrieNode} node - node to assign to character\n */\n set(char: character, node: TrieNode) {\n this._children.set(char, node);\n }\n\n /**\n * @public\n *\n * @desc Delete child node with specific character value\n *\n * @param {character} char - character to delete\n */\n delete(char: character) {\n this._children.delete(char);\n }\n}\n\nexport { TrieNode };\n", @@ -4523,7 +5082,7 @@ "lineNumber": 1 }, { - "__docId__": 180, + "__docId__": 200, "kind": "variable", "name": "SpecialChar", "memberof": "packages/Trie/src/lib/TrieNode.js", @@ -4543,7 +5102,7 @@ } }, { - "__docId__": 181, + "__docId__": 201, "kind": "class", "name": "TrieNode", "memberof": "packages/Trie/src/lib/TrieNode.js", @@ -4564,7 +5123,7 @@ "interface": false }, { - "__docId__": 182, + "__docId__": 202, "kind": "constructor", "name": "constructor", "memberof": "packages/Trie/src/lib/TrieNode.js~TrieNode", @@ -4577,7 +5136,7 @@ "lineNumber": 31 }, { - "__docId__": 183, + "__docId__": 203, "kind": "member", "name": "_char", "memberof": "packages/Trie/src/lib/TrieNode.js~TrieNode", @@ -4594,7 +5153,7 @@ } }, { - "__docId__": 184, + "__docId__": 204, "kind": "member", "name": "_isCompleteWord", "memberof": "packages/Trie/src/lib/TrieNode.js~TrieNode", @@ -4611,7 +5170,7 @@ } }, { - "__docId__": 185, + "__docId__": 205, "kind": "member", "name": "_children", "memberof": "packages/Trie/src/lib/TrieNode.js~TrieNode", @@ -4628,7 +5187,7 @@ } }, { - "__docId__": 186, + "__docId__": 206, "kind": "get", "name": "count", "memberof": "packages/Trie/src/lib/TrieNode.js~TrieNode", @@ -4646,7 +5205,7 @@ } }, { - "__docId__": 187, + "__docId__": 207, "kind": "get", "name": "char", "memberof": "packages/Trie/src/lib/TrieNode.js~TrieNode", @@ -4678,7 +5237,7 @@ } }, { - "__docId__": 188, + "__docId__": 208, "kind": "get", "name": "isCompleteWord", "memberof": "packages/Trie/src/lib/TrieNode.js~TrieNode", @@ -4710,7 +5269,7 @@ } }, { - "__docId__": 189, + "__docId__": 209, "kind": "get", "name": "isLeafNode", "memberof": "packages/Trie/src/lib/TrieNode.js~TrieNode", @@ -4742,7 +5301,7 @@ } }, { - "__docId__": 190, + "__docId__": 210, "kind": "method", "name": "has", "memberof": "packages/Trie/src/lib/TrieNode.js~TrieNode", @@ -4781,7 +5340,7 @@ } }, { - "__docId__": 191, + "__docId__": 211, "kind": "method", "name": "get", "memberof": "packages/Trie/src/lib/TrieNode.js~TrieNode", @@ -4820,7 +5379,7 @@ } }, { - "__docId__": 192, + "__docId__": 212, "kind": "method", "name": "set", "memberof": "packages/Trie/src/lib/TrieNode.js~TrieNode", @@ -4856,7 +5415,7 @@ "return": null }, { - "__docId__": 193, + "__docId__": 213, "kind": "method", "name": "delete", "memberof": "packages/Trie/src/lib/TrieNode.js~TrieNode", diff --git a/docs/script/search_index.js b/docs/script/search_index.js index 1daa840..f8c334f 100644 --- a/docs/script/search_index.js +++ b/docs/script/search_index.js @@ -11,6 +11,12 @@ window.esdocSearchIndex = [ "BinaryTreeNode @clarketm/super/packages/BinaryTree/src/lib/BinaryTreeNode.js", "class" ], + [ + "@clarketm/super/packages/heap/src/lib/heap.js~heap", + "class/packages/Heap/src/lib/Heap.js~Heap.html", + "Heap @clarketm/super/packages/Heap/src/lib/Heap.js", + "class" + ], [ "@clarketm/super/packages/number/src/lib/number.js~integertoromannumeralmap", "variable/index.html#static-variable-IntegerToRomanNumeralMap", @@ -367,37 +373,37 @@ window.esdocSearchIndex = [ ], [ "packages/binarytree/src/lib/binarytreenode.js~binarytreenode#left", - "class/packages/BinaryTree/src/lib/BinaryTreeNode.js~BinaryTreeNode.html#instance-get-left", + "class/packages/BinaryTree/src/lib/BinaryTreeNode.js~BinaryTreeNode.html#instance-set-left", "packages/BinaryTree/src/lib/BinaryTreeNode.js~BinaryTreeNode#left", "member" ], [ "packages/binarytree/src/lib/binarytreenode.js~binarytreenode#left", - "class/packages/BinaryTree/src/lib/BinaryTreeNode.js~BinaryTreeNode.html#instance-set-left", + "class/packages/BinaryTree/src/lib/BinaryTreeNode.js~BinaryTreeNode.html#instance-get-left", "packages/BinaryTree/src/lib/BinaryTreeNode.js~BinaryTreeNode#left", "member" ], [ "packages/binarytree/src/lib/binarytreenode.js~binarytreenode#right", - "class/packages/BinaryTree/src/lib/BinaryTreeNode.js~BinaryTreeNode.html#instance-get-right", + "class/packages/BinaryTree/src/lib/BinaryTreeNode.js~BinaryTreeNode.html#instance-set-right", "packages/BinaryTree/src/lib/BinaryTreeNode.js~BinaryTreeNode#right", "member" ], [ "packages/binarytree/src/lib/binarytreenode.js~binarytreenode#right", - "class/packages/BinaryTree/src/lib/BinaryTreeNode.js~BinaryTreeNode.html#instance-set-right", + "class/packages/BinaryTree/src/lib/BinaryTreeNode.js~BinaryTreeNode.html#instance-get-right", "packages/BinaryTree/src/lib/BinaryTreeNode.js~BinaryTreeNode#right", "member" ], [ "packages/binarytree/src/lib/binarytreenode.js~binarytreenode#value", - "class/packages/BinaryTree/src/lib/BinaryTreeNode.js~BinaryTreeNode.html#instance-set-value", + "class/packages/BinaryTree/src/lib/BinaryTreeNode.js~BinaryTreeNode.html#instance-get-value", "packages/BinaryTree/src/lib/BinaryTreeNode.js~BinaryTreeNode#value", "member" ], [ "packages/binarytree/src/lib/binarytreenode.js~binarytreenode#value", - "class/packages/BinaryTree/src/lib/BinaryTreeNode.js~BinaryTreeNode.html#instance-get-value", + "class/packages/BinaryTree/src/lib/BinaryTreeNode.js~BinaryTreeNode.html#instance-set-value", "packages/BinaryTree/src/lib/BinaryTreeNode.js~BinaryTreeNode#value", "member" ], @@ -407,6 +413,120 @@ window.esdocSearchIndex = [ "packages/BubbleSort/src/lib/BubbleSort.js", "file" ], + [ + "packages/heap/src/lib/heap.js", + "file/packages/Heap/src/lib/Heap.js.html", + "packages/Heap/src/lib/Heap.js", + "file" + ], + [ + "packages/heap/src/lib/heap.js~heap#_compare", + "class/packages/Heap/src/lib/Heap.js~Heap.html#instance-member-_compare", + "packages/Heap/src/lib/Heap.js~Heap#_compare", + "member" + ], + [ + "packages/heap/src/lib/heap.js~heap#_heap", + "class/packages/Heap/src/lib/Heap.js~Heap.html#instance-member-_heap", + "packages/Heap/src/lib/Heap.js~Heap#_heap", + "member" + ], + [ + "packages/heap/src/lib/heap.js~heap#_percolatedown", + "class/packages/Heap/src/lib/Heap.js~Heap.html#instance-method-_percolateDown", + "packages/Heap/src/lib/Heap.js~Heap#_percolateDown", + "method" + ], + [ + "packages/heap/src/lib/heap.js~heap#_percolateup", + "class/packages/Heap/src/lib/Heap.js~Heap.html#instance-method-_percolateUp", + "packages/Heap/src/lib/Heap.js~Heap#_percolateUp", + "method" + ], + [ + "packages/heap/src/lib/heap.js~heap#clear", + "class/packages/Heap/src/lib/Heap.js~Heap.html#instance-method-clear", + "packages/Heap/src/lib/Heap.js~Heap#clear", + "method" + ], + [ + "packages/heap/src/lib/heap.js~heap#constructor", + "class/packages/Heap/src/lib/Heap.js~Heap.html#instance-constructor-constructor", + "packages/Heap/src/lib/Heap.js~Heap#constructor", + "method" + ], + [ + "packages/heap/src/lib/heap.js~heap#deletemax", + "class/packages/Heap/src/lib/Heap.js~Heap.html#instance-method-deleteMax", + "packages/Heap/src/lib/Heap.js~Heap#deleteMax", + "method" + ], + [ + "packages/heap/src/lib/heap.js~heap#deletemin", + "class/packages/Heap/src/lib/Heap.js~Heap.html#instance-method-deleteMin", + "packages/Heap/src/lib/Heap.js~Heap#deleteMin", + "method" + ], + [ + "packages/heap/src/lib/heap.js~heap#insert", + "class/packages/Heap/src/lib/Heap.js~Heap.html#instance-method-insert", + "packages/Heap/src/lib/Heap.js~Heap#insert", + "method" + ], + [ + "packages/heap/src/lib/heap.js~heap#isempty", + "class/packages/Heap/src/lib/Heap.js~Heap.html#instance-method-isEmpty", + "packages/Heap/src/lib/Heap.js~Heap#isEmpty", + "method" + ], + [ + "packages/heap/src/lib/heap.js~heap#max", + "class/packages/Heap/src/lib/Heap.js~Heap.html#instance-get-max", + "packages/Heap/src/lib/Heap.js~Heap#max", + "member" + ], + [ + "packages/heap/src/lib/heap.js~heap#min", + "class/packages/Heap/src/lib/Heap.js~Heap.html#instance-get-min", + "packages/Heap/src/lib/Heap.js~Heap#min", + "member" + ], + [ + "packages/heap/src/lib/heap.js~heap#size", + "class/packages/Heap/src/lib/Heap.js~Heap.html#instance-get-size", + "packages/Heap/src/lib/Heap.js~Heap#size", + "member" + ], + [ + "packages/heap/src/lib/heap.js~heap#toarray", + "class/packages/Heap/src/lib/Heap.js~Heap.html#instance-method-toArray", + "packages/Heap/src/lib/Heap.js~Heap#toArray", + "method" + ], + [ + "packages/heap/src/lib/heap.js~heap._defaultcomparator", + "class/packages/Heap/src/lib/Heap.js~Heap.html#static-method-_defaultComparator", + "packages/Heap/src/lib/Heap.js~Heap._defaultComparator", + "method" + ], + [ + "packages/heap/src/lib/heap.js~heap._left", + "class/packages/Heap/src/lib/Heap.js~Heap.html#static-method-_left", + "packages/Heap/src/lib/Heap.js~Heap._left", + "method" + ], + [ + "packages/heap/src/lib/heap.js~heap._parent", + "class/packages/Heap/src/lib/Heap.js~Heap.html#static-method-_parent", + "packages/Heap/src/lib/Heap.js~Heap._parent", + "method" + ], + [ + "packages/heap/src/lib/heap.js~heap._right", + "class/packages/Heap/src/lib/Heap.js~Heap.html#static-method-_right", + "packages/Heap/src/lib/Heap.js~Heap._right", + "method" + ], [ "packages/insertionsort/src/lib/insertionsort.js", "file/packages/InsertionSort/src/lib/InsertionSort.js.html", @@ -547,37 +667,37 @@ window.esdocSearchIndex = [ ], [ "packages/linkedlist/src/lib/listnode.js~listnode#next", - "class/packages/LinkedList/src/lib/ListNode.js~ListNode.html#instance-get-next", + "class/packages/LinkedList/src/lib/ListNode.js~ListNode.html#instance-set-next", "packages/LinkedList/src/lib/ListNode.js~ListNode#next", "member" ], [ "packages/linkedlist/src/lib/listnode.js~listnode#next", - "class/packages/LinkedList/src/lib/ListNode.js~ListNode.html#instance-set-next", + "class/packages/LinkedList/src/lib/ListNode.js~ListNode.html#instance-get-next", "packages/LinkedList/src/lib/ListNode.js~ListNode#next", "member" ], [ "packages/linkedlist/src/lib/listnode.js~listnode#prev", - "class/packages/LinkedList/src/lib/ListNode.js~ListNode.html#instance-get-prev", + "class/packages/LinkedList/src/lib/ListNode.js~ListNode.html#instance-set-prev", "packages/LinkedList/src/lib/ListNode.js~ListNode#prev", "member" ], [ "packages/linkedlist/src/lib/listnode.js~listnode#prev", - "class/packages/LinkedList/src/lib/ListNode.js~ListNode.html#instance-set-prev", + "class/packages/LinkedList/src/lib/ListNode.js~ListNode.html#instance-get-prev", "packages/LinkedList/src/lib/ListNode.js~ListNode#prev", "member" ], [ "packages/linkedlist/src/lib/listnode.js~listnode#value", - "class/packages/LinkedList/src/lib/ListNode.js~ListNode.html#instance-get-value", + "class/packages/LinkedList/src/lib/ListNode.js~ListNode.html#instance-set-value", "packages/LinkedList/src/lib/ListNode.js~ListNode#value", "member" ], [ "packages/linkedlist/src/lib/listnode.js~listnode#value", - "class/packages/LinkedList/src/lib/ListNode.js~ListNode.html#instance-set-value", + "class/packages/LinkedList/src/lib/ListNode.js~ListNode.html#instance-get-value", "packages/LinkedList/src/lib/ListNode.js~ListNode#value", "member" ], diff --git a/docs/source.html b/docs/source.html index 76b8403..43d81b4 100644 --- a/docs/source.html +++ b/docs/source.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • @@ -67,7 +68,7 @@
    -

    Source 136/159

    +

    Source 153/178

    summary
    + public + + + + + +
    +

    + C + + + Heap +

    +
    +
    + + + +
    +
    + +
    @@ -115,6 +116,14 @@ + + + + + + + + diff --git a/docs/typedef/index.html b/docs/typedef/index.html index 0aab9c5..95ceaf0 100644 --- a/docs/typedef/index.html +++ b/docs/typedef/index.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • diff --git a/docs/variable/index.html b/docs/variable/index.html index 0903728..9d37c22 100644 --- a/docs/variable/index.html +++ b/docs/variable/index.html @@ -35,6 +35,7 @@
  • CBinaryTreeNode
  • VTraversalType
  • BubbleSort/src/libFbubbleSort
  • +
  • Heap/src/libCHeap
  • InsertionSort/src/libFinsertionSort
  • LinkedList/src/libCLinkedList
  • CListNode
  • diff --git a/package.json b/package.json index 39baff4..a2f86a2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@clarketm/super", - "version": "0.0.7", + "version": "0.0.8", "description": "Data structures, data types, and algorithms with superpowers! 💪", "main": "dist/super.js", "module": "dist/super.es.js", diff --git a/packages/Heap/src/lib/Heap.js b/packages/Heap/src/lib/Heap.js index 5a5a570..9a3331d 100644 --- a/packages/Heap/src/lib/Heap.js +++ b/packages/Heap/src/lib/Heap.js @@ -14,10 +14,10 @@ import { _compare, swap } from "../../../shared/src/helpers"; * */ class Heap { - // static HeapType = { - // MIN: (a: Item, b: Item): number => a - b, - // MAX: (a: Item, b: Item): number => b - a - // }; + static HeapType = { + MIN: (a: Item, b: Item): number => a - b, + MAX: (a: Item, b: Item): number => b - a + }; /** @private */ _heap: Array;
    57 2018-05-05 15:39:23 (UTC)
    packages/Heap/src/lib/Heap.jsHeap89 %17/194486 byte2462018-05-05 22:16:16 (UTC)
    packages/InsertionSort/src/lib/InsertionSort.js insertionSort