source: node_modules/recharts/lib/util/LRUCache.js

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 1.4 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.LRUCache = void 0;
7function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
8function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
9function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
10/**
11 * Simple LRU (Least Recently Used) cache implementation
12 */
13class LRUCache {
14 constructor(maxSize) {
15 _defineProperty(this, "cache", new Map());
16 this.maxSize = maxSize;
17 }
18 get(key) {
19 var value = this.cache.get(key);
20 if (value !== undefined) {
21 this.cache.delete(key);
22 this.cache.set(key, value);
23 }
24 return value;
25 }
26 set(key, value) {
27 if (this.cache.has(key)) {
28 this.cache.delete(key);
29 } else if (this.cache.size >= this.maxSize) {
30 var firstKey = this.cache.keys().next().value;
31 if (firstKey != null) {
32 this.cache.delete(firstKey);
33 }
34 }
35 this.cache.set(key, value);
36 }
37 clear() {
38 this.cache.clear();
39 }
40 size() {
41 return this.cache.size;
42 }
43}
44exports.LRUCache = LRUCache;
Note: See TracBrowser for help on using the repository browser.