diff options
| author | LLLL Colonq <llll@colonq> | 2026-07-17 03:10:43 -0400 |
|---|---|---|
| committer | LLLL Colonq <llll@colonq> | 2026-07-17 03:10:43 -0400 |
| commit | 07a36f2b38a5cba402ebc5158710f5a85f443456 (patch) | |
| tree | f28855384eadc73f49cc1a707a73896f87bc5530 /2026/games_submissions/liquidcake/queue.mjs | |
| parent | 951b316773265052fbc5fa546bbcf31bef277062 (diff) | |
Post-stream update
Diffstat (limited to '2026/games_submissions/liquidcake/queue.mjs')
| -rw-r--r-- | 2026/games_submissions/liquidcake/queue.mjs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/2026/games_submissions/liquidcake/queue.mjs b/2026/games_submissions/liquidcake/queue.mjs new file mode 100644 index 0000000..e6c3efe --- /dev/null +++ b/2026/games_submissions/liquidcake/queue.mjs @@ -0,0 +1,30 @@ +export class Queue { + /* Structure is a (hopefully short) list of (longer) lists. + * Queue to the last list. + * Hold index into first list. + */ + length = 0; + index = -1; + content = [[]]; + max_len = 100; + push(x) { + let content = this.content; + if (content[content.length - 1].length > this.max_len) { + content.push([]); + } + content[content.length - 1].push(x); + this.length += 1; + } + pop() { + this.index += 1; + if (this.index >= this.content[0].length) { + if (this.content.length == 1) { + throw("empty"); + } + this.content.shift(); + this.index = 0; + } + this.length -= 1; + return this.content[0][this.index]; + } +} |
