Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/robertzhidealx/lytepq
A small and mighty suite of data structures in JavaScript.
https://github.com/robertzhidealx/lytepq
algorithms array binary-heap data-structures disjoint-sets javascript priority-queue queue union-find
Last synced: 14 days ago
JSON representation
A small and mighty suite of data structures in JavaScript.
- Host: GitHub
- URL: https://github.com/robertzhidealx/lytepq
- Owner: robertzhidealx
- License: mit
- Created: 2021-07-15T14:36:08.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-05-27T22:34:48.000Z (over 2 years ago)
- Last Synced: 2024-10-11T21:44:27.127Z (about 1 month ago)
- Topics: algorithms, array, binary-heap, data-structures, disjoint-sets, javascript, priority-queue, queue, union-find
- Language: JavaScript
- Homepage:
- Size: 25.4 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# LytePQ ยท [![npm version](https://badge.fury.io/js/lytepq.svg)](https://badge.fury.io/js/lytepq) [![license](https://img.shields.io/github/license/robertzhidealx/lytepq)](https://github.com/robertzhidealx/lytepq/blob/main/LICENSE) [![PRs welcome](https://img.shields.io/badge/PRs-welcome-cyan)](https://github.com/robertzhidealx/lytepq/pulls)
A small and mighty priority queue library in JavaScript.
Servicing in parallel with **LyteSets** (under maintenance), a JavaScript disjoint sets library.
## Install
Install with either Yarn or NPM via `yarn add lytepq` or `npm install lytepq`.
## LytePQ
### Perks
โ Packed with all basic priority queue operations.
๐ Unopinionated functionality exposure - you decide how to use LytePQ.
๐ป Perfect for competitive programming, online tests, interviews, etc. Dijkstra's in JS made easy!
๐ Comprehensive JSDoc annotations and intellisense.
๐ญ TypeScript support.### Getting Started
Import into your project in the following ways.
```js
import { LytePQ } from "lytepq"; // ESconst { LytePQ } = require("lytepq"); // CommonJS
```### Demo
```js
// LytePQ is a min priority queue by default
const minQ = new LytePQ();
pq.push(2), pq.push(1), pq.push(3);
const smallest = pq.peek(); // returns the smallest item - 1// creates a max priority queue with a custom comparator function
const maxQ = new LytePQ([2, 3, -1], (a, b) => b - a);
const largest = pq.pop(); // removes and returns the largest item - 3// queue items can be objects with a matching comparator function
const objectQ = new LytePQ(
[
[0, 8],
[1, 2],
[2, 7],
],
(a, b) => a[1] - b[1]
);
const smallestObj = objectQ.pop(); // [1, 2]
```### Advanced Use Cases
```js
const minQ = new LytePQ();
pq.push(2), pq.push(1), pq.push(3);
// removes and returns the first instance of the specified item
const specified = pq.pop(2); // 2
```## Contributing
Issues and pull requests are welcome! Contact [me](https://twitter.com/Robert54161541) on Twitter if needed.
## Credits
This library took inspiration from [Vladimir Agafonkin](https://github.com/mourner)'s [tinyqueue](https://github.com/mourner/tinyqueue).