ant-design-x-vue
Version:
Craft AI-driven interfaces effortlessly
73 lines (72 loc) • 2.07 kB
JavaScript
function f(n, e) {
if (n.length !== e.length)
return !1;
for (let s = 0; s < n.length; s++)
if (n[s] !== e[s])
return !1;
return !0;
}
const i = class i {
constructor() {
this.cache = /* @__PURE__ */ new Map(), this.keys = [], this.cacheCallTimes = 0;
}
size() {
return this.keys.length;
}
internalGet(e, s = !1) {
let t = { map: this.cache };
return e.forEach((l) => {
var a;
t ? t = (a = t == null ? void 0 : t.map) == null ? void 0 : a.get(l) : t = void 0;
}), t != null && t.value && s && (t.value[1] = this.cacheCallTimes++), t == null ? void 0 : t.value;
}
get(e) {
var s;
return (s = this.internalGet(e, !0)) == null ? void 0 : s[0];
}
has(e) {
return !!this.internalGet(e);
}
set(e, s) {
if (!this.has(e)) {
if (this.size() + 1 > i.MAX_CACHE_SIZE + i.MAX_CACHE_OFFSET) {
const [l] = this.keys.reduce(
(a, h) => {
const [, r] = a;
return this.internalGet(h)[1] < r ? [h, this.internalGet(h)[1]] : a;
},
[this.keys[0], this.cacheCallTimes]
);
this.delete(l);
}
this.keys.push(e);
}
let t = this.cache;
e.forEach((l, a) => {
if (a === e.length - 1)
t.set(l, { value: [s, this.cacheCallTimes++] });
else {
const h = t.get(l);
h ? h.map || (h.map = /* @__PURE__ */ new Map()) : t.set(l, { map: /* @__PURE__ */ new Map() }), t = t.get(l).map;
}
});
}
deleteByPath(e, s) {
var a;
const t = e.get(s[0]);
if (s.length === 1)
return t.map ? e.set(s[0], { map: t.map }) : e.delete(s[0]), (a = t.value) == null ? void 0 : a[0];
const l = this.deleteByPath(t.map, s.slice(1));
return (!t.map || t.map.size === 0) && !t.value && e.delete(s[0]), l;
}
delete(e) {
if (this.has(e))
return this.keys = this.keys.filter((s) => !f(s, e)), this.deleteByPath(this.cache, e);
}
};
i.MAX_CACHE_SIZE = 20, i.MAX_CACHE_OFFSET = 5;
let u = i;
export {
u as default,
f as sameDerivativeOption
};