function u(c,e){if(c.length!==e.length)return!1;for(let s=0;s<c.length;s++)if(c[s]!==e[s])return!1;return!0}class n{static MAX_CACHE_SIZE=20;static MAX_CACHE_OFFSET=5;cache;keys;cacheCallTimes;constructor(){this.cache=new Map,this.keys=[],this.cacheCallTimes=0}size(){return this.keys.length}internalGet(e,s=!1){let t={map:this.cache};return e.forEach(a=>{t?t=t?.map?.get(a):t=void 0}),t?.value&&s&&(t.value[1]=this.cacheCallTimes++),t?.value}get(e){return this.internalGet(e,!0)?.[0]}has(e){return!!this.internalGet(e)}set(e,s){if(!this.has(e)){if(this.size()+1>n.MAX_CACHE_SIZE+n.MAX_CACHE_OFFSET){const[a]=this.keys.reduce((h,l)=>{const[,i]=h;return this.internalGet(l)[1]<i?[l,this.internalGet(l)[1]]:h},[this.keys[0],this.cacheCallTimes]);this.delete(a)}this.keys.push(e)}let t=this.cache;e.forEach((a,h)=>{if(h===e.length-1)t.set(a,{value:[s,this.cacheCallTimes++]});else{const l=t.get(a);l?l.map||(l.map=new Map):t.set(a,{map:new Map}),t=t.get(a).map}})}deleteByPath(e,s){const t=e.get(s[0]);if(s.length===1)return t.map?e.set(s[0],{map:t.map}):e.delete(s[0]),t.value?.[0];const a=this.deleteByPath(t.map,s.slice(1));return(!t.map||t.map.size===0)&&!t.value&&e.delete(s[0]),a}delete(e){if(this.has(e))return this.keys=this.keys.filter(s=>!u(s,e)),this.deleteByPath(this.cache,e)}}export{n as default,u as sameDerivativeOption};
