Lightweight min-max heap javascript library for node, browser
npm i minmaxheaps
node
const minmaxheaps = require("minmaxheaps")
let mmheap = new minmaxheaps.MinMaxHeap();
mmheap.push(16);
mmheap.push(-5643);
mmheap.popMin();
mmheap.popMax();
mmheap.popMax();
mmheap.push(123);
mmheap.popMin();
console.log(mmheap.heap);
console.log(mmheap.max());
console.log(mmheap.min());
browser
<head>
<script src="../dist/minmaxheaps.min.js"></script>
<script>
const {MinMaxHeap} = minmaxheap;
let mmheap = new MinMaxHeap();
mmheap.push(16);
mmheap.push(-5643);
mmheap.popMin();
mmheap.popMax();
mmheap.popMax();
mmheap.push(123);
mmheap.popMin();
console.log(mmheap.heap);
console.log(mmheap.max());
console.log(mmheap.min());
</script>
</head>
new MinMaxHeap([duplicate=true, comparator])
, wherecomparator
is optional comparison function andduplicate
is optional allow duplicate key (default is true)