summaryrefslogtreecommitdiff
path: root/lib/priority_queue.js
diff options
context:
space:
mode:
authorJulien Dessaux2023-07-01 23:13:13 +0200
committerJulien Dessaux2023-07-01 23:13:13 +0200
commit36cc33f9e96a38ecea98ac8d26275b4828347d80 (patch)
tree653dcea7e656ec815fc0a1fa5664a6b89abccaa3 /lib/priority_queue.js
parentFixed prepared statements (diff)
downloadspacetraders-36cc33f9e96a38ecea98ac8d26275b4828347d80.tar.gz
spacetraders-36cc33f9e96a38ecea98ac8d26275b4828347d80.tar.bz2
spacetraders-36cc33f9e96a38ecea98ac8d26275b4828347d80.zip
Moved the nodejs agent to its own subfolder to make room for my haskell agent
Diffstat (limited to 'lib/priority_queue.js')
-rw-r--r--lib/priority_queue.js39
1 files changed, 0 insertions, 39 deletions
diff --git a/lib/priority_queue.js b/lib/priority_queue.js
deleted file mode 100644
index da526b2..0000000
--- a/lib/priority_queue.js
+++ /dev/null
@@ -1,39 +0,0 @@
-export class QElement {
- constructor(element, priority) {
- this.element = element;
- this.priority = priority;
- }
-}
-
-export class PriorityQueue {
- constructor(elt) {
- this.items = [];
- if (elt !== undefined) {
- this.enqueue(elt, 0);
- }
- }
-
- enqueue(element, priority) {
- let qElement = new QElement(element, priority);
-
- for (let i = 0; i < this.items.length; ++i) {
- if (this.items[i].priority > qElement.priority) {
- this.items.splice(i, 0, qElement);
- return;
- }
- }
- this.items.push(qElement);
- }
- dequeue() {
- return this.items.shift(); // we would use pop to get the highest priority, shift() gives us the lowest priority
- }
- front() {
- return this.items[0];
- }
- rear() {
- return this.items[this.items.length - 1];
- }
- isEmpty() {
- return this.items.length === 0;
- }
-}