Skip to content

Naihan/simple-priority-queue

Repository files navigation

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

About

async priority queue

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •