simple-priority-queue
v1.5.0
Published
Simple and fast priority queue that uses promise based of while iteration and not blocking the main thread.
Readme
Priority Queue
Simple and fast priority queue that uses promise based of while iteration and not blocking the main thread.
Contents
Install
npm i --save simple-priority-queueBasic Usage
const { PriorityQueue } = require('simple-priority-queue');
const myQueue = new PriorityQueue(true); //true for maxheap, default is minheap
// enqueue recive 2 params nodeData: any object , nodePriority: priority of data
myQueue.insert({ myCoolData: 'MyCoolValue' }, 1);
myQueue.insert({ myCoolData: 'MyCoolValue' }, 2);
myQueue.insert({ myCoolData: 'MyCoolValue' }, 3);
myQueue.insert({ myCoolData: 'MyCoolValue' }, 4);
// dequeue by order of the priority
const value = myQueue.poll();
// sort the data (will remove the content of queue)
const mySortedArray = await myQueue.heapSort();