summaryrefslogtreecommitdiff
path: root/cli/js/web/streams/queue.ts
diff options
context:
space:
mode:
authorKitson Kelly <me@kitsonkelly.com>2020-04-23 00:06:51 +1000
committerGitHub <noreply@github.com>2020-04-22 10:06:51 -0400
commit8bcfc03d71cbd2cfd7ab68035ec0968d9f93b5b8 (patch)
treee1769ca51d2afde57ae18eb25b7a91388fcbf00a /cli/js/web/streams/queue.ts
parentb270d6c8d090669601465f8c9c94512d6c6a07d4 (diff)
Rewrite streams (#4842)
Diffstat (limited to 'cli/js/web/streams/queue.ts')
-rw-r--r--cli/js/web/streams/queue.ts58
1 files changed, 0 insertions, 58 deletions
diff --git a/cli/js/web/streams/queue.ts b/cli/js/web/streams/queue.ts
deleted file mode 100644
index 16e3eafe4..000000000
--- a/cli/js/web/streams/queue.ts
+++ /dev/null
@@ -1,58 +0,0 @@
-// Forked from https://github.com/stardazed/sd-streams/tree/8928cf04b035fd02fb1340b7eb541c76be37e546
-// Copyright (c) 2018-Present by Arthur Langereis - @zenmumbler MIT
-
-const CHUNK_SIZE = 16384;
-
-export interface Queue<T> {
- push(t: T): void;
- shift(): T | undefined;
- front(): T | undefined;
- readonly length: number;
-}
-
-export class QueueImpl<T> implements Queue<T> {
- private readonly chunks_: T[][];
- private readChunk_: T[];
- private writeChunk_: T[];
- private length_: number;
-
- constructor() {
- this.chunks_ = [[]];
- this.readChunk_ = this.writeChunk_ = this.chunks_[0];
- this.length_ = 0;
- }
-
- push(t: T): void {
- this.writeChunk_.push(t);
- this.length_ += 1;
- if (this.writeChunk_.length === CHUNK_SIZE) {
- this.writeChunk_ = [];
- this.chunks_.push(this.writeChunk_);
- }
- }
-
- front(): T | undefined {
- if (this.length_ === 0) {
- return undefined;
- }
- return this.readChunk_[0];
- }
-
- shift(): T | undefined {
- if (this.length_ === 0) {
- return undefined;
- }
- const t = this.readChunk_.shift();
-
- this.length_ -= 1;
- if (this.readChunk_.length === 0 && this.readChunk_ !== this.writeChunk_) {
- this.chunks_.shift();
- this.readChunk_ = this.chunks_[0];
- }
- return t;
- }
-
- get length(): number {
- return this.length_;
- }
-}