Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

heap-js

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

heap-js - npm Package Compare versions

Comparing version 1.2.2 to 1.3.0

dist/.DS_Store

4

dist/docs/assets/js/search.js

@@ -1,3 +0,3 @@

var typedoc = typedoc || {};
var typedoc = typedoc || {};
typedoc.search = typedoc.search || {};
typedoc.search.data = {"kinds":{"1":"External module","32":"Variable","128":"Class","512":"Constructor","1024":"Property","2048":"Method","65536":"Type literal","262144":"Accessor","4194304":"Type alias"},"rows":[{"id":0,"kind":1,"name":"\"Heap\"","url":"modules/_heap_.html","classes":"tsd-kind-external-module"},{"id":1,"kind":128,"name":"Heap","url":"classes/_heap_.heap.html","classes":"tsd-kind-class tsd-parent-kind-external-module tsd-has-type-parameter","parent":"\"Heap\""},{"id":2,"kind":1024,"name":"heapArray","url":"classes/_heap_.heap.html#heaparray","classes":"tsd-kind-property tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":3,"kind":1024,"name":"compare","url":"classes/_heap_.heap.html#compare","classes":"tsd-kind-property tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":4,"kind":1024,"name":"_limit","url":"classes/_heap_.heap.html#_limit","classes":"tsd-kind-property tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":5,"kind":1024,"name":"offer","url":"classes/_heap_.heap.html#offer","classes":"tsd-kind-property tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":6,"kind":1024,"name":"element","url":"classes/_heap_.heap.html#element","classes":"tsd-kind-property tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":7,"kind":1024,"name":"poll","url":"classes/_heap_.heap.html#poll","classes":"tsd-kind-property tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":8,"kind":512,"name":"constructor","url":"classes/_heap_.heap.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":9,"kind":2048,"name":"getChildrenIndexOf","url":"classes/_heap_.heap.html#getchildrenindexof","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-static","parent":"\"Heap\".Heap"},{"id":10,"kind":2048,"name":"getParentIndexOf","url":"classes/_heap_.heap.html#getparentindexof","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-static","parent":"\"Heap\".Heap"},{"id":11,"kind":2048,"name":"getSiblingIndexOf","url":"classes/_heap_.heap.html#getsiblingindexof","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-static","parent":"\"Heap\".Heap"},{"id":12,"kind":2048,"name":"minComparator","url":"classes/_heap_.heap.html#mincomparator","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-static","parent":"\"Heap\".Heap"},{"id":13,"kind":2048,"name":"maxComparator","url":"classes/_heap_.heap.html#maxcomparator","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-static","parent":"\"Heap\".Heap"},{"id":14,"kind":2048,"name":"defaultIsEqual","url":"classes/_heap_.heap.html#defaultisequal","classes":"tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter tsd-is-static","parent":"\"Heap\".Heap"},{"id":15,"kind":2048,"name":"print","url":"classes/_heap_.heap.html#print","classes":"tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter tsd-is-static","parent":"\"Heap\".Heap"},{"id":16,"kind":2048,"name":"heapify","url":"classes/_heap_.heap.html#heapify","classes":"tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter tsd-is-static","parent":"\"Heap\".Heap"},{"id":17,"kind":2048,"name":"heappop","url":"classes/_heap_.heap.html#heappop","classes":"tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter tsd-is-static","parent":"\"Heap\".Heap"},{"id":18,"kind":2048,"name":"heappush","url":"classes/_heap_.heap.html#heappush","classes":"tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter tsd-is-static","parent":"\"Heap\".Heap"},{"id":19,"kind":2048,"name":"heappushpop","url":"classes/_heap_.heap.html#heappushpop","classes":"tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter tsd-is-static","parent":"\"Heap\".Heap"},{"id":20,"kind":2048,"name":"heapreplace","url":"classes/_heap_.heap.html#heapreplace","classes":"tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter tsd-is-static","parent":"\"Heap\".Heap"},{"id":21,"kind":2048,"name":"heaptop","url":"classes/_heap_.heap.html#heaptop","classes":"tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter tsd-is-static","parent":"\"Heap\".Heap"},{"id":22,"kind":2048,"name":"heapbottom","url":"classes/_heap_.heap.html#heapbottom","classes":"tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter tsd-is-static","parent":"\"Heap\".Heap"},{"id":23,"kind":2048,"name":"add","url":"classes/_heap_.heap.html#add","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":24,"kind":2048,"name":"addAll","url":"classes/_heap_.heap.html#addall","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":25,"kind":2048,"name":"bottom","url":"classes/_heap_.heap.html#bottom","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":26,"kind":2048,"name":"check","url":"classes/_heap_.heap.html#check","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":27,"kind":2048,"name":"clear","url":"classes/_heap_.heap.html#clear","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":28,"kind":2048,"name":"clone","url":"classes/_heap_.heap.html#clone","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":29,"kind":2048,"name":"comparator","url":"classes/_heap_.heap.html#comparator","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":30,"kind":2048,"name":"contains","url":"classes/_heap_.heap.html#contains","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":31,"kind":2048,"name":"init","url":"classes/_heap_.heap.html#init","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":32,"kind":2048,"name":"isEmpty","url":"classes/_heap_.heap.html#isempty","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":33,"kind":2048,"name":"leafs","url":"classes/_heap_.heap.html#leafs","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":34,"kind":262144,"name":"length","url":"classes/_heap_.heap.html#length","classes":"tsd-kind-get-signature tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":35,"kind":262144,"name":"limit","url":"classes/_heap_.heap.html#limit","classes":"tsd-kind-accessor tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":36,"kind":2048,"name":"peek","url":"classes/_heap_.heap.html#peek","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":37,"kind":2048,"name":"pop","url":"classes/_heap_.heap.html#pop","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":38,"kind":2048,"name":"push","url":"classes/_heap_.heap.html#push","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":39,"kind":2048,"name":"pushpop","url":"classes/_heap_.heap.html#pushpop","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":40,"kind":2048,"name":"remove","url":"classes/_heap_.heap.html#remove","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":41,"kind":2048,"name":"replace","url":"classes/_heap_.heap.html#replace","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":42,"kind":2048,"name":"size","url":"classes/_heap_.heap.html#size","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":43,"kind":2048,"name":"top","url":"classes/_heap_.heap.html#top","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":44,"kind":2048,"name":"toArray","url":"classes/_heap_.heap.html#toarray","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":45,"kind":2048,"name":"toString","url":"classes/_heap_.heap.html#tostring","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":46,"kind":2048,"name":"get","url":"classes/_heap_.heap.html#get","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":47,"kind":2048,"name":"getChildrenOf","url":"classes/_heap_.heap.html#getchildrenof","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":48,"kind":2048,"name":"getParentOf","url":"classes/_heap_.heap.html#getparentof","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":49,"kind":2048,"name":"_applyLimit","url":"classes/_heap_.heap.html#_applylimit","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":50,"kind":2048,"name":"_bottomN","url":"classes/_heap_.heap.html#_bottomn","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":51,"kind":2048,"name":"_invertedCompare","url":"classes/_heap_.heap.html#_invertedcompare","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":52,"kind":2048,"name":"_moveNode","url":"classes/_heap_.heap.html#_movenode","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":53,"kind":2048,"name":"_sortNodeDown","url":"classes/_heap_.heap.html#_sortnodedown","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":54,"kind":2048,"name":"_sortNodeUp","url":"classes/_heap_.heap.html#_sortnodeup","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":55,"kind":2048,"name":"_topN","url":"classes/_heap_.heap.html#_topn","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":56,"kind":4194304,"name":"Comparator","url":"modules/_heap_.html#comparator","classes":"tsd-kind-type-alias tsd-parent-kind-external-module","parent":"\"Heap\""},{"id":57,"kind":65536,"name":"__type","url":"modules/_heap_.html#comparator.__type","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias tsd-is-not-exported","parent":"\"Heap\".Comparator"},{"id":58,"kind":4194304,"name":"IsEqual","url":"modules/_heap_.html#isequal","classes":"tsd-kind-type-alias tsd-parent-kind-external-module","parent":"\"Heap\""},{"id":59,"kind":65536,"name":"__type","url":"modules/_heap_.html#isequal.__type-1","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias tsd-is-not-exported","parent":"\"Heap\".IsEqual"},{"id":60,"kind":1,"name":"\"Heap.test\"","url":"modules/_heap_test_.html","classes":"tsd-kind-external-module"},{"id":61,"kind":32,"name":"someValues","url":"modules/_heap_test_.html#somevalues","classes":"tsd-kind-variable tsd-parent-kind-external-module tsd-is-not-exported","parent":"\"Heap.test\""},{"id":62,"kind":32,"name":"otherValues","url":"modules/_heap_test_.html#othervalues","classes":"tsd-kind-variable tsd-parent-kind-external-module tsd-is-not-exported","parent":"\"Heap.test\""}]};
typedoc.search.data = {"kinds":{"1":"External module","32":"Variable","128":"Class","512":"Constructor","1024":"Property","2048":"Method","65536":"Type literal","262144":"Accessor","4194304":"Type alias"},"rows":[{"id":0,"kind":1,"name":"\"Heap\"","url":"modules/_heap_.html","classes":"tsd-kind-external-module"},{"id":1,"kind":128,"name":"Heap","url":"classes/_heap_.heap.html","classes":"tsd-kind-class tsd-parent-kind-external-module tsd-has-type-parameter","parent":"\"Heap\""},{"id":2,"kind":1024,"name":"heapArray","url":"classes/_heap_.heap.html#heaparray","classes":"tsd-kind-property tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":3,"kind":1024,"name":"_limit","url":"classes/_heap_.heap.html#_limit","classes":"tsd-kind-property tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":4,"kind":1024,"name":"offer","url":"classes/_heap_.heap.html#offer","classes":"tsd-kind-property tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":5,"kind":1024,"name":"element","url":"classes/_heap_.heap.html#element","classes":"tsd-kind-property tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":6,"kind":1024,"name":"poll","url":"classes/_heap_.heap.html#poll","classes":"tsd-kind-property tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":7,"kind":512,"name":"constructor","url":"classes/_heap_.heap.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":8,"kind":1024,"name":"compare","url":"classes/_heap_.heap.html#compare","classes":"tsd-kind-property tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":9,"kind":2048,"name":"getChildrenIndexOf","url":"classes/_heap_.heap.html#getchildrenindexof","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-static","parent":"\"Heap\".Heap"},{"id":10,"kind":2048,"name":"getParentIndexOf","url":"classes/_heap_.heap.html#getparentindexof","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-static","parent":"\"Heap\".Heap"},{"id":11,"kind":2048,"name":"getSiblingIndexOf","url":"classes/_heap_.heap.html#getsiblingindexof","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-static","parent":"\"Heap\".Heap"},{"id":12,"kind":2048,"name":"minComparator","url":"classes/_heap_.heap.html#mincomparator","classes":"tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter tsd-is-static","parent":"\"Heap\".Heap"},{"id":13,"kind":2048,"name":"maxComparator","url":"classes/_heap_.heap.html#maxcomparator","classes":"tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter tsd-is-static","parent":"\"Heap\".Heap"},{"id":14,"kind":2048,"name":"minComparatorNumber","url":"classes/_heap_.heap.html#mincomparatornumber","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-static","parent":"\"Heap\".Heap"},{"id":15,"kind":2048,"name":"maxComparatorNumber","url":"classes/_heap_.heap.html#maxcomparatornumber","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-static","parent":"\"Heap\".Heap"},{"id":16,"kind":2048,"name":"defaultIsEqual","url":"classes/_heap_.heap.html#defaultisequal","classes":"tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter tsd-is-static","parent":"\"Heap\".Heap"},{"id":17,"kind":2048,"name":"print","url":"classes/_heap_.heap.html#print","classes":"tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter tsd-is-static","parent":"\"Heap\".Heap"},{"id":18,"kind":2048,"name":"heapify","url":"classes/_heap_.heap.html#heapify","classes":"tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter tsd-is-static","parent":"\"Heap\".Heap"},{"id":19,"kind":2048,"name":"heappop","url":"classes/_heap_.heap.html#heappop","classes":"tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter tsd-is-static","parent":"\"Heap\".Heap"},{"id":20,"kind":2048,"name":"heappush","url":"classes/_heap_.heap.html#heappush","classes":"tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter tsd-is-static","parent":"\"Heap\".Heap"},{"id":21,"kind":2048,"name":"heappushpop","url":"classes/_heap_.heap.html#heappushpop","classes":"tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter tsd-is-static","parent":"\"Heap\".Heap"},{"id":22,"kind":2048,"name":"heapreplace","url":"classes/_heap_.heap.html#heapreplace","classes":"tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter tsd-is-static","parent":"\"Heap\".Heap"},{"id":23,"kind":2048,"name":"heaptop","url":"classes/_heap_.heap.html#heaptop","classes":"tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter tsd-is-static","parent":"\"Heap\".Heap"},{"id":24,"kind":2048,"name":"heapbottom","url":"classes/_heap_.heap.html#heapbottom","classes":"tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter tsd-is-static","parent":"\"Heap\".Heap"},{"id":25,"kind":2048,"name":"add","url":"classes/_heap_.heap.html#add","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":26,"kind":2048,"name":"addAll","url":"classes/_heap_.heap.html#addall","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":27,"kind":2048,"name":"bottom","url":"classes/_heap_.heap.html#bottom","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":28,"kind":2048,"name":"check","url":"classes/_heap_.heap.html#check","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":29,"kind":2048,"name":"clear","url":"classes/_heap_.heap.html#clear","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":30,"kind":2048,"name":"clone","url":"classes/_heap_.heap.html#clone","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":31,"kind":2048,"name":"comparator","url":"classes/_heap_.heap.html#comparator","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":32,"kind":2048,"name":"contains","url":"classes/_heap_.heap.html#contains","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":33,"kind":2048,"name":"init","url":"classes/_heap_.heap.html#init","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":34,"kind":2048,"name":"isEmpty","url":"classes/_heap_.heap.html#isempty","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":35,"kind":2048,"name":"leafs","url":"classes/_heap_.heap.html#leafs","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":36,"kind":262144,"name":"length","url":"classes/_heap_.heap.html#length","classes":"tsd-kind-get-signature tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":37,"kind":262144,"name":"limit","url":"classes/_heap_.heap.html#limit","classes":"tsd-kind-accessor tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":38,"kind":2048,"name":"peek","url":"classes/_heap_.heap.html#peek","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":39,"kind":2048,"name":"pop","url":"classes/_heap_.heap.html#pop","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":40,"kind":2048,"name":"push","url":"classes/_heap_.heap.html#push","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":41,"kind":2048,"name":"pushpop","url":"classes/_heap_.heap.html#pushpop","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":42,"kind":2048,"name":"remove","url":"classes/_heap_.heap.html#remove","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":43,"kind":2048,"name":"replace","url":"classes/_heap_.heap.html#replace","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":44,"kind":2048,"name":"size","url":"classes/_heap_.heap.html#size","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":45,"kind":2048,"name":"top","url":"classes/_heap_.heap.html#top","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":46,"kind":2048,"name":"toArray","url":"classes/_heap_.heap.html#toarray","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":47,"kind":2048,"name":"toString","url":"classes/_heap_.heap.html#tostring","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":48,"kind":2048,"name":"get","url":"classes/_heap_.heap.html#get","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":49,"kind":2048,"name":"getChildrenOf","url":"classes/_heap_.heap.html#getchildrenof","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":50,"kind":2048,"name":"getParentOf","url":"classes/_heap_.heap.html#getparentof","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":51,"kind":2048,"name":"_applyLimit","url":"classes/_heap_.heap.html#_applylimit","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":52,"kind":2048,"name":"_bottomN","url":"classes/_heap_.heap.html#_bottomn","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":53,"kind":2048,"name":"_invertedCompare","url":"classes/_heap_.heap.html#_invertedcompare","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":54,"kind":2048,"name":"_moveNode","url":"classes/_heap_.heap.html#_movenode","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":55,"kind":2048,"name":"_sortNodeDown","url":"classes/_heap_.heap.html#_sortnodedown","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":56,"kind":2048,"name":"_sortNodeUp","url":"classes/_heap_.heap.html#_sortnodeup","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":57,"kind":2048,"name":"_topN","url":"classes/_heap_.heap.html#_topn","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"Heap\".Heap"},{"id":58,"kind":4194304,"name":"Comparator","url":"modules/_heap_.html#comparator","classes":"tsd-kind-type-alias tsd-parent-kind-external-module tsd-has-type-parameter","parent":"\"Heap\""},{"id":59,"kind":65536,"name":"__type","url":"modules/_heap_.html#comparator.__type","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias tsd-is-not-exported","parent":"\"Heap\".Comparator"},{"id":60,"kind":4194304,"name":"IsEqual","url":"modules/_heap_.html#isequal","classes":"tsd-kind-type-alias tsd-parent-kind-external-module tsd-has-type-parameter","parent":"\"Heap\""},{"id":61,"kind":65536,"name":"__type","url":"modules/_heap_.html#isequal.__type-1","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias tsd-is-not-exported","parent":"\"Heap\".IsEqual"},{"id":62,"kind":1,"name":"\"Heap.test\"","url":"modules/_heap_test_.html","classes":"tsd-kind-external-module"},{"id":63,"kind":32,"name":"someValues","url":"modules/_heap_test_.html#somevalues","classes":"tsd-kind-variable tsd-parent-kind-external-module tsd-is-not-exported","parent":"\"Heap.test\""},{"id":64,"kind":32,"name":"otherValues","url":"modules/_heap_test_.html#othervalues","classes":"tsd-kind-variable tsd-parent-kind-external-module tsd-is-not-exported","parent":"\"Heap.test\""}]};

