UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 1.35 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ const t=(t,e)=>{const s=Math.floor(e/8),l=e-8*s,h=t[s],o=1<<l;t[s]=h|o},e=(t,e)=>{const s=Math.floor(e/8),l=e-8*s,h=t[s],o=1<<l,i=(h&o)>>l;return t[s]=h&~o|o*(1-i),i};class s{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(t){const e=this._lookupTable.get(t),s=null!=e?this._getData(e):null;return"object"==typeof s?s:null}set(t,e){const s=this._freeIndex(),l=this._data[s]=null!=e?e:t;return this._lookupTable.set("object"==typeof l?l.cacheKey:l,s),e}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(e){const s=(1<<this._levels)-1,l=e;let h=Math.floor((s+l)/2);for(let o=this._levels-1;o>=0;o--)t(this._index,h),h=Math.floor(h/2);return this._data[e]}_freeIndex(){let t=0,s=0;for(let o=0;o<this._levels;o++)s=e(this._index,t),t=2*t+1+s;const l=t-((1<<this._levels)-1),h=this._data[l];if(h){const t="object"==typeof h?h.cacheKey:h;this._lookupTable.delete(t)}return l}}export{s as PLRUCache};