diff options
author | Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> | 2022-09-17 19:39:05 +0800 |
---|---|---|
committer | Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> | 2022-09-17 19:39:05 +0800 |
commit | 431e4fc9d1657a50ebc34b8ac24f9bfaea06417f (patch) | |
tree | 5987bb14f38d2999c682970429f34b41eb3e5826 /datastructures | |
parent | e73f2efdf0f50aa775c540317394d46428e9704f (diff) | |
download | SoopyV2-431e4fc9d1657a50ebc34b8ac24f9bfaea06417f.tar.gz SoopyV2-431e4fc9d1657a50ebc34b8ac24f9bfaea06417f.tar.bz2 SoopyV2-431e4fc9d1657a50ebc34b8ac24f9bfaea06417f.zip |
Initial move to babel + change fetch to use async/await
Diffstat (limited to 'datastructures')
-rw-r--r-- | datastructures/flatqueue.js | 83 |
1 files changed, 0 insertions, 83 deletions
diff --git a/datastructures/flatqueue.js b/datastructures/flatqueue.js deleted file mode 100644 index a011476..0000000 --- a/datastructures/flatqueue.js +++ /dev/null @@ -1,83 +0,0 @@ - -//SEE https://github.com/mourner/flatqueue - -export default class FlatQueue { - - constructor() { - this.ids = []; - this.values = []; - this.length = 0; - } - - clear() { - this.length = 0; - } - - push(id, value) { - let pos = this.length++; - - while (pos > 0) { - let parent = ((pos + 1) >>> 1) - 1; - let parentValue = this.values[parent]; - if (value >= parentValue) break; - this.ids[pos] = this.ids[parent]; - this.values[pos] = parentValue; - pos = parent; - } - - this.ids[pos] = id; - this.values[pos] = value; - } - - pop() { - if (this.length === 0) return undefined; - - let top = this.ids[0]; - this.length--; - - if (this.length > 0) { - let id = this.ids[0] = this.ids[this.length]; - let value = this.values[0] = this.values[this.length]; - let halfLength = this.length >> 1; - let pos = 0; - - while (pos < halfLength) { - let left = (pos << 1) + 1; - let right = left + 1; - let bestIndex = this.ids[left]; - let bestValue = this.values[left]; - let rightValue = this.values[right]; - - if (right < this.length && rightValue < bestValue) { - left = right; - bestIndex = this.ids[right]; - bestValue = rightValue; - } - if (bestValue >= value) break; - - this.ids[pos] = bestIndex; - this.values[pos] = bestValue; - pos = left; - } - - this.ids[pos] = id; - this.values[pos] = value; - } - - return top; - } - - peek() { - if (this.length === 0) return undefined; - return this.ids[0]; - } - - peekValue() { - if (this.length === 0) return undefined; - return this.values[0]; - } - - shrink() { - this.ids.length = this.values.length = this.length; - } -}
\ No newline at end of file |