d-heap
D-ary heap implementation.
Installation
$ npm i d-heap
Usage
var DHeap = ; var sample = 2 5 6 9 14 1 3 4 7 8 15 13 10 11 12 16; // 4-ary max-heapvar heap = sample;console;// [16, 7, 15, 12, 14, 1, 3, 4, 5, 8, 6, 13, 10, 11, 2, 9] // Custom arityvar binHeap = sample arity: 2 ;console;// [16, 14, 15, 12, 8, 13, 11, 9, 5, 7, 6, 1, 10, 3, 2, 4] // Custom comparator and sortingvar minHeap = sample { return b - a };minHeap;console;// [16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
API
items options // Options: // arity - heap arity, optional, // compare - comparator, optional. // Performs heapsort. // Updates item at given position. // Appends item and rebuild heap. // Returns top-most item. // Extracts top-most item from heap.
Performance
TL;DR
License
MIT