source: node_modules/recharts/es6/util/LRUCache.js@ ba17441

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

Added visualizations

  • Property mode set to 100644
File size: 1.3 KB
Line 
1function _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; }
2function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
3function _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); }
4/**
5 * Simple LRU (Least Recently Used) cache implementation
6 */
7export class LRUCache {
8 constructor(maxSize) {
9 _defineProperty(this, "cache", new Map());
10 this.maxSize = maxSize;
11 }
12 get(key) {
13 var value = this.cache.get(key);
14 if (value !== undefined) {
15 this.cache.delete(key);
16 this.cache.set(key, value);
17 }
18 return value;
19 }
20 set(key, value) {
21 if (this.cache.has(key)) {
22 this.cache.delete(key);
23 } else if (this.cache.size >= this.maxSize) {
24 var firstKey = this.cache.keys().next().value;
25 if (firstKey != null) {
26 this.cache.delete(firstKey);
27 }
28 }
29 this.cache.set(key, value);
30 }
31 clear() {
32 this.cache.clear();
33 }
34 size() {
35 return this.cache.size;
36 }
37}
Note: See TracBrowser for help on using the repository browser.