simple-priority-queue

1.5.0 • Public • Published

Priority Queue

Simple and fast priority queue that uses promise based of while iteration and not blocking the main thread.

NPM JavaScript Style Guide

Contents

Install

npm i --save simple-priority-queue

Basic 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();

License

MIT © https://github.com/Naihan/simple-priority-queue

Readme

Keywords

Package Sidebar

Install

npm i simple-priority-queue

Weekly Downloads

6

Version

1.5.0

License

ISC

Unpacked Size

13.5 kB

Total Files

7

Last publish

Collaborators

  • naihan