
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
@datastructures-js/priority-queue
Advanced tools
priority queue implementation in javascript using a Min Heap
A highly performant priority queue implementation using a Min Heap data structure.
npm install --save @datastructures-js/priority-queue
const PriorityQueue = require('@datastructures-js/priority-queue');
import PriorityQueue from '@datastructures-js/priority-queue';
const priorityQueue = new PriorityQueue();
adds an element with a priority (number) to the queue. The smaller the number, the higher the priority.
runtime | params |
---|---|
O(log(n)) |
element: object
priority: number |
priorityQueue.enqueue('patient y', 1); // highest priority
priorityQueue.enqueue('patient z', 3);
priorityQueue.enqueue('patient w', 4); // lowest priority
priorityQueue.enqueue('patient x', 2);
returns the element with highest priority in the queue.
runtime | return |
---|---|
O(1) | object |
console.log(priorityQueue.front()); // patient y
returns an element with lowest priority in the queue. If multiple elements exist at the lowest priority, the one that was inserted first will be returned.
runtime | return |
---|---|
O(1) | object |
priorityQueue.enqueue('patient m', 4); // lowest priority
priorityQueue.enqueue('patient c', 4); // lowest priority
console.log(priorityQueue.back()); // patient w
removes and returns the element with highest priority in the queue.
runtime | return |
---|---|
O(log(n)) | object |
console.log(priorityQueue.dequeue()); // patient y
console.log(priorityQueue.front()); // patient x
checks if the queue is empty.
runtime | return |
---|---|
O(1) | {boolean} |
console.log(priorityQueue.isEmpty()); // false
returns the number of elements in the queue.
runtime | return |
---|---|
O(1) | number |
console.log(priorityQueue.size()); // 5
returns an sorted array of elements from highest priority to lowest.
runtime | return |
---|---|
O(n*log(n)) | array |
console.log(priorityQueue.toArray()); // ['patient x', 'patient z', 'patient c', 'patient w', 'patient m']
clears all elements in the queue.
runtime |
---|
O(1) |
priorityQueue.clear();
console.log(priorityQueue.size()); // 0
console.log(priorityQueue.front()); // null
console.log(priorityQueue.dequeue()); // null
grunt build
The MIT License. Full License is here
FAQs
A heap-based implementation of priority queue in javascript with typescript support.
The npm package @datastructures-js/priority-queue receives a total of 151,526 weekly downloads. As such, @datastructures-js/priority-queue popularity was classified as popular.
We found that @datastructures-js/priority-queue demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.