trie-memoize
Version:
A memoization algorithm in which each function argument represents a new key, creating a trie of caches as defined by the array in your first argument.
3 lines (2 loc) • 654 B
JavaScript
var t=t=>{try{return new t}catch(t){var e={};return{set(t,r){e[t]=r},get:t=>e[t]}}};export default(e,r)=>{var n,g,s,u,o,v,i,a,d,{g:f,s:l}=(i=(g=e).length,a=t(g[0]),d=1===i,3>i?{g:t=>void 0===(s=a.get(t[0]))||d?s:s.get(t[1]),s:(e,r)=>(d?a.set(e[0],r):void 0===(s=a.get(e[0]))?((u=t(g[1])).set(e[1],r),a.set(e[0],u)):s.set(e[1],r),r)}:{g:t=>{for(v=a,o=0;i>o;o++)if(void 0===(v=v.get(t[o])))return;return v},s:(e,r)=>{for(v=a,o=0;i-1>o;o++)void 0===(u=v.get(e[o]))?(u=t(g[o+1]),v.set(e[o],u),v=u):v=u;return v.set(e[i-1],r),r}});return function(){return void 0===(n=f(arguments))?l(arguments,r.apply(null,arguments)):n}};
//# sourceMappingURL=index.mjs.map