first
This commit is contained in:
32
node_modules/p-queue/dist/priority-queue.js
generated
vendored
Normal file
32
node_modules/p-queue/dist/priority-queue.js
generated
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const lower_bound_1 = require("./lower-bound");
|
||||
class PriorityQueue {
|
||||
constructor() {
|
||||
this._queue = [];
|
||||
}
|
||||
enqueue(run, options) {
|
||||
options = Object.assign({ priority: 0 }, options);
|
||||
const element = {
|
||||
priority: options.priority,
|
||||
run
|
||||
};
|
||||
if (this.size && this._queue[this.size - 1].priority >= options.priority) {
|
||||
this._queue.push(element);
|
||||
return;
|
||||
}
|
||||
const index = lower_bound_1.default(this._queue, element, (a, b) => b.priority - a.priority);
|
||||
this._queue.splice(index, 0, element);
|
||||
}
|
||||
dequeue() {
|
||||
const item = this._queue.shift();
|
||||
return item === null || item === void 0 ? void 0 : item.run;
|
||||
}
|
||||
filter(options) {
|
||||
return this._queue.filter((element) => element.priority === options.priority).map((element) => element.run);
|
||||
}
|
||||
get size() {
|
||||
return this._queue.length;
|
||||
}
|
||||
}
|
||||
exports.default = PriorityQueue;
|
||||
Reference in New Issue
Block a user