UNPKG

1.13 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "t", {
4 value: true
5});
6
7exports.default = void 0;
8
9var _ContainerBase = require("../ContainerBase");
10
11class Queue extends _ContainerBase.Base {
12 constructor(t = []) {
13 super();
14 this.j = 0;
15 this.q = [];
16 const s = this;
17 t.forEach((function(t) {
18 s.push(t);
19 }));
20 }
21 clear() {
22 this.q = [];
23 this.i = this.j = 0;
24 }
25 push(t) {
26 const s = this.q.length;
27 if (this.j / s > .5 && this.j + this.i >= s && s > 4096) {
28 const s = this.i;
29 for (let t = 0; t < s; ++t) {
30 this.q[t] = this.q[this.j + t];
31 }
32 this.j = 0;
33 this.q[this.i] = t;
34 } else this.q[this.j + this.i] = t;
35 return ++this.i;
36 }
37 pop() {
38 if (this.i === 0) return;
39 const t = this.q[this.j++];
40 this.i -= 1;
41 return t;
42 }
43 front() {
44 if (this.i === 0) return;
45 return this.q[this.j];
46 }
47}
48
49var _default = Queue;
50
51exports.default = _default;
52//# sourceMappingURL=Queue.js.map