1.3.9 • Published 7 months ago

pqjs v1.3.9

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

Pq.js provides a fast, straightforward priority queue to manage data based on priority. Ideal for sorting, task scheduling, or implementing priority-based logic in your app.

  • ⚡ Simple and fast priority queue operations.
  • 🔽🔼 Supports both Min-Heap and Max-Heap configurations.
  • 🌱 No dependencies.

Perfect for anyone needing a priority queue implementation in JavaScript.

Installation

npm install pqjs

Usage

Importing the PriorityQueue

import {PriorityQueue} from "pqjs"

Creating a PriorityQueue

const pq = new PriorityQueue()

Creating a PriorityQueue with Initial Values

const initialValues = [10, 5, 20]
const pq = new PriorityQueue(initialValues)

Adding Elements

pq.push(10)
pq.push(5)
pq.push(20)

Accessing the Top Element

console.log(pq.top()) // 20 for Max-Heap by default

Removing the Top Element

console.log(pq.pop()) // 20

Checking if the Queue is Empty

console.log(pq.empty()) // false

Clearing the Queue

pq.clear()
console.log(pq.empty()) // true

Converting to an Array

console.log(pq.toArray()) // []

Using a Comparator for Min-Heap

const minHeapComparator = (a, b) => b - a
const minHeap = new PriorityQueue([], minHeapComparator)

minHeap.push(10)
minHeap.push(5)
minHeap.push(20)

console.log(minHeap.pop()) // 5 for Min-Heap
console.log(minHeap.pop()) // 10 for Min-Heap
console.log(minHeap.pop()) // 20 for Min-Heap

License

MIT © 2025 Vusal Huseynov

1.3.9

7 months ago

1.3.8

7 months ago

1.3.7

7 months ago

1.3.6

7 months ago

1.3.5

7 months ago

1.3.4

7 months ago

1.3.3

7 months ago

1.3.2

7 months ago

1.3.1

7 months ago

1.3.0

7 months ago

1.2.9

7 months ago

1.2.8

7 months ago

1.2.7

7 months ago

1.2.4

7 months ago

1.2.2

7 months ago

1.2.1

7 months ago

1.1.1

7 months ago

1.0.0

7 months ago