yabh
Yet another Binary Heap.
Last updated 10 years ago by jdobry .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install yabh 
SYNC missed versions from official npm registry.

yabh

bower version npm version Circle CI npm downloads codecov Codacy

Yet another Binary Heap.

Quick Start

bower install --save yabh or npm install --save yabh.

import BinaryHeap from 'yabh';
// or
define(['yabh'], function (BinaryHeap) { ... });
// or
var BinaryHeap = require('yabh');
// or
var BinaryHeap = window.BinaryHeap;

var heap = new BinaryHeap();

heap.push(4);
heap.push(2);
heap.push(1);
heap.push(5);
heap.push(3);
heap.peak(); // 1

API

BinaryHeap([weightFunc][, compareFunc])
var heap = new BinaryHeap();
heap.weightFunc; // function (x) { return x; }
heap.compareFunc; // function (x, y) { return x === y; }
var heap = new BinaryHeap(function (x) { return x.value; });
heap.weightFunc; // function (x) { return x.value; }
heap.compareFunc; // function (x, y) { return x === y; }

```js
var heap = new BinaryHeap(null, function (x, y) { return x == y; });
heap.weightFunc; // function (x) { return x; }
heap.compareFunc; // function (x, y) { return x == y; }
BinaryHeap#push(node) & BinaryHeap#pop()
var heap = new BinaryHeap();
heap.push(1);
heap.push(10);
heap.push(4);
heap.push(2);
heap.pop(); // 1
heap.pop(); // 2
heap.pop(); // 4
heap.pop(); // 10
BinaryHeap#peak()
var heap = new BinaryHeap();
heap.push(1);
heap.push(10);
heap.push(4);
heap.push(2);
heap.peek(); // 1
heap.pop(); // 1
heap.peek(); // 2
heap.pop(); // 2
heap.peek(); // 4
heap.pop(); // 4
heap.peek(); // 10
heap.pop(); // 10
BinaryHeap#remove(node)
var heap = new BinaryHeap();
heap.push(1);
heap.push(10);
heap.push(2);
heap.remove(10); // 10
heap.peek(); // 1
heap.remove(1); // 1
heap.peek(); // 2
BinaryHeap#removeAll()
var heap = new BinaryHeap();
heap.push(1);
heap.push(10);
heap.push(2);
heap.removeAll();
heap.size(); // 0
BinaryHeap#size()
var heap = new BinaryHeap();
heap.push(1);
heap.push(10);
heap.push(4);
heap.push(2);
heap.size(); // 4

License

The MIT License (MIT)

Copyright (c) 2015-2016 Jason Dobry

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Current Tags

  • 1.2.0                                ...           latest (9 years ago)

4 Versions

  • 1.2.0                                ...           9 years ago
  • 1.1.0                                ...           9 years ago
  • 1.0.1                                ...           10 years ago
  • 1.0.0                                ...           10 years ago
Maintainers (1)
Downloads
Total 5
Today 1
This Week 1
This Month 5
Last Day 0
Last Week 4
Last Month 0
Dependencies (0)
None
Dependents (2)

© 2010 - cnpmjs.org x YWFE | Home | YWFE