@js-sdsl/queue
Version:
javascript standard data structure library which benchmark against C++ STL
62 lines (57 loc) • 1.21 kB
JavaScript
"use strict";
Object.defineProperty(exports, "t", {
value: true
});
class Base {
constructor() {
this.i = 0;
}
get length() {
return this.i;
}
size() {
return this.i;
}
empty() {
return this.i === 0;
}
}
class Queue extends Base {
constructor(t = []) {
super();
this.h = 0;
this.u = [];
const s = this;
t.forEach((function(t) {
s.push(t);
}));
}
clear() {
this.u = [];
this.i = this.h = 0;
}
push(t) {
const s = this.u.length;
if (this.h / s > .5 && this.h + this.i >= s && s > 4096) {
const s = this.i;
for (let t = 0; t < s; ++t) {
this.u[t] = this.u[this.h + t];
}
this.h = 0;
this.u[this.i] = t;
} else this.u[this.h + this.i] = t;
return ++this.i;
}
pop() {
if (this.i === 0) return;
const t = this.u[this.h++];
this.i -= 1;
return t;
}
front() {
if (this.i === 0) return;
return this.u[this.h];
}
}
exports.Queue = Queue;
//# sourceMappingURL=index.js.map