12345 |
- /*
- All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- See https://js.arcgis.com/4.24/esri/copyright.txt for details.
- */
- import{isSome as t}from"./maybe.js";const e=(t,e)=>{const s=Math.floor(e/8),l=e-8*s,o=t[s],h=1<<l;t[s]=o|h},s=(t,e)=>{const s=Math.floor(e/8),l=e-8*s,o=t[s],h=1<<l,i=(o&h)>>l;return t[s]=o&~h|h*(1-i),i};class l{constructor(t){this._size=t,this._levels=Math.log2(this._size),this._index=new Uint8Array(Math.ceil(t/8)),this._data=new Array(t),this._lookupTable=new Map}with(t,e){return this.has(e)?this.get(e):this.set(e,t(e))}has(t){return this._lookupTable.has(t)}get(e){const s=this._lookupTable.get(e),l=t(s)?this._getData(s):null;return"object"==typeof l?l:null}set(e,s){const l=this._freeIndex(),o=this._data[l]=t(s)?s:e;return this._lookupTable.set("object"==typeof o?o.cacheKey:o,l),s}clear(){for(let t=0;t<this._index.length;t++)this._index[t]=0;for(let t=0;t<this._data.length;t++)this._data[t]=null;this._lookupTable.clear()}_getData(t){const s=(1<<this._levels)-1,l=t;let o=Math.floor((s+l)/2);for(let h=this._levels-1;h>=0;h--)e(this._index,o),o=Math.floor(o/2);return this._data[t]}_freeIndex(){let t=0,e=0;for(let h=0;h<this._levels;h++)e=s(this._index,t),t=2*t+1+e;const l=t-((1<<this._levels)-1),o=this._data[l];if(o){const t="object"==typeof o?o.cacheKey:o;this._lookupTable.delete(t)}return l}}export{l as PLRUCache};
|