@makakwastaken/ts-edifact
Version:
Edifact parser library
57 lines • 1.68 kB
JavaScript
"use strict";
/**
* @author Roman Vottner
* @copyright 2020 Roman Vottner
* @license Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Cache = void 0;
class Cache {
data;
queue;
begin;
end;
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