Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
priorityqueue
Advanced tools
An implementation of priority queue in javascript.
npm install priorityqueue
import PriorityQueue from "priorityqueue";
class Point {
constructor(x, y) {
this.x = x;
this.y = y;
}
}
const numericCompare = (a, b) => (a > b ? 1 : a < b ? -1 : 0);
const comparator = (a, b) => {
const x = numericCompare(a.x, b.x);
const y = numericCompare(a.y, b.y);
return x ? x : y;
};
const pq = new PriorityQueue({ comparator });
pq.push(new Point(4, 6));
pq.push(new Point(2, 3));
pq.push(new Point(5, 1));
pq.push(new Point(1, 2));
console.log(pq.pop()); // => {x: 5, y: 1}
console.log(pq.top()); // => {x: 4, y: 6}
pq.push(new Point(3, 4));
pq.push(new Point(6, 5));
console.log(pq.length); // => 5
console.log(pq.top()); // => {x: 6, y: 5}
options.comparator
defines an order of each values in PriorityQueue.
A comparator function format is in according with an argument of Array.prototype.sort
.
⚠️ The predefined order is also the same as Array.prototype.sort
.
Binary heap is a simple and efficient in almost cases.
cons:
merge
operation especiallypros:
merge
operation(constant time)pros:
merge
operation(constant time)Not to use:
import PriorityQueue, {
BinaryHeap,
PairingHeap,
SkewHeap,
} from "priorityqueue";
console.log(PriorityQueue === BinaryHeap); // => true
FAQs
An implementation of Priority Queue
The npm package priorityqueue receives a total of 329 weekly downloads. As such, priorityqueue popularity was classified as not popular.
We found that priorityqueue demonstrated a not healthy version release cadence and project activity because the last version was released 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
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.