UNPKG

@bravemobile/korea-administrative-area-geo-json-util

Version:
41 lines (40 loc) 1.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LRUMap = void 0; var LRUMap = /** @class */ (function () { // eslint-disable-next-line no-unused-vars function LRUMap(max) { if (max === void 0) { max = 10; } this.max = max; this.cache = new Map(); } LRUMap.prototype.get = function (key) { var item = this.cache.get(key); if (item) { // refresh key this.cache.delete(key); this.cache.set(key, item); } return item; }; LRUMap.prototype.set = function (key, val) { // refresh key if (this.cache.has(key)) this.cache.delete(key); // evict oldest else if (this.cache.size === this.max) this.cache.delete(this.first()); this.cache.set(key, val); }; LRUMap.prototype.keys = function () { return this.cache.keys(); }; LRUMap.prototype.first = function () { return this.keys().next().value; }; LRUMap.prototype.clear = function () { this.cache.clear(); }; return LRUMap; }()); exports.LRUMap = LRUMap;