# priorityqueuejs

> a simple priority queue data structure

Latest version **2.0.0** (published 2020-05-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install priorityqueuejs
pnpm add priorityqueuejs
yarn add priorityqueuejs
bun add priorityqueuejs
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2020-05-07 |
| First published | 2013-03-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/priorityqueuejs) |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 68 |
| Author | Jano González |
| Maintainers | janogonzalez |
| Keywords | heap, priority, queue, priority queue, data structure |

## Links

- npm: https://www.npmjs.com/package/priorityqueuejs
- Repository: https://github.com/janogonzalez/priorityqueuejs
- Homepage: https://github.com/janogonzalez/priorityqueuejs#readme
- Issues: https://github.com/janogonzalez/priorityqueuejs/issues
- npm.io page: https://npm.io/package/priorityqueuejs

## Alternatives

- [cron](https://npm.io/package/cron.md) — 4.9M weekly downloads
- [@vercel/queue](https://npm.io/package/@vercel/queue.md) — 731.6K weekly downloads
- [create-sonicjs](https://npm.io/package/create-sonicjs.md) — 1.6K weekly downloads
- [@exellix/jobs-api](https://npm.io/package/@exellix/jobs-api.md) — 941 weekly downloads
- [@forwardimpact/libskill](https://npm.io/package/@forwardimpact/libskill.md) — 575 weekly downloads

## Recent versions

- 2.0.0 (latest) — 2020-05-07
- 1.0.0 — 2015-02-23
- 0.2.0 — 2014-02-06
- 0.1.0 — 2013-03-04
- 0.0.2 — 2013-03-02
- 0.0.1 — 2013-03-02

## README

# priorityqueue.js

[![Build Status](https://travis-ci.com/janogonzalez/priorityqueuejs.svg?branch=master)](
  https://travis-ci.com/janogonzalez/priorityqueuejs)

A simple priority queue data structure for Node.js.

## Installation

```
$ npm install priorityqueuejs
```

## Example

```js
var PriorityQueue = require('priorityqueuejs');

var queue = new PriorityQueue(function(a, b) {
  return a.cash - b.cash;
});

queue.enq({ cash: 250, name: 'Valentina' });
queue.enq({ cash: 300, name: 'Jano' });
queue.enq({ cash: 150, name: 'Fran' });
queue.size(); // 3
queue.peek(); // { cash: 300, name: 'Jano' }
queue.deq(); // { cash: 300, name: 'Jano' }
queue.size(); // 2
```

## API

### `PriorityQueue()`

Initializes a new empty `PriorityQueue` wich uses `.DEFAULT_COMPARATOR()` as
the comparator function for its elements.

### `PriorityQueue(comparator)`

Initializes a new empty `PriorityQueue` with uses the given `comparator(a, b)`
function as the comparator for its elements.

The comparator function must return a positive number when `a > b`, 0 when
`a == b` and a negative number when `a < b`.

### `PriorityQueue.DEFAULT_COMPARATOR(a, b)`

Compares two `Number` or `String` objects.

### `PriorityQueue#deq()`

Dequeues the top element of the priority queue.
Throws an `Error` when the queue is empty.

### `PriorityQueue#enq(element)`

Enqueues the `element` at the priority queue and returns its new size.

### `PriorityQueue#forEach(fn)`

Executes `fn` on each element. Just be careful to not modify the priorities,
since the queue won't reorder itself.

### `PriorityQueue#isEmpty()`

Returns whether the priority queue is empty or not.

### `PriorityQueue#peek()`

Peeks at the top element of the priority queue.
Throws an `Error` when the queue is empty.

### `PriorityQueue#size()`

Returns the size of the priority queue.

## Testing

```
$ npm install
$ npm test
```

## Licence

MIT

---
_Source: https://npm.io/package/priorityqueuejs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
