eosplayer
Version:
eosplayer is the glue layer of eosjs, which is packaged based on eosjs and provides better usability for the application layer. It can be used on browsers already installed scatter or in Dapp wallets.
103 lines • 3.02 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var CQueue = /** @class */ (function () {
function CQueue(maxSize, overflow) {
if (maxSize === void 0) { maxSize = 1000; }
if (overflow === void 0) { overflow = false; }
this.maxSize = maxSize;
this.overflow = overflow;
this.vernierStart = 0;
this.vernierEnd = 0;
this.body = [];
}
Object.defineProperty(CQueue.prototype, "preferHead", {
get: function () {
return (this.full ? this.vernierEnd - this.maxSize : this.vernierStart);
},
enumerable: true,
configurable: true
});
Object.defineProperty(CQueue.prototype, "preferTail", {
get: function () {
return this.vernierEnd - 1;
},
enumerable: true,
configurable: true
});
Object.defineProperty(CQueue.prototype, "head", {
get: function () {
return this.preferHead % this.maxSize;
},
enumerable: true,
configurable: true
});
Object.defineProperty(CQueue.prototype, "tail", {
get: function () {
return this.preferTail % this.maxSize;
},
enumerable: true,
configurable: true
});
Object.defineProperty(CQueue.prototype, "length", {
get: function () {
return this.vernierEnd - this.vernierStart;
},
enumerable: true,
configurable: true
});
Object.defineProperty(CQueue.prototype, "full", {
get: function () {
return this.length >= this.maxSize;
},
enumerable: true,
configurable: true
});
Object.defineProperty(CQueue.prototype, "empty", {
get: function () {
return this.length <= 0;
},
enumerable: true,
configurable: true
});
CQueue.prototype.push = function (element) {
if (this.full && !this.overflow) {
return false;
}
this.vernierEnd++;
this.body[this.tail] = element;
return true;
};
CQueue.prototype.shift = function () {
if (this.empty) {
return false;
}
if (this.full) {
this.vernierStart = this.preferHead;
}
this.vernierStart++;
return true;
};
CQueue.prototype.front = function () {
if (this.empty) {
return this.body[this.head];
}
};
CQueue.prototype.rear = function () {
if (this.empty) {
return this.body[this.tail];
}
};
CQueue.prototype.toArray = function () {
var head = this.head;
var tail = this.tail;
if (head <= tail) {
return this.body.slice(head, tail + 1);
}
else if (head > tail) {
return this.body.slice(head, this.body.length).concat(this.body.slice(0, tail + 1));
}
};
return CQueue;
}());
exports.CQueue = CQueue;
//# sourceMappingURL=cQueue.js.map