1.0.3 • Published 2 years ago

@decoy9697/priority-queue v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Priority Queue

Downloads Size

npm install @decoy9697/priority-queue
import PQ, { LOW_FIRST } from "@decoy9697/priority-queue";

const pq = new PQ({ sort: LOW_FIRST });

// The number influences priority
// - lower takes precedence (given LOW_FIRST, otherwise use HIGH_FIRST)
// - with equal numbers, recency of insert takes precendence
pq.insert("🌵", 5);
pq.insert("🌿", 10);
pq.insert("🌴", 3);

// .peek() gives the item with the lowest number, but does not dequeue it
pq.peek(); // 🌴
pq.peek(); // 🌴

// .pop() gives the item with the lowest number, dequeuing it
pq.pop(); // 🌴
pq.pop(); // 🌵
pq.pop(); // 🌿
pq.pop(); // undefined

// .isEmpty() returns a boolean, true given it is empty
pq.isEmpty(); // true
1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

1.0.3

2 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.0

3 years ago