{"_id":"js-heap","_rev":"11-1ee3bc94c71ccd6519f8facdcbb69dc4","name":"js-heap","time":{"modified":"2022-06-19T05:35:45.528Z","created":"2014-10-14T03:32:59.524Z","0.1.0":"2014-10-14T03:32:59.524Z","0.2.0":"2014-10-14T03:35:07.841Z","0.3.0":"2014-10-14T07:04:49.309Z","0.3.1":"2014-12-25T12:26:30.327Z"},"maintainers":[{"name":"thauburger","email":"thauburger@gmail.com"}],"dist-tags":{"latest":"0.3.1"},"description":"A javascript heap implementation","readme":"js-heap\n=======\n\njs-heap is a flexible, value-agnostic heap for Javascript. It provides a simple interface and allows users to define custom comparison functions for heap sorting.\n\n## Installation\n\n```javscript\nnpm install js-heap\n```\n\n## Usage\n\nTo get started, `require` **js-heap**, and create a new Heap instance:\n\n```javascript\nvar Heap = require('js-heap');\n\nvar h = new Heap(function(a,b) {\n  return a - b;\n});\n```\n\nThe comparison function behaves like a [sort](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) function you would pass into a standard [Javascript Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array).\n\nThe default comparison function is the one shown above - the heap is organized so that the highest numeric priority is at the top.\n\n## Heap Values\n\nA node in the heap can be whatever you'd like:\n\n```javascript\n// Example node\nvar node = {\n  priority: 1,\n  value: 'ABCD',\n}\n\nh.push(node);\n```\n\nYou can create a custom sort function to compare arbitrary nodes:\n\n```javascript\nvar h = new Heap(function(a, b) {\n  return a.priority - b.priority;\n});\n```\n\n##.push(node)\nPushes a new node onto the heap. A \"node\" value can be a primitive or an arbitrary Javascript object. Pushed nodes are sorted based on the provided sort function.\n\n```javascript\nh.push(1);\nh.push(2);\n...\n```\n\n##.pop()\nRemoves and returns the top node in the heap. If the heap is empty, `null` is returned.\n\n```javascript\n// Returns 2\nh.pop();\n\n// Returns 1\nh.pop();\n\n// Returns null\nh.pop();\n...\n```\n\n##.peek()\nReturns the top node in the heap. The node remains on top of the heap.\n\n```javascript\nh.push(1);\n\n// Returns 1\nh.peek();\n\n// Still returns 1\nh.peek();\n...\n```\n\n##.isEmpty()\nReturns `true` if the heap is empty. \n\n##.length\nA read-only length property representing the number of nodes in the heap.\n","versions":{"0.2.0":{"name":"js-heap","version":"0.2.0","description":"A javascript heap implementation","main":"heap.js","homepage":"https://github.com/thauburger/js-heap","scripts":{"test":"node test/test.js | node_modules/.bin/tap-spec"},"keywords":["heap","priority","queue"],"author":{"name":"Tom Hauburger","email":"thauburger@gmail.com"},"license":"MIT","devDependencies":{"tap-spec":"^1.0.0","tape":"^3.0.0"},"repository":{"type":"git","url":"https://github.com/thauburger/js-heap"},"bugs":{"url":"https://github.com/thauburger/js-heap/issues"},"_id":"js-heap@0.2.0","_shasum":"9202a3c041a3bf97d768aecc5526bb257533fc99","_from":".","_npmVersion":"1.4.9","_npmUser":{"name":"thauburger","email":"thauburger@gmail.com"},"maintainers":[{"name":"thauburger","email":"thauburger@gmail.com"}],"dist":{"shasum":"9202a3c041a3bf97d768aecc5526bb257533fc99","tarball":"https://registry.npmjs.org/js-heap/-/js-heap-0.2.0.tgz","integrity":"sha512-QUkYbkG+7BYgkQctR0ijVWWln5dxm992icZ+FEDxcXWbjyYKQGkg/v6YQAw3MTMObFkL10wyAKuOlxY31/P8SA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDQEcgbEqA8RcrK9SG/xP5weTv3wHa+wIDqDDYbd9kDGwIgOpMgzKR5DrO+mbOtUaNoLlof2sQwzbRhpZ8VVi53b28="}]}},"0.3.0":{"name":"js-heap","version":"0.3.0","description":"A javascript heap implementation","main":"heap.js","homepage":"https://github.com/thauburger/js-heap","scripts":{"test":"node test/test.js | node_modules/.bin/tap-spec"},"keywords":["heap","priority","queue"],"author":{"name":"Tom Hauburger","email":"thauburger@gmail.com"},"license":"MIT","devDependencies":{"tap-spec":"^1.0.0","tape":"^3.0.0"},"repository":{"type":"git","url":"https://github.com/thauburger/js-heap"},"bugs":{"url":"https://github.com/thauburger/js-heap/issues"},"_id":"js-heap@0.3.0","_shasum":"5f561b02ba61273835e1f45d9d6ecf2b4a4599a5","_from":".","_npmVersion":"1.4.9","_npmUser":{"name":"thauburger","email":"thauburger@gmail.com"},"maintainers":[{"name":"thauburger","email":"thauburger@gmail.com"}],"dist":{"shasum":"5f561b02ba61273835e1f45d9d6ecf2b4a4599a5","tarball":"https://registry.npmjs.org/js-heap/-/js-heap-0.3.0.tgz","integrity":"sha512-tTwCduS3A7MIIjT9MoylDgLXykx/gxxcT9TAP7+BiwDIiLMt8rASphNiZRIj84y9eFaNM/palp1T4kB/D9DZhw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDgvuGhwnBZofiqwCD2TpSYvoDzuYpibXXT2Qy7E6F64QIhAMoq7B/55NbU5RN48PiROd6ZRecpZx3e64k/5XwcbF1N"}]}},"0.3.1":{"name":"js-heap","version":"0.3.1","description":"A javascript heap implementation","main":"heap.js","homepage":"https://github.com/thauburger/js-heap","scripts":{"test":"node test/test.js | node_modules/.bin/tap-spec"},"keywords":["heap","priority","queue"],"author":{"name":"Tom Hauburger","email":"thauburger@gmail.com"},"license":"MIT","devDependencies":{"tap-spec":"^1.0.0","tape":"^3.0.0"},"repository":{"type":"git","url":"https://github.com/thauburger/js-heap"},"gitHead":"019d4b6ad4aa8a424760d17405d99a1fc5bca84d","bugs":{"url":"https://github.com/thauburger/js-heap/issues"},"_id":"js-heap@0.3.1","_shasum":"5b48965edb23bf6497f55e4982b5699ae9e02f4c","_from":".","_npmVersion":"2.1.8","_nodeVersion":"0.10.33","_npmUser":{"name":"thauburger","email":"thauburger@gmail.com"},"maintainers":[{"name":"thauburger","email":"thauburger@gmail.com"}],"dist":{"shasum":"5b48965edb23bf6497f55e4982b5699ae9e02f4c","tarball":"https://registry.npmjs.org/js-heap/-/js-heap-0.3.1.tgz","integrity":"sha512-hj+APSYr/87JmlAZX2OLPJxigf/hhpc48lYPgwQLIedPITDNmimpGDWPBBMo2pwyiIqVsFwvtj9ISyM6+hDWvw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIESM5IR5hZQMbVJLzrv+naf7TMslYWJ7XMVQ6ya/yqJ/AiEApz1Dyo7MfVB0GjCCjkw7vvMOVth+VzXyt70BBb0vUec="}]}}},"homepage":"https://github.com/thauburger/js-heap","keywords":["heap","priority","queue"],"repository":{"type":"git","url":"https://github.com/thauburger/js-heap"},"author":{"name":"Tom Hauburger","email":"thauburger@gmail.com"},"bugs":{"url":"https://github.com/thauburger/js-heap/issues"},"license":"MIT","readmeFilename":"README.md"}