Initial commit
This commit is contained in:
15
node_modules/tinyqueue/LICENSE
generated
vendored
Normal file
15
node_modules/tinyqueue/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2017, Vladimir Agafonkin
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any purpose
|
||||
with or without fee is hereby granted, provided that the above copyright notice
|
||||
and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
||||
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
||||
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
||||
THIS SOFTWARE.
|
||||
59
node_modules/tinyqueue/README.md
generated
vendored
Normal file
59
node_modules/tinyqueue/README.md
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
## tinyqueue
|
||||
|
||||
The smallest and simplest binary heap priority queue in JavaScript.
|
||||
|
||||
```js
|
||||
// create an empty priority queue
|
||||
var queue = new TinyQueue();
|
||||
|
||||
// add some items
|
||||
queue.push(7);
|
||||
queue.push(5);
|
||||
queue.push(10);
|
||||
|
||||
// remove the top item
|
||||
var top = queue.pop(); // returns 5
|
||||
|
||||
// return the top item (without removal)
|
||||
top = queue.peek(); // returns 7
|
||||
|
||||
// get queue length
|
||||
queue.length; // returns 2
|
||||
|
||||
// create a priority queue from an existing array (modifies the array)
|
||||
queue = new TinyQueue([7, 5, 10]);
|
||||
|
||||
// pass a custom item comparator as a second argument
|
||||
queue = new TinyQueue([{value: 5}, {value: 7}], function (a, b) {
|
||||
return a.value - b.value;
|
||||
});
|
||||
|
||||
// turn a queue into a sorted array
|
||||
var array = [];
|
||||
while (queue.length) array.push(queue.pop());
|
||||
```
|
||||
|
||||
For a faster number-based queue, see [flatqueue](https://github.com/mourner/flatqueue).
|
||||
|
||||
### Install
|
||||
|
||||
Install using NPM (`npm install tinyqueue`) or Yarn (`yarn add tinyqueue`), then:
|
||||
|
||||
```js
|
||||
// import as an ES module
|
||||
import TinyQueue from 'tinyqueue';
|
||||
|
||||
// or require in Node / Browserify
|
||||
const TinyQueue = require('tinyqueue');
|
||||
```
|
||||
|
||||
Or use a browser build directly:
|
||||
|
||||
```html
|
||||
<script src="https://unpkg.com/tinyqueue@2.0.0/tinyqueue.min.js"></script>
|
||||
```
|
||||
|
||||
### Thanks
|
||||
|
||||
Inspired by [js-priority-queue](https://github.com/adamhooper/js-priority-queue)
|
||||
by [Adam Hooper](https://github.com/adamhooper).
|
||||
10
node_modules/tinyqueue/index.d.ts
generated
vendored
Normal file
10
node_modules/tinyqueue/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
export declare type Comparator<T> = (a: T, b: T) => number;
|
||||
|
||||
export default class TinyQueue<T> {
|
||||
public data : T[];
|
||||
public length : number;
|
||||
constructor (items? : T[], compare? : Comparator<T>);
|
||||
peek () : T | undefined;
|
||||
pop () : T | undefined;
|
||||
push (item: T) : void;
|
||||
}
|
||||
71
node_modules/tinyqueue/index.js
generated
vendored
Normal file
71
node_modules/tinyqueue/index.js
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
|
||||
export default class TinyQueue {
|
||||
constructor(data = [], compare = (a, b) => (a < b ? -1 : a > b ? 1 : 0)) {
|
||||
this.data = data;
|
||||
this.length = this.data.length;
|
||||
this.compare = compare;
|
||||
|
||||
if (this.length > 0) {
|
||||
for (let i = (this.length >> 1) - 1; i >= 0; i--) this._down(i);
|
||||
}
|
||||
}
|
||||
|
||||
push(item) {
|
||||
this.data.push(item);
|
||||
this._up(this.length++);
|
||||
}
|
||||
|
||||
pop() {
|
||||
if (this.length === 0) return undefined;
|
||||
|
||||
const top = this.data[0];
|
||||
const bottom = this.data.pop();
|
||||
|
||||
if (--this.length > 0) {
|
||||
this.data[0] = bottom;
|
||||
this._down(0);
|
||||
}
|
||||
|
||||
return top;
|
||||
}
|
||||
|
||||
peek() {
|
||||
return this.data[0];
|
||||
}
|
||||
|
||||
_up(pos) {
|
||||
const {data, compare} = this;
|
||||
const item = data[pos];
|
||||
|
||||
while (pos > 0) {
|
||||
const parent = (pos - 1) >> 1;
|
||||
const current = data[parent];
|
||||
if (compare(item, current) >= 0) break;
|
||||
data[pos] = current;
|
||||
pos = parent;
|
||||
}
|
||||
|
||||
data[pos] = item;
|
||||
}
|
||||
|
||||
_down(pos) {
|
||||
const {data, compare} = this;
|
||||
const halfLength = this.length >> 1;
|
||||
const item = data[pos];
|
||||
|
||||
while (pos < halfLength) {
|
||||
let bestChild = (pos << 1) + 1; // initially it is the left child
|
||||
const right = bestChild + 1;
|
||||
|
||||
if (right < this.length && compare(data[right], data[bestChild]) < 0) {
|
||||
bestChild = right;
|
||||
}
|
||||
if (compare(data[bestChild], item) >= 0) break;
|
||||
|
||||
data[pos] = data[bestChild];
|
||||
pos = bestChild;
|
||||
}
|
||||
|
||||
data[pos] = item;
|
||||
}
|
||||
}
|
||||
39
node_modules/tinyqueue/package.json
generated
vendored
Normal file
39
node_modules/tinyqueue/package.json
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"name": "tinyqueue",
|
||||
"version": "3.0.0",
|
||||
"description": "The smallest and simplest JavaScript priority queue",
|
||||
"type": "module",
|
||||
"main": "index.js",
|
||||
"module": "index.js",
|
||||
"types": "index.d.ts",
|
||||
"scripts": {
|
||||
"lint": "eslint *.js",
|
||||
"pretest": "npm run lint",
|
||||
"test": "node --test",
|
||||
"bench": "node bench.js",
|
||||
"prepublishOnly": "npm test"
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/mourner/tinyqueue.git"
|
||||
},
|
||||
"keywords": [
|
||||
"queue",
|
||||
"priority",
|
||||
"binary heap",
|
||||
"data structures"
|
||||
],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"bugs": {
|
||||
"url": "https://github.com/mourner/tinyqueue/issues"
|
||||
},
|
||||
"homepage": "https://github.com/mourner/tinyqueue",
|
||||
"devDependencies": {
|
||||
"eslint": "^9.6.0",
|
||||
"eslint-config-mourner": "^4.0.1"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user