{"_id":"heap","_rev":"1832078","name":"heap","description":"binary heap (priority queue) algorithms (ported from Python's heapq module)","dist-tags":{"latest":"0.2.7"},"maintainers":[{"name":"qiao","email":"xueqiaoxu@gmail.com"}],"time":{"modified":"2021-12-02T08:21:10.000Z","created":"2012-03-23T17:42:10.947Z","0.2.7":"2021-12-02T08:15:05.314Z","0.2.6":"2015-02-09T07:09:00.041Z","0.2.5":"2014-09-10T18:30:11.140Z","0.2.4":"2014-08-13T06:06:50.545Z","0.2.3":"2013-10-23T08:49:10.721Z","0.2.2":"2013-10-16T01:45:20.902Z","0.2.1":"2012-04-29T06:21:25.285Z","0.2.0":"2012-04-22T16:50:06.403Z","0.1.2":"2012-03-24T03:21:50.261Z","0.1.0":"2012-03-23T17:42:10.947Z"},"users":{"pvorb":true,"semencov":true,"kisskie":true,"brunocalou":true,"shanemileham":true,"archarious":true,"scott.m.sarsfield":true},"author":{"name":"Xueqiao Xu","email":"xueqiaoxu@gmail.com"},"repository":{"type":"git","url":"git://github.com/qiao/heap.js.git"},"versions":{"0.2.7":{"name":"heap","version":"0.2.7","description":"binary heap (priority queue) algorithms (ported from Python's heapq module)","homepage":"https://github.com/qiao/heap.js","keywords":["algorithm","data structure","heap"],"author":{"name":"Xueqiao Xu","email":"xueqiaoxu@gmail.com"},"main":"./index.js","devDependencies":{"coffee-script":"1.3.x","mocha":"2.1.x","should":"0.6.x"},"scripts":{"test":"make test"},"repository":{"type":"git","url":"git://github.com/qiao/heap.js.git"},"license":"MIT","gitHead":"21701c0b9c22039de6f948ed5f6d44e53ae79231","bugs":{"url":"https://github.com/qiao/heap.js/issues"},"_id":"heap@0.2.7","_nodeVersion":"17.0.1","_npmVersion":"8.1.0","dist":{"shasum":"1e6adf711d3f27ce35a81fe3b7bd576c2260a8fc","size":6718,"noattachment":false,"key":"/heap/-/heap-0.2.7.tgz","tarball":"http://registry.cnpm.dingdandao.com/heap/download/heap-0.2.7.tgz"},"_npmUser":{"name":"qiao","email":"xueqiaoxu@gmail.com"},"directories":{},"maintainers":[{"name":"qiao","email":"xueqiaoxu@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/heap_0.2.7_1638432905165_0.29257309632662976"},"_hasShrinkwrap":false,"publish_time":1638432905314,"_cnpm_publish_time":1638432905314},"0.2.6":{"name":"heap","version":"0.2.6","description":"binary heap (priority queue) algorithms (ported from Python's heapq module)","homepage":"https://github.com/qiao/heap.js","keywords":["algorithm","data structure","heap"],"author":{"name":"Xueqiao Xu","email":"xueqiaoxu@gmail.com"},"main":"./index.js","dependencies":{},"devDependencies":{"coffee-script":"1.3.x","mocha":"2.1.x","should":"0.6.x"},"scripts":{"test":"make test"},"repository":{"type":"git","url":"git://github.com/qiao/heap.js.git"},"licenses":[{"type":"PSF","url":"http://docs.python.org/license.html"}],"gitHead":"6244ef82933f42ae0e8e0e60aff7196f3f2feb61","bugs":{"url":"https://github.com/qiao/heap.js/issues"},"_id":"heap@0.2.6","_shasum":"087e1f10b046932fc8594dd9e6d378afc9d1e5ac","_from":".","_npmVersion":"2.1.6","_nodeVersion":"0.10.33","_npmUser":{"name":"qiao","email":"xueqiaoxu@gmail.com"},"maintainers":[{"name":"qiao","email":"xueqiaoxu@gmail.com"}],"dist":{"shasum":"087e1f10b046932fc8594dd9e6d378afc9d1e5ac","size":7221,"noattachment":false,"key":"/heap/-/heap-0.2.6.tgz","tarball":"http://registry.cnpm.dingdandao.com/heap/download/heap-0.2.6.tgz"},"directories":{},"publish_time":1423465740041,"_cnpm_publish_time":1423465740041,"_hasShrinkwrap":false},"0.2.5":{"name":"heap","version":"0.2.5","description":"binary heap (priority queue) algorithms (ported from Python's heapq module)","homepage":"https://github.com/qiao/heap.js","keywords":["algorithm","data structure","heap"],"author":{"name":"Xueqiao Xu","email":"xueqiaoxu@gmail.com"},"main":"./index.js","dependencies":{},"devDependencies":{"coffee-script":"1.3.x","mocha":"1.0.x","should":"0.6.x"},"scripts":{"test":"make test"},"repository":{"type":"git","url":"git://github.com/qiao/heap.js.git"},"licenses":[{"type":"PSF","url":"http://docs.python.org/license.html"}],"gitHead":"0eda661c983504ee239aeae6191401fad3ef4c55","bugs":{"url":"https://github.com/qiao/heap.js/issues"},"_id":"heap@0.2.5","_shasum":"713b65590ebcc40fcbeeaf55e851694092b39af1","_from":".","_npmVersion":"1.4.16","_npmUser":{"name":"qiao","email":"xueqiaoxu@gmail.com"},"maintainers":[{"name":"qiao","email":"xueqiaoxu@gmail.com"}],"dist":{"shasum":"713b65590ebcc40fcbeeaf55e851694092b39af1","size":7178,"noattachment":false,"key":"/heap/-/heap-0.2.5.tgz","tarball":"http://registry.cnpm.dingdandao.com/heap/download/heap-0.2.5.tgz"},"directories":{},"publish_time":1410373811140,"_cnpm_publish_time":1410373811140,"_hasShrinkwrap":false},"0.2.4":{"name":"heap","version":"0.2.4","description":"binary heap (priority queue) algorithms (ported from Python's heapq module)","homepage":"https://github.com/qiao/heap.js","keywords":["algorithm","data structure","heap"],"author":{"name":"Xueqiao Xu","email":"xueqiaoxu@gmail.com"},"main":"./index.js","dependencies":{},"devDependencies":{"coffee-script":"1.3.x","mocha":"1.0.x","should":"0.6.x"},"scripts":{"test":"make test"},"repository":{"type":"git","url":"git://github.com/qiao/heap.js.git"},"licenses":[{"type":"PSF","url":"http://docs.python.org/license.html"}],"gitHead":"c782fab6f0bb8bfc16c72387d2916034c84debbe","bugs":{"url":"https://github.com/qiao/heap.js/issues"},"_id":"heap@0.2.4","_shasum":"e96b141eb7956882de41945a6c5bbb985fd3cfae","_from":".","_npmVersion":"1.4.16","_npmUser":{"name":"qiao","email":"xueqiaoxu@gmail.com"},"maintainers":[{"name":"qiao","email":"xueqiaoxu@gmail.com"}],"dist":{"shasum":"e96b141eb7956882de41945a6c5bbb985fd3cfae","size":7128,"noattachment":false,"key":"/heap/-/heap-0.2.4.tgz","tarball":"http://registry.cnpm.dingdandao.com/heap/download/heap-0.2.4.tgz"},"directories":{},"publish_time":1407910010545,"_cnpm_publish_time":1407910010545,"_hasShrinkwrap":false},"0.2.3":{"name":"heap","version":"0.2.3","description":"binary heap (priority queue) algorithms (ported from Python's heapq module)","homepage":"https://github.com/qiao/heap.js","keywords":["algorithm","data structure","heap"],"author":{"name":"Xueqiao Xu","email":"xueqiaoxu@gmail.com"},"main":"./index.js","dependencies":{},"devDependencies":{"coffee-script":"1.3.x","mocha":"1.0.x","should":"0.6.x"},"repository":{"type":"git","url":"git://github.com/qiao/heap.js.git"},"licenses":[{"type":"PSF","url":"http://docs.python.org/license.html"}],"readmeFilename":"README.md","bugs":{"url":"https://github.com/qiao/heap.js/issues"},"_id":"heap@0.2.3","dist":{"shasum":"59f1466e0f40e9fec41866e5261d01780f90577b","size":6932,"noattachment":false,"key":"/heap/-/heap-0.2.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/heap/download/heap-0.2.3.tgz"},"_from":".","_npmVersion":"1.3.11","_npmUser":{"name":"qiao","email":"xueqiaoxu@gmail.com"},"maintainers":[{"name":"qiao","email":"xueqiaoxu@gmail.com"}],"directories":{},"publish_time":1382518150721,"_cnpm_publish_time":1382518150721,"_hasShrinkwrap":false},"0.2.2":{"name":"heap","version":"0.2.2","description":"binary heap (priority queue) algorithms (ported from Python's heapq module)","homepage":"https://github.com/qiao/heap.js","keywords":["algorithm","data structure","heap"],"author":{"name":"Xueqiao Xu","email":"xueqiaoxu@gmail.com"},"main":"./index.js","dependencies":{},"devDependencies":{"coffee-script":"1.3.x","mocha":"1.0.x","should":"0.6.x"},"repository":{"type":"git","url":"git://github.com/qiao/heap.js.git"},"licenses":[{"type":"PSF","url":"http://docs.python.org/license.html"}],"readmeFilename":"README.md","bugs":{"url":"https://github.com/qiao/heap.js/issues"},"_id":"heap@0.2.2","dist":{"shasum":"fc204a17e6bc58a4ef75a98bc1ac795f147c8a1f","size":6953,"noattachment":false,"key":"/heap/-/heap-0.2.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/heap/download/heap-0.2.2.tgz"},"_from":".","_npmVersion":"1.3.8","_npmUser":{"name":"qiao","email":"xueqiaoxu@gmail.com"},"maintainers":[{"name":"qiao","email":"xueqiaoxu@gmail.com"}],"directories":{},"publish_time":1381887920902,"_cnpm_publish_time":1381887920902,"_hasShrinkwrap":false},"0.2.1":{"name":"heap","version":"0.2.1","description":"binary heap (priority queue) algorithms (ported from Python's heapq module)","homepage":"https://github.com/qiao/heap.js","keywords":["algorithm","data structure","heap"],"author":{"name":"Xueqiao Xu","email":"xueqiaoxu@gmail.com"},"main":"./index.js","dependencies":{},"devDependencies":{"coffee-script":"1.3.x","mocha":"1.0.x","should":"0.6.x"},"repository":{"type":"git","url":"git://github.com/qiao/heap.js.git"},"licenses":[{"type":"PSF","url":"http://docs.python.org/license.html"}],"_npmUser":{"name":"qiao","email":"xueqiaoxu@gmail.com"},"_id":"heap@0.2.1","optionalDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.1.18","_nodeVersion":"v0.6.15","_defaultsLoaded":true,"dist":{"shasum":"85829b1ea798ce41a548fa908c069baa075152ad","size":6957,"noattachment":false,"key":"/heap/-/heap-0.2.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/heap/download/heap-0.2.1.tgz"},"maintainers":[{"name":"qiao","email":"xueqiaoxu@gmail.com"}],"directories":{},"publish_time":1335680485285,"_cnpm_publish_time":1335680485285,"_hasShrinkwrap":false},"0.2.0":{"name":"heap","version":"0.2.0","description":"binary heap (priority queue) algorithms (ported from Python's heapq module)","homepage":"https://github.com/qiao/heap.js","keywords":["algorithm","data structure","heap"],"author":{"name":"Xueqiao Xu","email":"xueqiaoxu@gmail.com"},"main":"./index.js","dependencies":{},"devDependencies":{"coffee-script":">= 1.3.0","mocha":">= 0.14.0","should":">= 0.6.0"},"repository":{"type":"git","url":"git://github.com/qiao/heap.js.git"},"licenses":[{"type":"PSF","url":"http://docs.python.org/license.html"}],"_npmUser":{"name":"qiao","email":"xueqiaoxu@gmail.com"},"_id":"heap@0.2.0","optionalDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.1.18","_nodeVersion":"v0.6.15","_defaultsLoaded":true,"dist":{"shasum":"8ea3bbd03f9cc17509dc0aed4502523eb4963486","size":6694,"noattachment":false,"key":"/heap/-/heap-0.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/heap/download/heap-0.2.0.tgz"},"maintainers":[{"name":"qiao","email":"xueqiaoxu@gmail.com"}],"directories":{},"publish_time":1335113406403,"_cnpm_publish_time":1335113406403,"_hasShrinkwrap":false},"0.1.2":{"name":"heap","version":"0.1.2","description":"binary heap (priority queue) algorithms (ported from Python's heapq module)","homepage":"https://github.com/qiao/heap.js","keywords":["algorithm","data structure","heap"],"author":{"name":"Xueqiao Xu","email":"xueqiaoxu@gmail.com"},"main":"./index.js","dependencies":{},"devDependencies":{"coffee-script":">= 1.2.0","mocha":">= 0.14.0","should":">= 0.6.0"},"repository":{"type":"git","url":"git://github.com/qiao/heap.js.git"},"licenses":[{"type":"PSF","url":"http://docs.python.org/license.html"}],"_npmUser":{"name":"qiao","email":"xueqiaoxu@gmail.com"},"_id":"heap@0.1.2","optionalDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.1.9","_nodeVersion":"v0.6.13","_defaultsLoaded":true,"dist":{"shasum":"fb43eb55ad974c7b17b8942d05740dc44cc27ac8","size":6262,"noattachment":false,"key":"/heap/-/heap-0.1.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/heap/download/heap-0.1.2.tgz"},"maintainers":[{"name":"qiao","email":"xueqiaoxu@gmail.com"}],"directories":{},"publish_time":1332559310261,"_cnpm_publish_time":1332559310261,"_hasShrinkwrap":false},"0.1.0":{"name":"heap","version":"0.1.0","description":"binary heap (priority queue) algorithms (ported from Python's heapq module)","homepage":"https://github.com/qiao/heap.js","keywords":["algorithm","data structure","heap"],"author":{"name":"Xueqiao Xu","email":"xueqiaoxu@gmail.com"},"main":"./index.js","dependencies":{},"devDependencies":{"coffee-script":">= 1.2.0","mocha":">= 0.14.0","should":">= 0.6.0"},"repository":{"type":"git","url":"git://github.com/qiao/heap.js.git"},"licenses":[{"type":"MIT","url":"http://opensource.org/licenses/mit-license.php"}],"_npmUser":{"name":"qiao","email":"xueqiaoxu@gmail.com"},"_id":"heap@0.1.0","optionalDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.1.9","_nodeVersion":"v0.6.13","_defaultsLoaded":true,"dist":{"shasum":"d601715c7717fd9915fbbc35c8805f4a49f6f229","size":6238,"noattachment":false,"key":"/heap/-/heap-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/heap/download/heap-0.1.0.tgz"},"maintainers":[{"name":"qiao","email":"xueqiaoxu@gmail.com"}],"directories":{},"publish_time":1332524530947,"_cnpm_publish_time":1332524530947,"_hasShrinkwrap":false}},"readme":"Heap.js\n=======\n\n[![Build Status](https://travis-ci.org/qiao/heap.js.svg?branch=master)](https://travis-ci.org/qiao/heap.js)\n\nA binary heap implementation in CoffeeScript/JavaScript. Ported from Python's [heapq](http://docs.python.org/library/heapq.html) module.\n\n\nDownload\n--------\n\nThis module can be used in either the browser or node.js.\n\nfor browser use, you may [download the script](https://raw.github.com/qiao/heap.js/master/lib/heap.js) and include it in you web page.\n\n```html\n<script type=\"text/javascript\" src=\"./heap.js\"></script>\n```\n\nfor node.js, you may install it via npm:\n\n```bash\nnpm install heap\n```\n\nthen require it:\n\n```\nvar Heap = require('heap');\n```\n\nExamples\n-------\n\n\npush and pop\n\n```js\nvar heap = new Heap();\nheap.push(3);\nheap.push(1);\nheap.push(2);\nheap.pop(); // 1\n```\n\ncustom comparison function\n\n```js\nvar heap = new Heap(function(a, b) {\n    return a.foo - b.foo;\n});\nheap.push({foo: 3});\nheap.push({foo: 1});\nheap.push({foo: 2});\nheap.pop(); // {foo: 1}\n```\n\nfind 3 largest/smallest items in an array\n\n```js\nvar array = [1, 3, 4, 2, 5];\nHeap.nlargest(array, 3);  // [5, 4, 3]\nHeap.nsmallest(array, 3); // [1, 2, 3]\n```\n\nDocument\n--------\n\nThis module exposes only one object, namely the Heap class.\n\n### Constructor: Heap([cmp]) ###\n\nThe constructor receives a comparison function as an optional parameter. If omitted, the heap is built as a min-heap, which means that the smallest element will be popped out first.\n\nIf the comparison function is supplied, the heap will be built according to the \nreturn value of the comparison function.\n\n* if cmp(a, b) < 0, then item a will come prior to b\n* if cmp(a, b) > 0, then item b will come prior to a\n\nSo, the comparison function has the following form:\n\n```js\nfunction cmp(a, b) {\n  if (a is prior to b) {\n    return -1;\n  } \n  if (b is prior to a) {\n    return 1;\n  }\n  return 0;\n}\n```\n\nTo compare numbers, simply: \n\n```js\nfunction cmp(a, b) {\n  return a - b;\n}\n```\n\n### Instance Methods ###\n\n**push(item)** (alias: **insert**) \n\nPush item onto heap.\n\n**pop()**\n\nPop the smallest item off the heap and return it.\n\n**peek()** (alias: **top** / **front**)\n\nReturn the smallest item of the heap.\n\n**replace(item)**\n\nPop and return the current smallest value, and add the new item.\n\nThis is more efficient than pop() followed by push(), and can be \nmore appropriate when using a fixed size heap. Note that the value\nreturned may be larger than item! \n\n**pushpop(item)**\n\nFast version of a push followed by a pop.\n\n**heapify()**\n\nRebuild the heap. This method may come handy when the priority of the \ninternal data is being modified.\n\n**updateItem(item)**\n\nUpdate the position of the given item in the heap.\nThis function should be called every time the item is being modified.\n\n**empty()**\n\nDetermine whether the heap is empty.\n\n**size()**\n\nGet the number of elements stored in the heap.\n\n**toArray()**\n\nReturn the array representation of the heap. (note: the array is a shallow copy of the heap's internal nodes)\n\n**clone()** (alias: **copy**)\n\nReturn a clone of the heap. (note: the internal data is a shallow copy of the original one)\n\n### Static Methods ###\n\nNOTE: All the static methods are designed to be applied on arrays.\n\n**push(array, item, [cmp])** \n\nPush item onto array, maintaining the heap invariant.\n\n**pop(array, [cmp])**\n\nPop the smallest item off the array, maintaining the heap invariant.\n\n**replace(array, item, [cmp])**\n\nPop and return the current smallest value, and add the new item.\n\nThis is more efficient than heappop() followed by heappush(), and can be \nmore appropriate when using a fixed size heap. Note that the value\nreturned may be larger than item! \n\n**pushpop(array, item, [cmp])**\n\nFast version of a heappush followed by a heappop.\n\n**heapify(array, [cmp])**\n\nBuild the heap.\n\n**updateItem(array, item, [cmp])**\n\nUpdate the position of the given item in the heap.\nThis function should be called every time the item is being modified.\n\n**nlargest(array, n, [cmp])**\n\nFind the n largest elements in a dataset.\n\n**nsmallest(array, n, [cmp])**\n\nFind the n smallest elements in a dataset.\n","_attachments":{},"homepage":"https://github.com/qiao/heap.js","bugs":{"url":"https://github.com/qiao/heap.js/issues"},"license":"MIT"}