ts-edifact
Version:
Edifact parser library
36 lines • 991 B
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Cache = void 0;
class Cache {
constructor(size) {
this.data = {};
this.queue = new Array(size);
this.begin = 0;
this.end = size;
}
insert(key, value) {
if (!this.contains(key)) {
if ((this.end + 1 - this.begin) % this.queue.length === 0) {
delete this.data[this.queue[this.begin]];
this.begin = (this.begin + 1) % this.queue.length;
}
this.end = (this.end + 1) % this.queue.length;
this.queue[this.end] = key;
}
this.data[key] = value;
}
contains(key) {
if (Object.prototype.hasOwnProperty.call(this.data, key)) {
return true;
}
return false;
}
get(key) {
return this.data[key];
}
length() {
return this.queue.length;
}
}
exports.Cache = Cache;
//# sourceMappingURL=cache.js.map