UNPKG

@js-sdsl/queue

Version:

javascript standard data structure library which benchmark against C++ STL

95 lines (89 loc) 2.42 kB
var extendStatics = function(t, n) { extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(t, n) { t.__proto__ = n; } || function(t, n) { for (var e in n) if (Object.prototype.hasOwnProperty.call(n, e)) t[e] = n[e]; }; return extendStatics(t, n); }; function __extends(t, n) { if (typeof n !== "function" && n !== null) throw new TypeError("Class extends value " + String(n) + " is not a constructor or null"); extendStatics(t, n); function __() { this.constructor = t; } t.prototype = n === null ? Object.create(n) : (__.prototype = n.prototype, new __); } var Base = function() { function Base() { this.t = 0; } Object.defineProperty(Base.prototype, "length", { get: function() { return this.t; }, enumerable: false, configurable: true }); Base.prototype.size = function() { return this.t; }; Base.prototype.empty = function() { return this.t === 0; }; return Base; }(); (function(t) { __extends(Container, t); function Container() { return t !== null && t.apply(this, arguments) || this; } return Container; })(Base); var Queue = function(t) { __extends(Queue, t); function Queue(n) { if (n === void 0) { n = []; } var e = t.call(this) || this; e.i = 0; e.u = []; var i = e; n.forEach((function(t) { i.push(t); })); return e; } Queue.prototype.clear = function() { this.u = []; this.t = this.i = 0; }; Queue.prototype.push = function(t) { var n = this.u.length; if (this.i / n > .5 && this.i + this.t >= n && n > 4096) { var e = this.t; for (var i = 0; i < e; ++i) { this.u[i] = this.u[this.i + i]; } this.i = 0; this.u[this.t] = t; } else this.u[this.i + this.t] = t; return ++this.t; }; Queue.prototype.pop = function() { if (this.t === 0) return; var t = this.u[this.i++]; this.t -= 1; return t; }; Queue.prototype.front = function() { if (this.t === 0) return; return this.u[this.i]; }; return Queue; }(Base); export { Queue }; //# sourceMappingURL=index.js.map