Comparing version 0.3.0 to 0.3.1
@@ -1,1 +0,1 @@ | ||
var createLRU=k=>{var{max:i,onEviction:f,debug:T}=k;if(!(Number.isInteger(i)&&i>0))throw new TypeError("`max` must be a positive integer");var d=0,b=0,t=0,s=[],y=new Map,l=new Array(i).fill(void 0),n=new Array(i).fill(void 0),m=new Array(i).fill(0),v=new Array(i).fill(0),p=e=>{if(e!==t){var r=m[e],u=v[e];e===b?b=r:u!==0&&(m[u]=r),r!==0&&(v[r]=u),m[t]=e,v[e]=t,m[e]=0,t=e}},A=()=>{var e=b,r=l[e];return f==null||f(r,n[e]),y.delete(r),l[e]=void 0,n[e]=void 0,b=m[e],b!==0&&(v[b]=0),d--,d===0&&(b=t=0),e};return{set(e,r){var u=y.get(e);u===void 0?(u=d===i?A():s.length>0?s.pop():d,y.set(e,u),l[u]=e,d++):f==null||f(e,n[u]),n[u]=r,d===1?b=t=u:p(u)},get(e){var r=y.get(e);if(r!==void 0)return p(r),n[r]},peek:e=>{var r=y.get(e);return r!==void 0?n[r]:void 0},has:e=>y.has(e),*keys(){for(var e=t,r=0;r<d;r++)yield l[e],e=v[e]},*values(){for(var e=t,r=0;r<d;r++)yield n[e],e=v[e]},*entries(){for(var e=t,r=0;r<d;r++)yield[l[e],n[e]],e=v[e]},forEach:e=>{for(var r=t,u=0;u<d;u++){var o=l[r],g=n[r];e(g,o),r=v[r]}},delete(e){var r=y.get(e);return r!==void 0?(f==null||f(e,n[r]),y.delete(e),s.push(r),l[r]=void 0,n[r]=void 0,d--,!0):!1},evict:e=>{for(var r=Math.min(e,d);r>0;)A(),r--},clear(){for(var e of y.values())f==null||f(l[e],n[e]);y.clear(),l.fill(void 0),n.fill(void 0),s=[],d=0,b=t=0},resize:e=>{if(!(Number.isInteger(e)&&e>0))throw new TypeError("`max` must be a positive integer");if(e!==i){if(e<i){for(var r=t,u=Math.min(d,e),o=d-u,g=new Array(e),K=new Array(e),I=new Array(e),V=new Array(e),a=1;a<=o;a++)f==null||f(l[a],n[a]);for(var a=u-1;a>=0;a--)g[a]=l[r],K[a]=n[r],I[a]=a+1,V[a]=a-1,y.set(g[a],a),r=v[r];b=0,t=u-1,d=u,l.length=e,n.length=e,m.length=e,v.length=e;for(var a=0;a<u;a++)l[a]=g[a],n[a]=K[a],m[a]=I[a],v[a]=V[a];s=[];for(var a=u;a<e;a++)s.push(a)}else{var h=e-i;l.push(...new Array(h).fill(void 0)),n.push(...new Array(h).fill(void 0)),m.push(...new Array(h).fill(0)),v.push(...new Array(h).fill(0))}i=e}},get max(){return i},get size(){return d},get available(){return i-d},get debug(){return T===!0?{tail:t,head:b,keyMap:y,keyList:l,valList:n,prev:v,next:m,free:s}:void 0}}}; | ||
var createLRU=k=>{var{max:t,onEviction:d}=k;if(!(Number.isInteger(t)&&t>0))throw new TypeError("`max` must be a positive integer");var n=0,m=0,i=0,b=[],y=new Map,l=new Array(t).fill(void 0),f=new Array(t).fill(void 0),s=new Array(t).fill(0),v=new Array(t).fill(0),p=e=>{if(e!==i){var r=s[e],u=v[e];e===m?m=r:u!==0&&(s[u]=r),r!==0&&(v[r]=u),s[i]=e,v[e]=i,s[e]=0,i=e}},A=()=>{var e=m,r=l[e];return d==null||d(r,f[e]),y.delete(r),l[e]=void 0,f[e]=void 0,m=s[e],m!==0&&(v[m]=0),n--,n===0&&(m=i=0),e};return{set(e,r){var u=y.get(e);u===void 0?(u=n===t?A():b.length>0?b.pop():n,y.set(e,u),l[u]=e,n++):d==null||d(e,f[u]),f[u]=r,n===1?m=i=u:p(u)},get(e){var r=y.get(e);if(r!==void 0)return p(r),f[r]},peek:e=>{var r=y.get(e);return r!==void 0?f[r]:void 0},has:e=>y.has(e),*keys(){for(var e=i,r=0;r<n;r++)yield l[e],e=v[e]},*values(){for(var e=i,r=0;r<n;r++)yield f[e],e=v[e]},*entries(){for(var e=i,r=0;r<n;r++)yield[l[e],f[e]],e=v[e]},forEach:e=>{for(var r=i,u=0;u<n;u++){var o=l[r],h=f[r];e(h,o),r=v[r]}},delete(e){var r=y.get(e);return r!==void 0?(d==null||d(e,f[r]),y.delete(e),b.push(r),l[r]=void 0,f[r]=void 0,n--,!0):!1},evict:e=>{for(var r=Math.min(e,n);r>0;)A(),r--},clear(){for(var e of y.values())d==null||d(l[e],f[e]);y.clear(),l.fill(void 0),f.fill(void 0),b=[],n=0,m=i=0},resize:e=>{if(!(Number.isInteger(e)&&e>0))throw new TypeError("`max` must be a positive integer");if(e!==t){if(e<t){for(var r=i,u=Math.min(n,e),o=n-u,h=new Array(e),K=new Array(e),I=new Array(e),V=new Array(e),a=1;a<=o;a++)d==null||d(l[a],f[a]);for(var a=u-1;a>=0;a--)h[a]=l[r],K[a]=f[r],I[a]=a+1,V[a]=a-1,y.set(h[a],a),r=v[r];m=0,i=u-1,n=u,l.length=e,f.length=e,s.length=e,v.length=e;for(var a=0;a<u;a++)l[a]=h[a],f[a]=K[a],s[a]=I[a],v[a]=V[a];b=[];for(var a=u;a<e;a++)b.push(a)}else{var g=e-t;l.push(...new Array(g).fill(void 0)),f.push(...new Array(g).fill(void 0)),s.push(...new Array(g).fill(0)),v.push(...new Array(g).fill(0))}t=e}},get max(){return t},get size(){return n},get available(){return t-n}}}; |
@@ -6,3 +6,2 @@ export declare const createLRU: <Key, Value>(options: { | ||
onEviction?: (key: Key, value: Value) => unknown; | ||
debug?: boolean; | ||
}) => { | ||
@@ -39,12 +38,2 @@ /** Adds a key-value pair to the cache. Updates the value if the key already exists. */ | ||
readonly available: number; | ||
readonly debug: { | ||
tail: number; | ||
head: number; | ||
keyMap: Map<Key, number>; | ||
keyList: (Key | undefined)[]; | ||
valList: (Value | undefined)[]; | ||
prev: number[]; | ||
next: number[]; | ||
free: number[]; | ||
} | undefined; | ||
}; |
@@ -5,3 +5,3 @@ "use strict"; | ||
const createLRU = (options) => { | ||
let { max, onEviction, debug } = options; | ||
let { max, onEviction } = options; | ||
if (!(Number.isInteger(max) && max > 0)) | ||
@@ -211,9 +211,4 @@ throw new TypeError('`max` must be a positive integer'); | ||
}, | ||
get debug() { | ||
return debug === true | ||
? { tail, head, keyMap, keyList, valList, prev, next, free } | ||
: undefined; | ||
}, | ||
}; | ||
}; | ||
exports.createLRU = createLRU; |
{ | ||
"name": "lru.min", | ||
"version": "0.3.0", | ||
"description": "π₯ An extremely fast and efficient LRU cache for JavaScript (Browser compatible) β 6.5KB.", | ||
"version": "0.3.1", | ||
"description": "π₯ An extremely fast and efficient LRU cache for JavaScript (Browser compatible) β 6.4KB.", | ||
"main": "./lib/index.js", | ||
@@ -6,0 +6,0 @@ "module": "./lib/index.mjs", |
<h1 align="center">lru.min</h1> | ||
<div align="center"> | ||
π₯ An extremely fast and efficient <strong><a href="https://en.m.wikipedia.org/wiki/Cache_replacement_policies#Least_Recently_Used_.28LRU.29">LRU</a> Cache</strong> for <strong>JavaScript</strong> (<strong>Browser</strong> compatible) β **6.5KB**. | ||
π₯ An extremely fast and efficient <strong><a href="https://en.m.wikipedia.org/wiki/Cache_replacement_policies#Least_Recently_Used_.28LRU.29">LRU</a> Cache</strong> for <strong>JavaScript</strong> (<strong>Browser</strong> compatible) β **6.4KB**. | ||
@@ -6,0 +6,0 @@ </div> |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27866
454