Erster Commit
This commit is contained in:
36
node_modules/ts-edifact/lib/cache.js
generated
vendored
Normal file
36
node_modules/ts-edifact/lib/cache.js
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
"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
|
||||
Reference in New Issue
Block a user