@@ -5,3 +5,3 @@ /**

*/
var Heap = (function () {
var Heap = /** @class */ (function () {
/**

@@ -12,6 +12,7 @@ * Heap instance constructor.

function Heap(compare) {
var _this = this;
if (compare === void 0) { compare = Heap.minComparator; }
var _this = this;
this.compare = compare;
this.heapArray = [];
this._limit = null;
this._limit = 0;
/**

@@ -36,3 +37,2 @@ * Alias of add

};
this.compare = compare;
}

@@ -81,3 +81,11 @@ /*

Heap.minComparator = function (a, b) {
return a - b;
if (a > b) {
return 1;
}
else if (a < b) {
return -1;
}
else {
return 0;
}
};

@@ -91,2 +99,28 @@ /**

Heap.maxComparator = function (a, b) {
if (b > a) {
return 1;
}
else if (b < a) {
return -1;
}
else {
return 0;
}
};
/**
* Min number heap comparison function, default.
* @param {Number} a First element
* @param {Number} b Second element
* @return {Number} 0 if they're equal, positive if `a` goes up, negative if `b` goes up
*/
Heap.minComparatorNumber = function (a, b) {
return a - b;
};
/**
* Max number heap comparison function.
* @param {Number} a First element
* @param {Number} b Second element
* @return {Number} 0 if they're equal, positive if `a` goes up, negative if `b` goes up
*/
Heap.maxComparatorNumber = function (a, b) {
return b - a;

@@ -114,3 +148,3 @@ };

function repeat(str, times) {
var out = "";
var out = '';
for (; times > 0; --times) {

@@ -143,3 +177,3 @@ out += str;

var times = Math.pow(2, maxLines - i) - 1;
return (repeat(" ", Math.floor(times / 2) * maxLength) +
return (repeat(' ', Math.floor(times / 2) * maxLength) +
line

@@ -149,9 +183,7 @@ .map(function (el) {

var half = (maxLength - el.length) / 2;
return (repeat(" ", Math.ceil(half)) +
el +
repeat(" ", Math.floor(half)));
return repeat(' ', Math.ceil(half)) + el + repeat(' ', Math.floor(half));
})
.join(repeat(" ", times * maxLength)));
.join(repeat(' ', times * maxLength)));
})
.join("\n");
.join('\n');
};

@@ -266,2 +298,3 @@ /*

Heap.prototype.addAll = function (elements) {
var _a;
var i = this.length;

@@ -274,3 +307,2 @@ (_a = this.heapArray).push.apply(_a, elements);

return true;
var _a;
};

@@ -313,5 +345,3 @@ /**

var _this = this;
return this.heapArray.find(function (el, j, arr) {
return !!_this.getChildrenOf(j).find(function (ch) { return _this.compare(el, ch) > 0; });
});
return this.heapArray.find(function (el, j, arr) { return !!_this.getChildrenOf(j).find(function (ch) { return _this.compare(el, ch) > 0; }); });
};

@@ -456,4 +486,4 @@ /**

Heap.prototype.pushpop = function (element) {
var _a;
if (this.compare(this.heapArray[0], element) < 0) {
_a = [this.heapArray[0], element], element = _a[0], this.heapArray[0] = _a[1];

@@ -463,3 +493,2 @@ this._sortNodeDown(0);

return element;
var _a;
};

@@ -637,8 +666,4 @@ /**

Heap.prototype._moveNode = function (j, k) {
_a = [
this.heapArray[k],
this.heapArray[j]
], this.heapArray[j] = _a[0], this.heapArray[k] = _a[1];
var _a;
_a = [this.heapArray[k], this.heapArray[j]], this.heapArray[j] = _a[0], this.heapArray[k] = _a[1];
};

@@ -664,4 +689,3 @@ /**

var bestChild = this.heapArray[bestChildIndex];
if (typeof bestChild !== "undefined" &&
this.compare(self, bestChild) > 0) {
if (typeof bestChild !== 'undefined' && this.compare(self, bestChild) > 0) {
this._moveNode(i, bestChildIndex);

@@ -727,3 +751,3 @@ i = bestChildIndex;

export { Heap };export default Heap;
//# sourceMappingURL=heap-js.es5.js.map
export default Heap;
export { Heap };
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.heap = global.heap || {})));
}(this, (function (exports) { 'use strict';
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = global || self, factory(global.heap = {}));
}(this, function (exports) { 'use strict';
/**
* Heap
* @type {Class}
*/
var Heap = (function () {
/**
* Heap instance constructor.
* @param {Function} compare Optional comparison function, defaults to Heap.minComparator<number>
* Heap
* @type {Class}
*/
function Heap(compare) {
if (compare === void 0) { compare = Heap.minComparator; }
var _this = this;
this.heapArray = [];
this._limit = null;
var Heap = /** @class */ (function () {
/**
* Alias of add
* Heap instance constructor.
* @param {Function} compare Optional comparison function, defaults to Heap.minComparator<number>
*/
this.offer = this.add;
function Heap(compare) {
var _this = this;
if (compare === void 0) { compare = Heap.minComparator; }
this.compare = compare;
this.heapArray = [];
this._limit = 0;
/**
* Alias of add
*/
this.offer = this.add;
/**
* Alias of peek
*/
this.element = this.peek;
/**
* Alias of pop
*/
this.poll = this.pop;
/**
* Returns the inverse to the comparison function.
* @return {Function}
*/
this._invertedCompare = function (a, b) {
return -1 * _this.compare(a, b);
};
}
/*
Static methods
*/
/**
* Alias of peek
* Gets children indices for given index.
* @param {Number} idx Parent index
* @return {Array(Number)} Array of children indices
*/
this.element = this.peek;
Heap.getChildrenIndexOf = function (idx) {
return [idx * 2 + 1, idx * 2 + 2];
};
/**
* Alias of pop
* Gets parent index for given index.
* @param {Number} idx Children index
* @return {Number | undefined} Parent index, -1 if idx is 0
*/
this.poll = this.pop;
Heap.getParentIndexOf = function (idx) {
if (idx <= 0) {
return -1;
}
var whichChildren = idx % 2 ? 1 : 2;
return Math.floor((idx - whichChildren) / 2);
};
/**
* Returns the inverse to the comparison function.
* @return {Function}
* Gets sibling index for given index.
* @param {Number} idx Children index
* @return {Number | undefined} Sibling index, -1 if idx is 0
*/
this._invertedCompare = function (a, b) {
return -1 * _this.compare(a, b);
Heap.getSiblingIndexOf = function (idx) {
if (idx <= 0) {
return -1;
}
var whichChildren = idx % 2 ? 1 : -1;
return idx + whichChildren;
};
this.compare = compare;
}
/*
Static methods
*/
/**
* Gets children indices for given index.
* @param {Number} idx Parent index
* @return {Array(Number)} Array of children indices
*/
Heap.getChildrenIndexOf = function (idx) {
return [idx * 2 + 1, idx * 2 + 2];
};
/**
* Gets parent index for given index.
* @param {Number} idx Children index
* @return {Number | undefined} Parent index, -1 if idx is 0
*/
Heap.getParentIndexOf = function (idx) {
if (idx <= 0) {
return -1;
}
var whichChildren = idx % 2 ? 1 : 2;
return Math.floor((idx - whichChildren) / 2);
};
/**
* Gets sibling index for given index.
* @param {Number} idx Children index
* @return {Number | undefined} Sibling index, -1 if idx is 0
*/
Heap.getSiblingIndexOf = function (idx) {
if (idx <= 0) {
return -1;
}
var whichChildren = idx % 2 ? 1 : -1;
return idx + whichChildren;
};
/**
* Min heap comparison function, default.
* @param {any} a First element
* @param {any} b Second element
* @return {Number} 0 if they're equal, positive if `a` goes up, negative if `b` goes up
*/
Heap.minComparator = function (a, b) {
return a - b;
};
/**
* Max heap comparison function.
* @param {any} a First element
* @param {any} b Second element
* @return {Number} 0 if they're equal, positive if `a` goes up, negative if `b` goes up
*/
Heap.maxComparator = function (a, b) {
return b - a;
};
/**
* Default equality function.
* @param {any} a First element
* @param {any} b Second element
* @return {Boolean} True if equal, false otherwise
*/
Heap.defaultIsEqual = function (a, b) {
return a === b;
};
/**
* Prints a heap.
* @param {Heap} heap Heap to be printed
* @returns {String}
*/
Heap.print = function (heap) {
function deep(i) {
var pi = Heap.getParentIndexOf(i);
return Math.floor(Math.log2(pi + 1));
}
function repeat(str, times) {
var out = "";
for (; times > 0; --times) {
out += str;
/**
* Min heap comparison function, default.
* @param {any} a First element
* @param {any} b Second element
* @return {Number} 0 if they're equal, positive if `a` goes up, negative if `b` goes up
*/
Heap.minComparator = function (a, b) {
if (a > b) {
return 1;
}
return out;
}
var node = 0;
var lines = [];
var maxLines = deep(heap.length - 1) + 2;
var maxLength = 0;
while (node < heap.length) {
var i = deep(node) + 1;
if (node === 0) {
i = 0;
else if (a < b) {
return -1;
}
// Text representation
var nodeText = heap.get(node).toString();
if (nodeText.length > maxLength) {
maxLength = nodeText.length;
else {
return 0;
}
// Add to line
lines[i] = lines[i] || [];
lines[i].push(nodeText);
node += 1;
}
return lines
.map(function (line, i) {
var times = Math.pow(2, maxLines - i) - 1;
return (repeat(" ", Math.floor(times / 2) * maxLength) +
line
.map(function (el) {
// centered
var half = (maxLength - el.length) / 2;
return (repeat(" ", Math.ceil(half)) +
el +
repeat(" ", Math.floor(half)));
})
.join(repeat(" ", times * maxLength)));
})
.join("\n");
};
/*
Python style
*/
/**
* Converts an array into an array-heap
* @param {Array} arr Array to be modified
* @param {Function} compare Optional compare function
* @return {Heap} For convenience, it returns a Heap instance
*/
Heap.heapify = function (arr, compare) {
var heap = new Heap(compare);
heap.heapArray = arr;
heap.init();
return heap;
};
/**
* Extract the peek of an array-heap
* @param {Array} heapArr Array to be modified, should be a heap
* @param {Function} compare Optional compare function
* @return {any} Returns the extracted peek
*/
Heap.heappop = function (heapArr, compare) {
var heap = new Heap(compare);
heap.heapArray = heapArr;
return heap.pop();
};
/**
* Pushes a item into an array-heap
* @param {Array} heapArr Array to be modified, should be a heap
* @param {any} item Item to push
* @param {Function} compare Optional compare function
*/
Heap.heappush = function (heapArr, item, compare) {
var heap = new Heap(compare);
heap.heapArray = heapArr;
heap.push(item);
};
/**
* Push followed by pop, faster
* @param {Array} heapArr Array to be modified, should be a heap
* @param {any} item Item to push
* @param {Function} compare Optional compare function
* @return {any} Returns the extracted peek
*/
Heap.heappushpop = function (heapArr, item, compare) {
var heap = new Heap(compare);
heap.heapArray = heapArr;
return heap.pushpop(item);
};
/**
* Replace peek with item
* @param {Array} heapArr Array to be modified, should be a heap
* @param {any} item Item as replacement
* @param {Function} compare Optional compare function
* @return {any} Returns the extracted peek
*/
Heap.heapreplace = function (heapArr, item, compare) {
var heap = new Heap(compare);
heap.heapArray = heapArr;
return heap.replace(item);
};
/**
* Return the `n` most valuable elements
* @param {Array} heapArr Array, should be a heap
* @param {number} n Max number of elements
* @param {Function} compare Optional compare function
* @return {any} Elements
*/
Heap.heaptop = function (heapArr, n, compare) {
if (n === void 0) { n = 1; }
var heap = new Heap(compare);
heap.heapArray = heapArr;
return heap.top(n);
};
/**
* Return the `n` least valuable elements
* @param {Array} heapArr Array, should be a heap
* @param {number} n Max number of elements
* @param {Function} compare Optional compare function
* @return {any} Elements
*/
Heap.heapbottom = function (heapArr, n, compare) {
if (n === void 0) { n = 1; }
var heap = new Heap(compare);
heap.heapArray = heapArr;
return heap.bottom(n);
};
/*
Instance methods
*/
/**
* Adds an element to the heap. Aliases: `offer`.
* Same as: push(element)
* @param {any} element Element to be added
* @return {Boolean} true
*/
Heap.prototype.add = function (element) {
this._sortNodeUp(this.heapArray.push(element) - 1);
this._applyLimit();
return true;
};
/**
* Adds an array of elements to the heap.
* Similar as: push(element, element, ...).
* @param {Array} elements Elements to be added
* @return {Boolean} true
*/
Heap.prototype.addAll = function (elements) {
var i = this.length;
(_a = this.heapArray).push.apply(_a, elements);
for (var l = this.length; i < l; ++i) {
this._sortNodeUp(i);
}
this._applyLimit();
return true;
var _a;
};
/**
* Return the bottom (lowest value) N elements of the heap.
*
* @param {Number} n Number of elements.
* @return {Array} Array of length <= N.
*/
Heap.prototype.bottom = function (n) {
if (n === void 0) { n = 1; }
if (this.heapArray.length === 0 || n <= 0) {
// Nothing to do
return [];
}
else if (this.heapArray.length === 1) {
// Just the peek
return [this.heapArray[0]];
}
else if (n >= this.heapArray.length) {
// The whole peek
// Clone is needed due to the sort method (in-place) that would destroy the heap
var cloned = this.heapArray.slice(0);
cloned.sort(this._invertedCompare);
return cloned;
}
else {
// Some elements
var result = this._bottomN(n);
result.sort(this._invertedCompare);
return result;
}
};
/**
* Check if the heap is sorted, useful for testing purposes.
* @return {Undefined | Element} Returns an element if something wrong is found, otherwise it's undefined
*/
Heap.prototype.check = function () {
var _this = this;
return this.heapArray.find(function (el, j, arr) {
return !!_this.getChildrenOf(j).find(function (ch) { return _this.compare(el, ch) > 0; });
});
};
/**
* Remove all of the elements from this heap.
*/
Heap.prototype.clear = function () {
this.heapArray = [];
};
/**
* Clone this heap
* @return {Heap}
*/
Heap.prototype.clone = function () {
var cloned = new Heap(this.comparator());
cloned.heapArray = this.toArray();
cloned._limit = this._limit;
return cloned;
};
/**
* Returns the comparison function.
* @return {Function}
*/
Heap.prototype.comparator = function () {
return this.compare;
};
/**
* Returns true if this queue contains the specified element.
* @param {any} o Element to be found
* @param {Function} fn Optional comparison function, receives (element, needle)
* @return {Boolean}
*/
Heap.prototype.contains = function (o, fn) {
if (fn === void 0) { fn = Heap.defaultIsEqual; }
return this.heapArray.findIndex(function (el) { return fn(el, o); }) >= 0;
};
/**
* Initialise a heap, sorting nodes
* @param {Array} array Optional initial state array
*/
Heap.prototype.init = function (array) {
if (array) {
this.heapArray = array.slice(0);
}
for (var i = Math.floor(this.heapArray.length); i >= 0; --i) {
this._sortNodeDown(i);
}
this._applyLimit();
};
/**
* Test if the heap has no elements.
* @return {Boolean} True if no elements on the heap
*/
Heap.prototype.isEmpty = function () {
return this.length === 0;
};
/**
* Get the leafs of the tree (no children nodes)
*/
Heap.prototype.leafs = function () {
if (this.heapArray.length === 0) {
return [];
}
var pi = Heap.getParentIndexOf(this.heapArray.length - 1);
return this.heapArray.slice(pi + 1);
};
Object.defineProperty(Heap.prototype, "length", {
};
/**
* Length of the heap.
* @return {Number}
* Max heap comparison function.
* @param {any} a First element
* @param {any} b Second element
* @return {Number} 0 if they're equal, positive if `a` goes up, negative if `b` goes up
*/
get: function () {
return this.heapArray.length;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Heap.prototype, "limit", {
Heap.maxComparator = function (a, b) {
if (b > a) {
return 1;
}
else if (b < a) {
return -1;
}
else {
return 0;
}
};
/**
* Get length limit of the heap.
* @return {Number}
* Min number heap comparison function, default.
* @param {Number} a First element
* @param {Number} b Second element
* @return {Number} 0 if they're equal, positive if `a` goes up, negative if `b` goes up
*/
get: function () {
return this._limit;
},
Heap.minComparatorNumber = function (a, b) {
return a - b;
};
/**
* Set length limit of the heap.
* @return {Number}
* Max number heap comparison function.
* @param {Number} a First element
* @param {Number} b Second element
* @return {Number} 0 if they're equal, positive if `a` goes up, negative if `b` goes up
*/
set: function (_l) {
this._limit = _l;
Heap.maxComparatorNumber = function (a, b) {
return b - a;
};
/**
* Default equality function.
* @param {any} a First element
* @param {any} b Second element
* @return {Boolean} True if equal, false otherwise
*/
Heap.defaultIsEqual = function (a, b) {
return a === b;
};
/**
* Prints a heap.
* @param {Heap} heap Heap to be printed
* @returns {String}
*/
Heap.print = function (heap) {
function deep(i) {
var pi = Heap.getParentIndexOf(i);
return Math.floor(Math.log2(pi + 1));
}
function repeat(str, times) {
var out = '';
for (; times > 0; --times) {
out += str;
}
return out;
}
var node = 0;
var lines = [];
var maxLines = deep(heap.length - 1) + 2;
var maxLength = 0;
while (node < heap.length) {
var i = deep(node) + 1;
if (node === 0) {
i = 0;
}
// Text representation
var nodeText = heap.get(node).toString();
if (nodeText.length > maxLength) {
maxLength = nodeText.length;
}
// Add to line
lines[i] = lines[i] || [];
lines[i].push(nodeText);
node += 1;
}
return lines
.map(function (line, i) {
var times = Math.pow(2, maxLines - i) - 1;
return (repeat(' ', Math.floor(times / 2) * maxLength) +
line
.map(function (el) {
// centered
var half = (maxLength - el.length) / 2;
return repeat(' ', Math.ceil(half)) + el + repeat(' ', Math.floor(half));
})
.join(repeat(' ', times * maxLength)));
})
.join('\n');
};
/*
Python style
*/
/**
* Converts an array into an array-heap
* @param {Array} arr Array to be modified
* @param {Function} compare Optional compare function
* @return {Heap} For convenience, it returns a Heap instance
*/
Heap.heapify = function (arr, compare) {
var heap = new Heap(compare);
heap.heapArray = arr;
heap.init();
return heap;
};
/**
* Extract the peek of an array-heap
* @param {Array} heapArr Array to be modified, should be a heap
* @param {Function} compare Optional compare function
* @return {any} Returns the extracted peek
*/
Heap.heappop = function (heapArr, compare) {
var heap = new Heap(compare);
heap.heapArray = heapArr;
return heap.pop();
};
/**
* Pushes a item into an array-heap
* @param {Array} heapArr Array to be modified, should be a heap
* @param {any} item Item to push
* @param {Function} compare Optional compare function
*/
Heap.heappush = function (heapArr, item, compare) {
var heap = new Heap(compare);
heap.heapArray = heapArr;
heap.push(item);
};
/**
* Push followed by pop, faster
* @param {Array} heapArr Array to be modified, should be a heap
* @param {any} item Item to push
* @param {Function} compare Optional compare function
* @return {any} Returns the extracted peek
*/
Heap.heappushpop = function (heapArr, item, compare) {
var heap = new Heap(compare);
heap.heapArray = heapArr;
return heap.pushpop(item);
};
/**
* Replace peek with item
* @param {Array} heapArr Array to be modified, should be a heap
* @param {any} item Item as replacement
* @param {Function} compare Optional compare function
* @return {any} Returns the extracted peek
*/
Heap.heapreplace = function (heapArr, item, compare) {
var heap = new Heap(compare);
heap.heapArray = heapArr;
return heap.replace(item);
};
/**
* Return the `n` most valuable elements
* @param {Array} heapArr Array, should be a heap
* @param {number} n Max number of elements
* @param {Function} compare Optional compare function
* @return {any} Elements
*/
Heap.heaptop = function (heapArr, n, compare) {
if (n === void 0) { n = 1; }
var heap = new Heap(compare);
heap.heapArray = heapArr;
return heap.top(n);
};
/**
* Return the `n` least valuable elements
* @param {Array} heapArr Array, should be a heap
* @param {number} n Max number of elements
* @param {Function} compare Optional compare function
* @return {any} Elements
*/
Heap.heapbottom = function (heapArr, n, compare) {
if (n === void 0) { n = 1; }
var heap = new Heap(compare);
heap.heapArray = heapArr;
return heap.bottom(n);
};
/*
Instance methods
*/
/**
* Adds an element to the heap. Aliases: `offer`.
* Same as: push(element)
* @param {any} element Element to be added
* @return {Boolean} true
*/
Heap.prototype.add = function (element) {
this._sortNodeUp(this.heapArray.push(element) - 1);
this._applyLimit();
},
enumerable: true,
configurable: true
});
/**
* Top node. Aliases: `element`.
* Same as: `top(1)[0]`
* @return {any} Top node
*/
Heap.prototype.peek = function () {
return this.heapArray[0];
};
/**
* Extract the top node (root). Aliases: `poll`.
* @return {any} Extracted top node, undefined if empty
*/
Heap.prototype.pop = function () {
var pop = this.heapArray.pop();
if (this.length > 0 && pop !== undefined) {
return this.replace(pop);
}
return pop;
};
/**
* Pushes element(s) to the heap.
* @param {...any} elements Elements to insert
* @return {Boolean} True if elements are present
*/
Heap.prototype.push = function () {
var elements = [];
for (var _i = 0; _i < arguments.length; _i++) {
elements[_i] = arguments[_i];
}
if (elements.length < 1) {
return false;
}
else if (elements.length === 1) {
return this.add(elements[0]);
}
else {
return this.addAll(elements);
}
};
/**
* Same as push & pop in sequence, but faster
* @param {any} element Element to insert
* @return {any} Extracted top node
*/
Heap.prototype.pushpop = function (element) {
if (this.compare(this.heapArray[0], element) < 0) {
_a = [this.heapArray[0], element], element = _a[0], this.heapArray[0] = _a[1];
this._sortNodeDown(0);
}
return element;
var _a;
};
/**
* Remove an element from the heap.
* @param {any} o Element to be found
* @param {Function} fn Optional function to compare
* @return {Boolean} True if the heap was modified
*/
Heap.prototype.remove = function (o, fn) {
if (fn === void 0) { fn = Heap.defaultIsEqual; }
if (this.length > 0) {
if (o === undefined) {
this.pop();
return true;
return true;
};
/**
* Adds an array of elements to the heap.
* Similar as: push(element, element, ...).
* @param {Array} elements Elements to be added
* @return {Boolean} true
*/
Heap.prototype.addAll = function (elements) {
var _a;
var i = this.length;
(_a = this.heapArray).push.apply(_a, elements);
for (var l = this.length; i < l; ++i) {
this._sortNodeUp(i);
}
this._applyLimit();
return true;
};
/**
* Return the bottom (lowest value) N elements of the heap.
*
* @param {Number} n Number of elements.
* @return {Array} Array of length <= N.
*/
Heap.prototype.bottom = function (n) {
if (n === void 0) { n = 1; }
if (this.heapArray.length === 0 || n <= 0) {
// Nothing to do
return [];
}
else if (this.heapArray.length === 1) {
// Just the peek
return [this.heapArray[0]];
}
else if (n >= this.heapArray.length) {
// The whole peek
// Clone is needed due to the sort method (in-place) that would destroy the heap
var cloned = this.heapArray.slice(0);
cloned.sort(this._invertedCompare);
return cloned;
}
else {
var idx = this.heapArray.findIndex(function (el) { return fn(el, o); });
if (idx >= 0) {
if (idx === 0) {
this.pop();
}
else if (idx === this.length - 1) {
this.heapArray.pop();
}
else {
this.heapArray.splice(idx, 1, this.heapArray.pop());
this._sortNodeUp(idx);
this._sortNodeDown(idx);
}
return true;
}
// Some elements
var result = this._bottomN(n);
result.sort(this._invertedCompare);
return result;
}
}
return false;
};
/**
* Pop the current peek value, and add the new item.
* @param {any} element Element to replace peek
* @return {any} Old peek
*/
Heap.prototype.replace = function (element) {
var peek = this.heapArray[0];
this.heapArray[0] = element;
this._sortNodeDown(0);
return peek;
};
/**
* Size of the heap
* @return {Number}
*/
Heap.prototype.size = function () {
return this.length;
};
/**
* Return the top (highest value) N elements of the heap.
*
* @param {Number} n Number of elements.
* @return {Array} Array of length <= N.
*/
Heap.prototype.top = function (n) {
if (n === void 0) { n = 1; }
if (this.heapArray.length === 0 || n <= 0) {
// Nothing to do
return [];
}
else if (this.heapArray.length === 1 || n === 1) {
// Just the peek
return [this.heapArray[0]];
}
else if (n >= this.heapArray.length) {
// The whole peek
// Clone is needed due to the sort method (in-place) that would destroy the heap
var cloned = this.heapArray.slice(0);
cloned.sort(this.compare);
};
/**
* Check if the heap is sorted, useful for testing purposes.
* @return {Undefined | Element} Returns an element if something wrong is found, otherwise it's undefined
*/
Heap.prototype.check = function () {
var _this = this;
return this.heapArray.find(function (el, j, arr) { return !!_this.getChildrenOf(j).find(function (ch) { return _this.compare(el, ch) > 0; }); });
};
/**
* Remove all of the elements from this heap.
*/
Heap.prototype.clear = function () {
this.heapArray = [];
};
/**
* Clone this heap
* @return {Heap}
*/
Heap.prototype.clone = function () {
var cloned = new Heap(this.comparator());
cloned.heapArray = this.toArray();
cloned._limit = this._limit;
return cloned;
}
else {
// Some elements
var result = this._topN(n);
result.sort(this.compare);
return result;
}
};
/**
* Clone the heap's internal array
* @return {Array}
*/
Heap.prototype.toArray = function () {
return this.heapArray.slice(0);
};
/**
* String output, call to Array.prototype.toString()
* @return {String}
*/
Heap.prototype.toString = function () {
return this.heapArray.toString();
};
/**
* Get the element at the given index.
* @param {Number} i Index to get
* @return {any} Element at that index
*/
Heap.prototype.get = function (i) {
return this.heapArray[i];
};
/**
* Get the elements of these node's children
* @param {Number} idx Node index
* @return {Array(any)} Children elements
*/
Heap.prototype.getChildrenOf = function (idx) {
var _this = this;
return Heap.getChildrenIndexOf(idx)
.map(function (i) { return _this.heapArray[i]; })
.filter(function (e) { return e !== undefined; });
};
/**
* Get the element of this node's parent
* @param {Number} idx Node index
* @return {any} Parent element
*/
Heap.prototype.getParentOf = function (idx) {
var pi = Heap.getParentIndexOf(idx);
return this.heapArray[pi];
};
/**
* Limit heap size if needed
*/
Heap.prototype._applyLimit = function () {
if (this._limit && this._limit < this.heapArray.length) {
var rm = this.heapArray.length - this._limit;
// It's much faster than splice
while (rm) {
this.heapArray.pop();
--rm;
};
/**
* Returns the comparison function.
* @return {Function}
*/
Heap.prototype.comparator = function () {
return this.compare;
};
/**
* Returns true if this queue contains the specified element.
* @param {any} o Element to be found
* @param {Function} fn Optional comparison function, receives (element, needle)
* @return {Boolean}
*/
Heap.prototype.contains = function (o, fn) {
if (fn === void 0) { fn = Heap.defaultIsEqual; }
return this.heapArray.findIndex(function (el) { return fn(el, o); }) >= 0;
};
/**
* Initialise a heap, sorting nodes
* @param {Array} array Optional initial state array
*/
Heap.prototype.init = function (array) {
if (array) {
this.heapArray = array.slice(0);
}
}
};
/**
* Return the bottom (lowest value) N elements of the heap, without corner cases, unsorted
*
* @param {Number} n Number of elements.
* @return {Array} Array of length <= N.
*/
Heap.prototype._bottomN = function (n) {
// Use an inverted heap
var bottomHeap = new Heap(this.compare);
bottomHeap.limit = n;
bottomHeap.init(this.heapArray.slice(-n));
var startAt = this.heapArray.length - 1 - n;
var parentStartAt = Heap.getParentIndexOf(startAt);
var indices = [];
for (var i = startAt; i > parentStartAt; --i) {
indices.push(i);
}
var arr = this.heapArray;
while (indices.length) {
var i = indices.shift();
if (this.compare(arr[i], bottomHeap.peek()) > 0) {
bottomHeap.replace(arr[i]);
if (i % 2) {
indices.push(Heap.getParentIndexOf(i));
}
for (var i = Math.floor(this.heapArray.length); i >= 0; --i) {
this._sortNodeDown(i);
}
}
return bottomHeap.toArray();
};
/**
* Move a node to a new index, switching places
* @param {Number} j First node index
* @param {Number} k Another node index
*/
Heap.prototype._moveNode = function (j, k) {
_a = [
this.heapArray[k],
this.heapArray[j]
], this.heapArray[j] = _a[0], this.heapArray[k] = _a[1];
var _a;
};
/**
* Move a node down the tree (to the leaves) to find a place where the heap is sorted.
* @param {Number} i Index of the node
*/
Heap.prototype._sortNodeDown = function (i) {
var _this = this;
var moveIt = i < this.heapArray.length - 1;
var moved = false;
var self = this.heapArray[i];
var getPotentialParent = function (best, j) {
if (_this.compare(_this.heapArray[j], _this.heapArray[best]) < 0) {
best = j;
this._applyLimit();
};
/**
* Test if the heap has no elements.
* @return {Boolean} True if no elements on the heap
*/
Heap.prototype.isEmpty = function () {
return this.length === 0;
};
/**
* Get the leafs of the tree (no children nodes)
*/
Heap.prototype.leafs = function () {
if (this.heapArray.length === 0) {
return [];
}
return best;
var pi = Heap.getParentIndexOf(this.heapArray.length - 1);
return this.heapArray.slice(pi + 1);
};
while (moveIt) {
var childrenIdx = Heap.getChildrenIndexOf(i);
var bestChildIndex = childrenIdx.reduce(getPotentialParent, childrenIdx[0]);
var bestChild = this.heapArray[bestChildIndex];
if (typeof bestChild !== "undefined" &&
this.compare(self, bestChild) > 0) {
this._moveNode(i, bestChildIndex);
i = bestChildIndex;
moved = true;
Object.defineProperty(Heap.prototype, "length", {
/**
* Length of the heap.
* @return {Number}
*/
get: function () {
return this.heapArray.length;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Heap.prototype, "limit", {
/**
* Get length limit of the heap.
* @return {Number}
*/
get: function () {
return this._limit;
},
/**
* Set length limit of the heap.
* @return {Number}
*/
set: function (_l) {
this._limit = _l;
this._applyLimit();
},
enumerable: true,
configurable: true
});
/**
* Top node. Aliases: `element`.
* Same as: `top(1)[0]`
* @return {any} Top node
*/
Heap.prototype.peek = function () {
return this.heapArray[0];
};
/**
* Extract the top node (root). Aliases: `poll`.
* @return {any} Extracted top node, undefined if empty
*/
Heap.prototype.pop = function () {
var pop = this.heapArray.pop();
if (this.length > 0 && pop !== undefined) {
return this.replace(pop);
}
return pop;
};
/**
* Pushes element(s) to the heap.
* @param {...any} elements Elements to insert
* @return {Boolean} True if elements are present
*/
Heap.prototype.push = function () {
var elements = [];
for (var _i = 0; _i < arguments.length; _i++) {
elements[_i] = arguments[_i];
}
if (elements.length < 1) {
return false;
}
else if (elements.length === 1) {
return this.add(elements[0]);
}
else {
moveIt = false;
return this.addAll(elements);
}
}
return moved;
};
/**
* Move a node up the tree (to the root) to find a place where the heap is sorted.
* @param {Number} i Index of the node
*/
Heap.prototype._sortNodeUp = function (i) {
var moveIt = i > 0;
var moved = false;
while (moveIt) {
var pi = Heap.getParentIndexOf(i);
if (pi >= 0 && this.compare(this.heapArray[pi], this.heapArray[i]) > 0) {
this._moveNode(i, pi);
i = pi;
moved = true;
};
/**
* Same as push & pop in sequence, but faster
* @param {any} element Element to insert
* @return {any} Extracted top node
*/
Heap.prototype.pushpop = function (element) {
var _a;
if (this.compare(this.heapArray[0], element) < 0) {
_a = [this.heapArray[0], element], element = _a[0], this.heapArray[0] = _a[1];
this._sortNodeDown(0);
}
return element;
};
/**
* Remove an element from the heap.
* @param {any} o Element to be found
* @param {Function} fn Optional function to compare
* @return {Boolean} True if the heap was modified
*/
Heap.prototype.remove = function (o, fn) {
if (fn === void 0) { fn = Heap.defaultIsEqual; }
if (this.length > 0) {
if (o === undefined) {
this.pop();
return true;
}
else {
var idx = this.heapArray.findIndex(function (el) { return fn(el, o); });
if (idx >= 0) {
if (idx === 0) {
this.pop();
}
else if (idx === this.length - 1) {
this.heapArray.pop();
}
else {
this.heapArray.splice(idx, 1, this.heapArray.pop());
this._sortNodeUp(idx);
this._sortNodeDown(idx);
}
return true;
}
}
}
return false;
};
/**
* Pop the current peek value, and add the new item.
* @param {any} element Element to replace peek
* @return {any} Old peek
*/
Heap.prototype.replace = function (element) {
var peek = this.heapArray[0];
this.heapArray[0] = element;
this._sortNodeDown(0);
return peek;
};
/**
* Size of the heap
* @return {Number}
*/
Heap.prototype.size = function () {
return this.length;
};
/**
* Return the top (highest value) N elements of the heap.
*
* @param {Number} n Number of elements.
* @return {Array} Array of length <= N.
*/
Heap.prototype.top = function (n) {
if (n === void 0) { n = 1; }
if (this.heapArray.length === 0 || n <= 0) {
// Nothing to do
return [];
}
else if (this.heapArray.length === 1 || n === 1) {
// Just the peek
return [this.heapArray[0]];
}
else if (n >= this.heapArray.length) {
// The whole peek
// Clone is needed due to the sort method (in-place) that would destroy the heap
var cloned = this.heapArray.slice(0);
cloned.sort(this.compare);
return cloned;
}
else {
moveIt = false;
// Some elements
var result = this._topN(n);
result.sort(this.compare);
return result;
}
}
return moved;
};
/**
* Return the top (highest value) N elements of the heap, without corner cases, unsorted
*
* @param {Number} n Number of elements.
* @return {Array} Array of length <= N.
*/
Heap.prototype._topN = function (n) {
// Use an inverted heap
var topHeap = new Heap(this._invertedCompare);
topHeap.limit = n;
var indices = [0];
var arr = this.heapArray;
while (indices.length) {
var i = indices.shift();
if (i < arr.length) {
if (topHeap.length < n) {
topHeap.push(arr[i]);
indices.push.apply(indices, Heap.getChildrenIndexOf(i));
};
/**
* Clone the heap's internal array
* @return {Array}
*/
Heap.prototype.toArray = function () {
return this.heapArray.slice(0);
};
/**
* String output, call to Array.prototype.toString()
* @return {String}
*/
Heap.prototype.toString = function () {
return this.heapArray.toString();
};
/**
* Get the element at the given index.
* @param {Number} i Index to get
* @return {any} Element at that index
*/
Heap.prototype.get = function (i) {
return this.heapArray[i];
};
/**
* Get the elements of these node's children
* @param {Number} idx Node index
* @return {Array(any)} Children elements
*/
Heap.prototype.getChildrenOf = function (idx) {
var _this = this;
return Heap.getChildrenIndexOf(idx)
.map(function (i) { return _this.heapArray[i]; })
.filter(function (e) { return e !== undefined; });
};
/**
* Get the element of this node's parent
* @param {Number} idx Node index
* @return {any} Parent element
*/
Heap.prototype.getParentOf = function (idx) {
var pi = Heap.getParentIndexOf(idx);
return this.heapArray[pi];
};
/**
* Limit heap size if needed
*/
Heap.prototype._applyLimit = function () {
if (this._limit && this._limit < this.heapArray.length) {
var rm = this.heapArray.length - this._limit;
// It's much faster than splice
while (rm) {
this.heapArray.pop();
--rm;
}
else if (this.compare(arr[i], topHeap.peek()) <= 0) {
topHeap.replace(arr[i]);
indices.push.apply(indices, Heap.getChildrenIndexOf(i));
}
};
/**
* Return the bottom (lowest value) N elements of the heap, without corner cases, unsorted
*
* @param {Number} n Number of elements.
* @return {Array} Array of length <= N.
*/
Heap.prototype._bottomN = function (n) {
// Use an inverted heap
var bottomHeap = new Heap(this.compare);
bottomHeap.limit = n;
bottomHeap.init(this.heapArray.slice(-n));
var startAt = this.heapArray.length - 1 - n;
var parentStartAt = Heap.getParentIndexOf(startAt);
var indices = [];
for (var i = startAt; i > parentStartAt; --i) {
indices.push(i);
}
var arr = this.heapArray;
while (indices.length) {
var i = indices.shift();
if (this.compare(arr[i], bottomHeap.peek()) > 0) {
bottomHeap.replace(arr[i]);
if (i % 2) {
indices.push(Heap.getParentIndexOf(i));
}
}
}
}
return topHeap.toArray();
};
return Heap;
}());
return bottomHeap.toArray();
};
/**
* Move a node to a new index, switching places
* @param {Number} j First node index
* @param {Number} k Another node index
*/
Heap.prototype._moveNode = function (j, k) {
var _a;
_a = [this.heapArray[k], this.heapArray[j]], this.heapArray[j] = _a[0], this.heapArray[k] = _a[1];
};
/**
* Move a node down the tree (to the leaves) to find a place where the heap is sorted.
* @param {Number} i Index of the node
*/
Heap.prototype._sortNodeDown = function (i) {
var _this = this;
var moveIt = i < this.heapArray.length - 1;
var moved = false;
var self = this.heapArray[i];
var getPotentialParent = function (best, j) {
if (_this.compare(_this.heapArray[j], _this.heapArray[best]) < 0) {
best = j;
}
return best;
};
while (moveIt) {
var childrenIdx = Heap.getChildrenIndexOf(i);
var bestChildIndex = childrenIdx.reduce(getPotentialParent, childrenIdx[0]);
var bestChild = this.heapArray[bestChildIndex];
if (typeof bestChild !== 'undefined' && this.compare(self, bestChild) > 0) {
this._moveNode(i, bestChildIndex);
i = bestChildIndex;
moved = true;
}
else {
moveIt = false;
}
}
return moved;
};
/**
* Move a node up the tree (to the root) to find a place where the heap is sorted.
* @param {Number} i Index of the node
*/
Heap.prototype._sortNodeUp = function (i) {
var moveIt = i > 0;
var moved = false;
while (moveIt) {
var pi = Heap.getParentIndexOf(i);
if (pi >= 0 && this.compare(this.heapArray[pi], this.heapArray[i]) > 0) {
this._moveNode(i, pi);
i = pi;
moved = true;
}
else {
moveIt = false;
}
}
return moved;
};
/**
* Return the top (highest value) N elements of the heap, without corner cases, unsorted
*
* @param {Number} n Number of elements.
* @return {Array} Array of length <= N.
*/
Heap.prototype._topN = function (n) {
// Use an inverted heap
var topHeap = new Heap(this._invertedCompare);
topHeap.limit = n;
var indices = [0];
var arr = this.heapArray;
while (indices.length) {
var i = indices.shift();
if (i < arr.length) {
if (topHeap.length < n) {
topHeap.push(arr[i]);
indices.push.apply(indices, Heap.getChildrenIndexOf(i));
}
else if (this.compare(arr[i], topHeap.peek()) <= 0) {
topHeap.replace(arr[i]);
indices.push.apply(indices, Heap.getChildrenIndexOf(i));
}
}
}
return topHeap.toArray();
};
return Heap;
}());
exports.Heap = Heap;
exports['default'] = Heap;
exports.Heap = Heap;
exports.default = Heap;
Object.defineProperty(exports, '__esModule', { value: true });
Object.defineProperty(exports, '__esModule', { value: true });
})));
//# sourceMappingURL=heap-js.umd.js.map
}));

@@ -8,5 +8,5 @@ export declare type Comparator<T> = (a: T, b: T) => number;

export declare class Heap<T> {
compare: Comparator<T>;
heapArray: Array<T>;
compare: Comparator<T>;
_limit: number | null;
_limit: number;
/**

@@ -28,3 +28,3 @@ * Alias of add

*/
constructor(compare?: Comparator<T | number>);
constructor(compare?: Comparator<T>);
/**

@@ -54,3 +54,3 @@ * Gets children indices for given index.

*/
static minComparator(a: number, b: number): number;
static minComparator<N>(a: N, b: N): number;
/**

@@ -62,4 +62,18 @@ * Max heap comparison function.

*/
static maxComparator(a: number, b: number): number;
static maxComparator<N>(a: N, b: N): number;
/**
* Min number heap comparison function, default.
* @param {Number} a First element
* @param {Number} b Second element
* @return {Number} 0 if they're equal, positive if `a` goes up, negative if `b` goes up
*/
static minComparatorNumber(a: number, b: number): number;
/**
* Max number heap comparison function.
* @param {Number} a First element
* @param {Number} b Second element
* @return {Number} 0 if they're equal, positive if `a` goes up, negative if `b` goes up
*/
static maxComparatorNumber(a: number, b: number): number;
/**
* Default equality function.

@@ -201,6 +215,6 @@ * @param {any} a First element

/**
* Set length limit of the heap.
* @return {Number}
*/
limit: number | null;
* Set length limit of the heap.
* @return {Number}
*/
limit: number;
/**

@@ -207,0 +221,0 @@ * Top node. Aliases: `element`.

{
"name": "heap-js",
"version": "1.2.2",
"description": "Heap data structure for JavaScript.",
"version": "1.3.0",
"description": "Heap data structure for JavaScript / TypeScript.",
"keywords": [

@@ -17,3 +17,3 @@ "heap",

"module": "dist/heap-js.es5.js",
"types": "dist/types/heap-js.d.ts",
"types": "dist/types/Heap.d.ts",
"author": "Ignacio Lago @ignlg <ignacio@ignaciolago.com>",

@@ -82,28 +82,28 @@ "license": "BSD-3-Clause",

"devDependencies": {
"@types/jest": "^20.0.0",
"@types/node": "^8.0.0",
"commitizen": "^2.9.6",
"coveralls": "^2.13.1",
"cross-env": "^5.0.1",
"cz-conventional-changelog": "^2.0.0",
"husky": "^0.14.3",
"jest": "^20.0.4",
"lint-staged": "^4.0.0",
"@types/jest": "^24.0.11",
"@types/node": "^11.13.4",
"commitizen": "^3.0.7",
"coveralls": "^3.0.3",
"cross-env": "^5.2.0",
"cz-conventional-changelog": "^2.1.0",
"husky": "^1.3.1",
"jest": "^24.7.1",
"lint-staged": "^8.1.5",
"lodash.camelcase": "^4.3.0",
"prettier": "^1.4.4",
"rimraf": "^2.6.1",
"rollup": "^0.43.1",
"rollup-plugin-commonjs": "^8.0.2",
"rollup-plugin-node-resolve": "^3.0.0",
"prettier": "^1.17.0",
"rimraf": "^2.6.3",
"rollup": "^1.10.0",
"rollup-plugin-commonjs": "^9.3.4",
"rollup-plugin-node-resolve": "^4.2.3",
"rollup-plugin-sourcemaps": "^0.4.2",
"ts-jest": "^20.0.6",
"ts-node": "^3.0.6",
"tsc-watch": "^1.0.5",
"tslint": "^5.4.3",
"tslint-config-prettier": "^1.1.0",
"tslint-config-standard": "^6.0.0",
"typedoc": "^0.7.1",
"typescript": "^2.3.4",
"validate-commit-msg": "^2.12.2"
"ts-jest": "^24.0.2",
"ts-node": "^8.1.0",
"tsc-watch": "^2.1.2",
"tslint": "^5.15.0",
"tslint-config-prettier": "^1.18.0",
"tslint-config-standard": "^8.0.1",
"typedoc": "^0.14.2",
"typescript": "^3.4.3",
"validate-commit-msg": "^2.14.0"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc