Comparing version 0.0.5 to 0.0.6
@@ -1,2 +0,2 @@ | ||
/*! dw-cache v0.0.5 https://github.com/falsandtru/dw-cache | (c) 2021, falsandtru | (Apache-2.0 AND MPL-2.0) License */ | ||
/*! dw-cache v0.0.6 https://github.com/falsandtru/dw-cache | (c) 2021, falsandtru | (Apache-2.0 AND MPL-2.0) License */ | ||
require = function () { | ||
@@ -413,5 +413,3 @@ function r(e, n, t) { | ||
while (this.length === this.capacity || this.space && this.size + margin > this.space) { | ||
const list = false || LRU.length === 0 || LFU.length > this.capacity * this.ratio / 100 || LFU.length > this.capacity / 2 && LFU.last.value < this.clock - this.capacity * 8 ? LFU : LRU; | ||
if (list.length === 0) | ||
throw new Error(`Spica: Cache: Failed to secure the margin.`); | ||
const list = false || LRU.length === +(restore === LRU) || LFU.length > this.capacity * this.ratio / 100 || LFU.length > this.capacity / 2 && LFU.last.value < this.clock - this.capacity * 8 ? LFU : LRU; | ||
const index = list.last; | ||
@@ -546,11 +544,8 @@ if (miss !== null && miss !== void 0 ? miss : (0, compare_1.equal)(index.key, key)) { | ||
const isCalculable = LRU[1] + LFU[1] > 0; | ||
const rateR = rate(window, LRU[0], LRU[0] + LFU[0], LRU[1], LRU[1] + LFU[1]); | ||
const rateF = rate(window, LFU[0], LRU[0] + LFU[0], LFU[1], LRU[1] + LFU[1]) * indexes.LRU.length / indexes.LFU.length | 0; | ||
const isLRUFilled = indexes.LRU.length >= capacity * (100 - ratio) / 100; | ||
const isLFUFilled = indexes.LFU.length >= capacity * ratio / 100; | ||
const step = 1; | ||
if (isCalculable && ratio < 100 && isLFUFilled && rateF > rateR) { | ||
this.ratio += step; | ||
} else if (isCalculable && ratio > 10 && isLRUFilled && rateR > rateF) { | ||
this.ratio -= step; | ||
const rateR = +isCalculable && rate(window, LRU[0], LRU[0] + LFU[0], LRU[1], LRU[1] + LFU[1]); | ||
const rateF = +isCalculable && rate(window, LFU[0], LRU[0] + LFU[0], LFU[1], LRU[1] + LFU[1]) * indexes.LRU.length / indexes.LFU.length | 0; | ||
if (isCalculable && ratio < 100 && rateF > rateR && indexes.LFU.length >= capacity * ratio / 100) { | ||
++this.ratio; | ||
} else if (isCalculable && ratio > 10 && rateR > rateF && indexes.LRU.length >= capacity * (100 - ratio) / 100) { | ||
--this.ratio; | ||
} | ||
@@ -557,0 +552,0 @@ if (LRU[0] + LFU[0] >= window) { |
@@ -1,2 +0,2 @@ | ||
/*! dw-cache v0.0.5 https://github.com/falsandtru/dw-cache | (c) 2021, falsandtru | (Apache-2.0 AND MPL-2.0) License */ | ||
require=function(){return function e(t,s,i){function n(o,c){if(!s[o]){if(!t[o]){var a="function"==typeof require&&require;if(!c&&a)return a(o,!0);if(r)return r(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}var h=s[o]={exports:{}};t[o][0].call(h.exports,function(e){return n(t[o][1][e]||e)},h,h.exports,e,t,s,i)}return s[o].exports}for(var r="function"==typeof require&&require,o=0;o<i.length;o++)n(i[o]);return n}}()({1:[function(e,t,s){},{}],2:[function(e,t,s){arguments[4][1][0].apply(s,arguments)},{dup:1}],3:[function(e,t,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0}),s.isArray=s.ObjectValues=s.ObjectSetPrototypeOf=s.ObjectSeal=s.ObjectPreventExtensions=s.ObjectKeys=s.isSealed=s.isFrozen=s.isExtensible=s.ObjectIs=s.ObjectGetPrototypeOf=s.ObjectGetOwnPropertySymbols=s.ObjectGetOwnPropertyNames=s.ObjectGetOwnPropertyDescriptors=s.ObjectGetOwnPropertyDescriptor=s.ObjectFromEntries=s.ObjectFreeze=s.ObjectEntries=s.ObjectDefineProperty=s.ObjectDefineProperties=s.ObjectCreate=s.ObjectAssign=s.toString=s.isEnumerable=s.isPrototypeOf=s.hasOwnProperty=s.SymbolKeyFor=s.SymbolFor=s.sign=s.round=s.random=s.min=s.max=s.floor=s.ceil=s.abs=s.parseInt=s.parseFloat=s.isSafeInteger=s.isNaN=s.isInteger=s.isFinite=s.NaN=void 0,s.NaN=Number.NaN,s.isFinite=Number.isFinite,s.isInteger=Number.isInteger,s.isNaN=Number.isNaN,s.isSafeInteger=Number.isSafeInteger,s.parseFloat=Number.parseFloat,s.parseInt=Number.parseInt,s.abs=Math.abs,s.ceil=Math.ceil,s.floor=Math.floor,s.max=Math.max,s.min=Math.min,s.random=Math.random,s.round=Math.round,s.sign=Math.sign,s.SymbolFor=Symbol.for,s.SymbolKeyFor=Symbol.keyFor,s.hasOwnProperty=Object.prototype.hasOwnProperty.call.bind(Object.prototype.hasOwnProperty),s.isPrototypeOf=Object.prototype.isPrototypeOf.call.bind(Object.prototype.isPrototypeOf),s.isEnumerable=Object.prototype.propertyIsEnumerable.call.bind(Object.prototype.propertyIsEnumerable),s.toString=Object.prototype.toString.call.bind(Object.prototype.toString),s.ObjectAssign=Object.assign,s.ObjectCreate=Object.create,s.ObjectDefineProperties=Object.defineProperties,s.ObjectDefineProperty=Object.defineProperty,s.ObjectEntries=Object.entries,s.ObjectFreeze=Object.freeze,s.ObjectFromEntries=Object.fromEntries,s.ObjectGetOwnPropertyDescriptor=Object.getOwnPropertyDescriptor,s.ObjectGetOwnPropertyDescriptors=Object.getOwnPropertyDescriptors,s.ObjectGetOwnPropertyNames=Object.getOwnPropertyNames,s.ObjectGetOwnPropertySymbols=Object.getOwnPropertySymbols,s.ObjectGetPrototypeOf=Object.getPrototypeOf,s.ObjectIs=Object.is,s.isExtensible=Object.isExtensible,s.isFrozen=Object.isFrozen,s.isSealed=Object.isSealed,s.ObjectKeys=Object.keys,s.ObjectPreventExtensions=Object.preventExtensions,s.ObjectSeal=Object.seal,s.ObjectSetPrototypeOf=Object.setPrototypeOf,s.ObjectValues=Object.values,s.isArray=Array.isArray},{}],4:[function(e,t,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0}),s.join=s.splice=s.pop=s.push=s.shift=s.unshift=s.indexOf=void 0;const i=e("./global");function n(e,t){if("length"in e)for(let s=e.length-1;s>=0;--s)t.unshift(e[s]);else t.unshift(...e);return t}function r(e,t){if("length"in t)for(let s=0,i=t.length;s<i;++s)e.push(t[s]);else for(const s of t)e.push(s);return e}function o(e,t,s,...c){if(0===s&&0===c.length)return[];switch(s=s>e.length?e.length:s,t){case 0:switch(s){case 0:return[[],n(c,e)][0];case 1:return 0===e.length?[[],n(c,e)][0]:[[e.shift()],n(c,e)][0];case void 0:if(e.length>1||arguments.length>2)break;return 0===e.length?[]:o(e,t,1)}break;case-1:case e.length-1:switch(s){case 1:return 0===e.length?[[],r(e,c)][0]:[[e.pop()],r(e,c)][0];case void 0:if(e.length>1||arguments.length>2)break;return 0===e.length?[]:o(e,t,1)}break;case e.length:case i.Infinity:return[[],r(e,c)][0]}return arguments.length>2?e.splice(t,s,...c):e.splice(t)}s.indexOf=function(e,t){return 0===e.length?-1:t==t?e.indexOf(t):e.findIndex(e=>e!=e)},s.unshift=n,s.shift=function(e,t){if(t<0)throw new Error("Unexpected negative number");return void 0===t?[e.shift(),e]:[o(e,0,t),e]},s.push=r,s.pop=function(e,t){if(t<0)throw new Error("Unexpected negative number");return void 0===t?[e,e.pop()]:[e,o(e,e.length-t,t)]},s.splice=o,s.join=function(e,t=""){let s="";for(let i=0;i<e.length;++i)s+=0===i?e[i]:t+e[i];return s}},{"./global":10}],5:[function(e,t,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0}),s.template=s.overwrite=s.inherit=s.merge=s.extend=s.clone=s.assign=void 0;const i=e("./global"),n=e("./alias"),r=e("./type"),o=e("./array");function c(e){return function(t,...s){if((0,r.isPrimitive)(t))return t;for(let i=0;i<s.length;++i){const o=s[i];if(o===t)continue;if((0,r.isPrimitive)(o))continue;const c=(0,n.ObjectKeys)(o);for(let s=0;s<c.length;++s)e(c[s],t,o)}return t}}function a(e){switch((0,r.type)(e)){case"Array":return[];case"Object":return e instanceof i.Object?{}:(0,n.ObjectCreate)(null);default:return e}}s.assign=c((e,t,s)=>t[e]=s[e]),s.clone=c((e,t,i)=>{switch((0,r.type)(i[e])){case"Array":return t[e]=i[e].slice();case"Object":switch((0,r.type)(t[e])){case"Object":return t[e]=(0,s.clone)(a(i[e]),i[e]);default:return t[e]=i[e]}default:return t[e]=i[e]}}),s.extend=c((e,t,i)=>{switch((0,r.type)(i[e])){case"undefined":return;case"Array":return t[e]=i[e];case"Object":switch((0,r.type)(t[e])){case"Object":return t[e]=(0,s.extend)(t[e],i[e]);default:return t[e]=(0,s.extend)(a(i[e]),i[e])}default:return t[e]=i[e]}}),s.merge=c((e,t,i)=>{switch((0,r.type)(i[e])){case"undefined":return;case"Array":switch((0,r.type)(t[e])){case"Array":return t[e]=(0,o.push)(t[e],i[e]);default:return t[e]=i[e].slice()}case"Object":switch((0,r.type)(t[e])){case"Object":return t[e]=(0,s.merge)(t[e],i[e]);default:return t[e]=(0,s.merge)(a(i[e]),i[e])}default:return t[e]=i[e]}}),s.inherit=c((e,t,i)=>{switch((0,r.type)(i[e])){case"undefined":return;case"Array":return t[e]=i[e].slice();case"Object":switch((0,r.type)(t[e])){case"Object":return t[e]=(0,n.hasOwnProperty)(t,e)?(0,s.inherit)(t[e],i[e]):(0,s.inherit)((0,n.ObjectCreate)(t[e]),i[e]);default:return t[e]=(0,n.ObjectCreate)(i[e])}default:return t[e]=i[e]}}),s.overwrite=c((e,t,i)=>{switch((0,r.type)(i[e])){case"Array":return t[e]=i[e];case"Object":switch((0,r.type)(t[e])){case"Object":return t[e]=(0,s.overwrite)(t[e],i[e]);default:return t[e]=(0,s.overwrite)(a(i[e]),i[e])}default:return t[e]=i[e]}}),s.template=c},{"./alias":3,"./array":4,"./global":10,"./type":16}],6:[function(e,t,s){"use strict";var i;Object.defineProperty(s,"__esModule",{value:!0}),s.Cache=void 0;const n=e("./global"),r=e("./alias"),o=e("./clock"),c=e("./ixlist"),a=e("./assign"),u=e("./tuple"),h=e("./compare"),l=Symbol("size");function f(e,t,s,i,n){e=(0,r.min)(s+n,e);const o=100*t/s|0,c=(0,r.min)(100*s/e|0,100);return o*c+(100*i/n|0)*(100-c)|0}s.Cache=class{constructor(e,t={}){if(this.capacity=e,this.settings={space:0,age:n.Infinity,capture:{delete:!0,clear:!0}},this[i]=0,this.clock=0,this.clockR=0,this.memory=new n.Map,this.indexes={LRU:new c.IxList(this.capacity),LFU:new c.IxList(this.capacity)},this.stack={length:0},this.stats={LRU:(0,u.tuple)(0,0),LFU:(0,u.tuple)(0,0)},this.ratio=50,this.frequency=(0,r.max)(this.capacity/100|0,1),e<1)throw new Error("Spica: Cache: Capacity must be 1 or more.");(0,a.extend)(this.settings,t),this.space=this.settings.space}get length(){return this.indexes.LRU.length+this.indexes.LFU.length}get size(){return this[l]}resume(){if(0===this.stack.length)return;const{stack:e,settings:{disposer:t}}=this;for(;e.length>0;){const{key:s,value:i}=e[--e.length];t(i,s)}}dispose(e,{target:t,index:s,value:i,size:n},r){this.indexes[t].del(e,s),this.memory.delete(e),this.space&&(this[l]-=n),null==r||r(i,e)}secure(e,t){if(e<=0)return;const{LRU:s,LFU:i}=this.indexes;let n,r=!(arguments.length<2)&&void 0;for(;this.length===this.capacity||this.space&&this.size+e>this.space;){const e=0===s.length||i.length>this.capacity*this.ratio/100||i.length>this.capacity/2&&i.last.value<this.clock-8*this.capacity?i:s;if(0===e.length)throw new Error("Spica: Cache: Failed to secure the margin.");const o=e.last;if(null!=r?r:(0,h.equal)(o.key,t)){r=!1,n=e,e.HEAD=o.index;continue}const c=this.memory.get(o.key);this.dispose(o.key,c,void 0),this.settings.disposer&&(this.stack[this.stack.length++]={key:o.key,value:c.value})}n&&n.length>0&&(n.HEAD=n.tail.index)}put(e,t,s=1,i=this.settings.age){var r,c;if(s<1)throw new Error("Spica: Cache: Size must be 1 or more.");if(i<1)throw new Error("Spica: Cache: Age must be 1 or more.");if(this.space&&s>this.space||i<=0)return null===(c=(r=this.settings).disposer)||void 0===c||c.call(r,t,e),!1;const a=i===n.Infinity?n.Infinity:(0,o.now)()+i,u=this.memory.get(e);if(u)return this.settings.disposer&&(this.stack[this.stack.length++]={key:e,value:u.value}),this.secure(s-u.size,e),this.space&&(this[l]+=s-u.size),u.value=t,u.size=s,u.expiry=a,this.resume(),!0;this.secure(s);const{LRU:h}=this.indexes;return this.space&&(this[l]+=s),this.memory.set(e,{target:"LRU",index:h.add(e,++this.clockR),value:t,size:s,expiry:a}),this.resume(),!1}set(e,t,s,i){return this.put(e,t,s,i),this}get(e){const t=this.memory.get(e);if(t){if(!(t.expiry!==n.Infinity&&t.expiry<=(0,o.now)()))return this.access(e,t),this.slide(),t.value;this.dispose(e,t,this.settings.disposer)}}has(e){const t=this.memory.get(e);return!(!t||t.expiry!==n.Infinity&&t.expiry<=(0,o.now)()&&(this.dispose(e,t,this.settings.disposer),1))}delete(e){const t=this.memory.get(e);return!!t&&(this.dispose(e,t,this.settings.capture.delete?this.settings.disposer:void 0),!0)}clear(){if(this[l]=0,this.ratio=50,this.indexes.LRU.clear(),this.indexes.LFU.clear(),this.stack={length:0},this.stats={LRU:[0,0],LFU:[0,0]},!this.settings.disposer||!this.settings.capture.clear)return void this.memory.clear();const e=this.memory;this.memory=new n.Map;for(const[t,{value:s}]of e)this.settings.disposer(s,t)}*[(i=l,Symbol.iterator)](){for(const[e,{value:t}]of this.memory)yield[e,t]}slide(){const{LRU:e,LFU:t}=this.stats,{capacity:s,ratio:i,indexes:n}=this;if((e[0]+t[0])%this.frequency)return;const r=s,o=e[1]+t[1]>0,c=f(r,e[0],e[0]+t[0],e[1],e[1]+t[1]),a=f(r,t[0],e[0]+t[0],t[1],e[1]+t[1])*n.LRU.length/n.LFU.length|0,u=n.LRU.length>=s*(100-i)/100,h=n.LFU.length>=s*i/100;o&&i<100&&h&&a>c?this.ratio+=1:o&&i>10&&u&&c>a&&(this.ratio-=1),e[0]+t[0]>=r&&(this.stats={LRU:[0,e[0]],LFU:[0,t[0]]})}access(e,t){return this.accessLFU(e,t)||this.accessLRU(e,t)}accessLRU(e,t){if("LRU"!==t.target)return!1;const{LRU:s,LFU:i}=this.indexes,{index:n}=t;return++this.stats.LRU[0],++this.clock,++this.clockR,s.node(n).value+s.length/3>this.clockR?(s.put(e,this.clockR,n),s.moveToHead(n),!0):(s.del(e,n),t.target="LFU",t.index=i.add(e,this.clock),!0)}accessLFU(e,t){if("LFU"!==t.target)return!1;const{LFU:s}=this.indexes,{index:i}=t;return++this.stats.LFU[0],++this.clock,s.put(e,this.clock,i),s.moveToHead(i),!0}}},{"./alias":3,"./assign":5,"./clock":7,"./compare":8,"./global":10,"./ixlist":11,"./tuple":15}],7:[function(e,t,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0}),s.tick=s.wait=s.clock=s.now=void 0;const i=e("./global"),n=e("./alias"),r=e("./promise"),o=e("./exception");let c;s.now=function(){return void 0!==c?c:(f(()=>c=void 0),c=i.Date.now())},s.clock=Promise.resolve(void 0),s.wait=function(e){return 0===e?r.AtomicPromise.resolve(s.clock):new r.AtomicPromise(t=>void(0,i.setTimeout)(t,e))};let a=[],u=[],h=0;const l=Promise.resolve();function f(e){0===h&&l.then(d),h++===a.length?a.push(e):a[h-1]=e}function d(){const e=h;[h,a,u]=[0,u,a];for(let t=0;t<e;++t)try{u[t](),u[t]=void 0}catch(e){(0,o.causeAsyncException)(e)}u.length>1e3&&e<.5*u.length&&u.splice((0,n.floor)(.9*u.length),u.length)}s.tick=f},{"./alias":3,"./exception":9,"./global":10,"./promise":14}],8:[function(e,t,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0}),s.equal=void 0,s.equal=function(e,t){return e==e?e===t:t!=t}},{}],9:[function(e,t,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0}),s.causeAsyncException=void 0,s.causeAsyncException=function(e){Promise.reject(e)}},{}],10:[function(_dereq_,module,exports){"use strict";const global="undefined"!=typeof globalThis&&globalThis||"undefined"!=typeof self&&self||Function("return this")();eval("global.global = global"),module.exports=global},{}],11:[function(e,t,s){"use strict";var i=this&&this.__createBinding||(Object.create?function(e,t,s,i){void 0===i&&(i=s),Object.defineProperty(e,i,{enumerable:!0,get:function(){return t[s]}})}:function(e,t,s,i){void 0===i&&(i=s),e[i]=t[s]}),n=this&&this.__exportStar||function(e,t){for(var s in e)"default"===s||Object.prototype.hasOwnProperty.call(t,s)||i(t,e,s)};Object.defineProperty(s,"__esModule",{value:!0}),n(e("./list/ixlist"),s)},{"./list/ixlist":12}],12:[function(e,t,s){"use strict";var i,n;Object.defineProperty(s,"__esModule",{value:!0}),s.IxList=void 0;const r=e("../compare"),o=Symbol("cursor"),c=Symbol("length");s.IxList=class{constructor(e,t){this.capacity=e,this.index=t,this.nodes={},this.buffers={length:0},this.HEAD=0,this[i]=0,this[n]=0}get length(){return this[c]}get head(){return this.nodes[this.HEAD]}get tail(){if(0===this.length)return;const e=this.nodes;return e[e[this.HEAD].next]}get last(){if(0===this.length)return;const e=this.nodes;return e[e[this.HEAD].prev]}node(e){return this.nodes[e]}clear(){var e;this.nodes={},this.buffers={length:0},null===(e=this.index)||void 0===e||e.clear(),this.HEAD=0,this[o]=0,this[c]=0}add(e,t){var s,i;const n=this.nodes,a=n[this.HEAD];if(!a){const i=this.HEAD=this[o]=this.buffers.length>0?this.buffers[--this.buffers.length]:this.length;return++this[c],null===(s=this.index)||void 0===s||s.set(e,i),n[i]={index:i,key:e,value:t,next:i,prev:i},i}if(this.length<this.capacity){const s=this.HEAD=this[o]=this.buffers.length>0?this.buffers[--this.buffers.length]:this.length;return++this[c],null===(i=this.index)||void 0===i||i.set(e,s),n[s]={index:s,key:e,value:t,next:a.index,prev:a.prev},a.prev=n[a.prev].next=s,s}{const s=n[a.prev],i=this.HEAD=this[o]=s.index;return this.index&&!(0,r.equal)(s.key,e)&&(this.index.delete(s.key,s.index),this.index.set(e,i)),s.key=e,s.value=t,i}}put(e,t,s){const i=this.search(e,s);return i?(i.value=t,i.index):this.add(e,t)}set(e,t,s){return this.put(e,t,s),this}search(e,t=this[o]){var s;const i=this.nodes;let n;if((n=i[t])&&(0,r.equal)(n.key,e))return this[o]=t,n;if(!this.index)throw new Error("Spica: IxList: Invalid index.");return 0===this.length||n&&1===this.length?void 0:(n=i[t=null!==(s=this.index.get(e))&&void 0!==s?s:this.capacity])?(this[o]=t,n):void 0}find(e,t){if(!this.index)throw new Error("Spica: IxList: No index.");return this.search(e,t)}get(e,t){var s;return null===(s=this.find(e,t))||void 0===s?void 0:s.value}has(e,t){return void 0!==this.find(e,t)}del(e,t){var s;const i=this[o],n=this.search(e,t);if(!n)return;this[o]=i,--this[c],this.buffers[this.buffers.length++]=n.index,null===(s=this.index)||void 0===s||s.delete(n.key,n.index);const r=this.nodes;return r[n.prev].next=n.next,r[n.next].prev=n.prev,this.HEAD===n.index&&(this.HEAD=n.next),this[o]===n.index&&(this[o]=n.next),r[n.index]=void 0,n}delete(e,t){return void 0!==this.del(e,t)}unshift(e,t){return this.add(e,t)}shift(){const e=this.nodes[this.HEAD];return e&&this.del(e.key,e.index)}push(e,t){return this.HEAD=this.nodes[this.add(e,t)].next}pop(){if(0===this.length)return;const e=this.nodes,t=e[e[this.HEAD].prev];return t&&this.del(t.key,t.index)}*[(i=o,n=c,Symbol.iterator)](){const e=this.nodes;for(let t=e[this.HEAD],s=0;t&&s<this.length;(t=e[t.next])&&++s)yield[t.key,t.value]}insert(e,t){if(e===t)return!1;const s=this.nodes,i=s[e];if(!i)return!1;const n=s[t];if(!n)return!1;if(i.next===n.index)return!1;const r=s[n.prev],o=s[i.prev],c=s[i.next];return r.next=i.index,i.next=n.index,n.prev=i.index,i.prev=r.index,o.next=c.index,c.prev=o.index,!0}moveToHead(e){return!(this.length<=1)&&(e!==this.HEAD&&(!!this.nodes[e]&&(this.insert(e,this.HEAD),this.HEAD=e,!0)))}moveToPrev(e){if(this.length<=1)return!1;if(e===this.HEAD)return!1;const t=this.nodes[e];return!!t&&(this.insert(t.index,t.prev),t.next===this.HEAD&&(this.HEAD=t.index),!0)}swap(e,t){if(this.length<=1)return!1;if(e===t)return!1;const s=this.nodes,i=s[e],n=s[t];if(!i||!n)return!1;if(i.next===n.index)return this.moveToPrev(t);if(n.next===i.index)return this.moveToPrev(e);switch(this.insert(n.index,i.index),this.insert(i.index,n.next),this.HEAD){case i.index:this.HEAD=n.index;break;case n.index:this.HEAD=i.index}return!0}}},{"../compare":8}],13:[function(e,t,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0}),s.noop=void 0,s.noop=function(){}},{}],14:[function(e,t,s){"use strict";var i,n;Object.defineProperty(s,"__esModule",{value:!0}),s.never=s.isPromiseLike=s.Internal=s.AtomicPromise=void 0;const r=e("./global"),o=e("./alias"),c=e("./noop"),a=Symbol.for("spica/promise::internal");class u{constructor(e){this[i]="Promise",this[n]=new h;try{e(e=>void this[a].resolve(e),e=>void this[a].reject(e))}catch(e){this[a].reject(e)}}static get[Symbol.species](){return u}static all(e){return new u((t,s)=>{const i=(0,o.isArray)(e)?e:[...e],n=(0,r.Array)(i.length);let c=0;for(let e=0;e<i.length;++e){const r=i[e];if(d(r)){if(p(r)){const{status:t}=r[a];switch(t.state){case 2:n[e]=t.value,++c;continue;case 3:s(t.reason),e=i.length;continue}}r.then(s=>{n[e]=s,++c===i.length&&t(n)},t=>{s(t),e=i.length})}else n[e]=r,++c}c===i.length&&t(n)})}static race(e){return new u((t,s)=>{const i=(0,o.isArray)(e)?e:[...e];for(let e=0;e<i.length;++e){const n=i[e];if(!d(n))return t(n);if(p(n)){const{status:e}=n[a];switch(e.state){case 2:return t(e.value);case 3:return s(e.reason)}}}let n=!1;for(let e=0;e<i.length;++e){if(i[e].then(e=>{t(e),n=!0},e=>{s(e),n=!0}),n)return}})}static allSettled(e){return new u(t=>{const s=(0,o.isArray)(e)?e:[...e],i=(0,r.Array)(s.length);let n=0;for(let e=0;e<s.length;++e){const r=s[e];if(d(r)){if(p(r)){const{status:t}=r[a];switch(t.state){case 2:i[e]={status:"fulfilled",value:t.value},++n;continue;case 3:i[e]={status:"rejected",reason:t.reason},++n;continue}}r.then(r=>{i[e]={status:"fulfilled",value:r},++n===s.length&&t(i)},r=>{i[e]={status:"rejected",reason:r},++n===s.length&&t(i)})}else i[e]={status:"fulfilled",value:r},++n}n===s.length&&t(i)})}static resolve(e){return new u(t=>t(e))}static reject(e){return new u((t,s)=>s(e))}then(e,t){return new u((s,i)=>this[a].then(s,i,e,t))}catch(e){return this.then(void 0,e)}finally(e){return this.then(e,e).then(()=>this)}}s.AtomicPromise=u,i=Symbol.toStringTag,n=a;class h{constructor(){this.status={state:0},this.fulfillReactions=[],this.rejectReactions=[]}get isPending(){return 0===this.status.state}resolve(e){if(0===this.status.state){if(!d(e))return this.status={state:2,value:e},this.resume();if(p(e)){const t=e[a];switch(t.status.state){case 2:case 3:return this.status=t.status,this.resume();default:return t.then(()=>(this.status=t.status,this.resume()),()=>(this.status=t.status,this.resume()))}}this.status={state:1,promise:e},e.then(e=>{this.status={state:2,value:e},this.resume()},e=>{this.status={state:3,reason:e},this.resume()})}}reject(e){if(0===this.status.state)return this.status={state:3,reason:e},this.resume()}then(e,t,s,i){const{status:n,fulfillReactions:r,rejectReactions:o}=this;switch(n.state){case 2:if(0!==r.length)break;return f(e,t,e,s,n.value);case 3:if(0!==o.length)break;return f(e,t,t,i,n.reason)}r.push([e,t,e,s]),o.push([e,t,t,i])}resume(){const{status:e,fulfillReactions:t,rejectReactions:s}=this;switch(e.state){case 0:case 1:return;case 2:if(0!==s.length&&(this.rejectReactions=[]),0===t.length)return;return l(t,e.value),void(this.fulfillReactions=[]);case 3:if(0!==t.length&&(this.fulfillReactions=[]),0===s.length)return;return l(s,e.reason),void(this.rejectReactions=[])}}}function l(e,t){for(let s=0;s<e.length;++s){const i=e[s];f(i[0],i[1],i[2],i[3],t)}}function f(e,t,s,i,n){if(!i)return s(n);try{e(i(n))}catch(e){t(e)}}function d(e){return null!==e&&"object"==typeof e&&"function"==typeof e.then}function p(e){return a in e}s.Internal=h,s.isPromiseLike=d,s.never=new class e extends Promise{static get[Symbol.species](){return e}constructor(){super(c.noop)}then(){return this}catch(){return this}finally(){return this}}},{"./alias":3,"./global":10,"./noop":13}],15:[function(e,t,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0}),s.tuple=void 0,s.tuple=function(...e){return e}},{}],16:[function(e,t,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0}),s.isPrimitive=s.isType=s.type=void 0;const i=e("./alias"),n=Object.prototype.toString.call.bind(Object.prototype.toString),r=Object.prototype,o=Array.prototype;function c(e){if(void 0===e)return"undefined";if(null===e)return"null";const t=typeof e;if("object"===t){const t=(0,i.ObjectGetPrototypeOf)(e);return t===r||null===t?"Object":t===o?"Array":n(e).slice(8,-1)}return"function"===t?"Function":t}s.type=c,s.isType=function(e,t){return"object"===t?null!==e&&typeof e===t:"function"===t?typeof e===t:c(e)===t},s.isPrimitive=function(e){const t=typeof e;return"object"!==t&&"function"!==t||null===e}},{"./alias":3}],"dw-cache":[function(e,t,s){"use strict";var i=this&&this.__createBinding||(Object.create?function(e,t,s,i){void 0===i&&(i=s),Object.defineProperty(e,i,{enumerable:!0,get:function(){return t[s]}})}:function(e,t,s,i){void 0===i&&(i=s),e[i]=t[s]}),n=this&&this.__exportStar||function(e,t){for(var s in e)"default"===s||Object.prototype.hasOwnProperty.call(t,s)||i(t,e,s)};Object.defineProperty(s,"__esModule",{value:!0}),n(e("spica/cache"),s)},{"spica/cache":6}]},{},[1,2,"dw-cache"]),function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof module&&module.exports?module.exports=t():Object.assign(e,t())}("undefined"!=typeof self?self:this,function(){return require("dw-cache")}); | ||
/*! dw-cache v0.0.6 https://github.com/falsandtru/dw-cache | (c) 2021, falsandtru | (Apache-2.0 AND MPL-2.0) License */ | ||
require=function(){return function e(t,s,i){function n(o,c){if(!s[o]){if(!t[o]){var a="function"==typeof require&&require;if(!c&&a)return a(o,!0);if(r)return r(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}var h=s[o]={exports:{}};t[o][0].call(h.exports,function(e){return n(t[o][1][e]||e)},h,h.exports,e,t,s,i)}return s[o].exports}for(var r="function"==typeof require&&require,o=0;o<i.length;o++)n(i[o]);return n}}()({1:[function(e,t,s){},{}],2:[function(e,t,s){arguments[4][1][0].apply(s,arguments)},{dup:1}],3:[function(e,t,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0}),s.isArray=s.ObjectValues=s.ObjectSetPrototypeOf=s.ObjectSeal=s.ObjectPreventExtensions=s.ObjectKeys=s.isSealed=s.isFrozen=s.isExtensible=s.ObjectIs=s.ObjectGetPrototypeOf=s.ObjectGetOwnPropertySymbols=s.ObjectGetOwnPropertyNames=s.ObjectGetOwnPropertyDescriptors=s.ObjectGetOwnPropertyDescriptor=s.ObjectFromEntries=s.ObjectFreeze=s.ObjectEntries=s.ObjectDefineProperty=s.ObjectDefineProperties=s.ObjectCreate=s.ObjectAssign=s.toString=s.isEnumerable=s.isPrototypeOf=s.hasOwnProperty=s.SymbolKeyFor=s.SymbolFor=s.sign=s.round=s.random=s.min=s.max=s.floor=s.ceil=s.abs=s.parseInt=s.parseFloat=s.isSafeInteger=s.isNaN=s.isInteger=s.isFinite=s.NaN=void 0,s.NaN=Number.NaN,s.isFinite=Number.isFinite,s.isInteger=Number.isInteger,s.isNaN=Number.isNaN,s.isSafeInteger=Number.isSafeInteger,s.parseFloat=Number.parseFloat,s.parseInt=Number.parseInt,s.abs=Math.abs,s.ceil=Math.ceil,s.floor=Math.floor,s.max=Math.max,s.min=Math.min,s.random=Math.random,s.round=Math.round,s.sign=Math.sign,s.SymbolFor=Symbol.for,s.SymbolKeyFor=Symbol.keyFor,s.hasOwnProperty=Object.prototype.hasOwnProperty.call.bind(Object.prototype.hasOwnProperty),s.isPrototypeOf=Object.prototype.isPrototypeOf.call.bind(Object.prototype.isPrototypeOf),s.isEnumerable=Object.prototype.propertyIsEnumerable.call.bind(Object.prototype.propertyIsEnumerable),s.toString=Object.prototype.toString.call.bind(Object.prototype.toString),s.ObjectAssign=Object.assign,s.ObjectCreate=Object.create,s.ObjectDefineProperties=Object.defineProperties,s.ObjectDefineProperty=Object.defineProperty,s.ObjectEntries=Object.entries,s.ObjectFreeze=Object.freeze,s.ObjectFromEntries=Object.fromEntries,s.ObjectGetOwnPropertyDescriptor=Object.getOwnPropertyDescriptor,s.ObjectGetOwnPropertyDescriptors=Object.getOwnPropertyDescriptors,s.ObjectGetOwnPropertyNames=Object.getOwnPropertyNames,s.ObjectGetOwnPropertySymbols=Object.getOwnPropertySymbols,s.ObjectGetPrototypeOf=Object.getPrototypeOf,s.ObjectIs=Object.is,s.isExtensible=Object.isExtensible,s.isFrozen=Object.isFrozen,s.isSealed=Object.isSealed,s.ObjectKeys=Object.keys,s.ObjectPreventExtensions=Object.preventExtensions,s.ObjectSeal=Object.seal,s.ObjectSetPrototypeOf=Object.setPrototypeOf,s.ObjectValues=Object.values,s.isArray=Array.isArray},{}],4:[function(e,t,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0}),s.join=s.splice=s.pop=s.push=s.shift=s.unshift=s.indexOf=void 0;const i=e("./global");function n(e,t){if("length"in e)for(let s=e.length-1;s>=0;--s)t.unshift(e[s]);else t.unshift(...e);return t}function r(e,t){if("length"in t)for(let s=0,i=t.length;s<i;++s)e.push(t[s]);else for(const s of t)e.push(s);return e}function o(e,t,s,...c){if(0===s&&0===c.length)return[];switch(s=s>e.length?e.length:s,t){case 0:switch(s){case 0:return[[],n(c,e)][0];case 1:return 0===e.length?[[],n(c,e)][0]:[[e.shift()],n(c,e)][0];case void 0:if(e.length>1||arguments.length>2)break;return 0===e.length?[]:o(e,t,1)}break;case-1:case e.length-1:switch(s){case 1:return 0===e.length?[[],r(e,c)][0]:[[e.pop()],r(e,c)][0];case void 0:if(e.length>1||arguments.length>2)break;return 0===e.length?[]:o(e,t,1)}break;case e.length:case i.Infinity:return[[],r(e,c)][0]}return arguments.length>2?e.splice(t,s,...c):e.splice(t)}s.indexOf=function(e,t){return 0===e.length?-1:t==t?e.indexOf(t):e.findIndex(e=>e!=e)},s.unshift=n,s.shift=function(e,t){if(t<0)throw new Error("Unexpected negative number");return void 0===t?[e.shift(),e]:[o(e,0,t),e]},s.push=r,s.pop=function(e,t){if(t<0)throw new Error("Unexpected negative number");return void 0===t?[e,e.pop()]:[e,o(e,e.length-t,t)]},s.splice=o,s.join=function(e,t=""){let s="";for(let i=0;i<e.length;++i)s+=0===i?e[i]:t+e[i];return s}},{"./global":10}],5:[function(e,t,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0}),s.template=s.overwrite=s.inherit=s.merge=s.extend=s.clone=s.assign=void 0;const i=e("./global"),n=e("./alias"),r=e("./type"),o=e("./array");function c(e){return function(t,...s){if((0,r.isPrimitive)(t))return t;for(let i=0;i<s.length;++i){const o=s[i];if(o===t)continue;if((0,r.isPrimitive)(o))continue;const c=(0,n.ObjectKeys)(o);for(let s=0;s<c.length;++s)e(c[s],t,o)}return t}}function a(e){switch((0,r.type)(e)){case"Array":return[];case"Object":return e instanceof i.Object?{}:(0,n.ObjectCreate)(null);default:return e}}s.assign=c((e,t,s)=>t[e]=s[e]),s.clone=c((e,t,i)=>{switch((0,r.type)(i[e])){case"Array":return t[e]=i[e].slice();case"Object":switch((0,r.type)(t[e])){case"Object":return t[e]=(0,s.clone)(a(i[e]),i[e]);default:return t[e]=i[e]}default:return t[e]=i[e]}}),s.extend=c((e,t,i)=>{switch((0,r.type)(i[e])){case"undefined":return;case"Array":return t[e]=i[e];case"Object":switch((0,r.type)(t[e])){case"Object":return t[e]=(0,s.extend)(t[e],i[e]);default:return t[e]=(0,s.extend)(a(i[e]),i[e])}default:return t[e]=i[e]}}),s.merge=c((e,t,i)=>{switch((0,r.type)(i[e])){case"undefined":return;case"Array":switch((0,r.type)(t[e])){case"Array":return t[e]=(0,o.push)(t[e],i[e]);default:return t[e]=i[e].slice()}case"Object":switch((0,r.type)(t[e])){case"Object":return t[e]=(0,s.merge)(t[e],i[e]);default:return t[e]=(0,s.merge)(a(i[e]),i[e])}default:return t[e]=i[e]}}),s.inherit=c((e,t,i)=>{switch((0,r.type)(i[e])){case"undefined":return;case"Array":return t[e]=i[e].slice();case"Object":switch((0,r.type)(t[e])){case"Object":return t[e]=(0,n.hasOwnProperty)(t,e)?(0,s.inherit)(t[e],i[e]):(0,s.inherit)((0,n.ObjectCreate)(t[e]),i[e]);default:return t[e]=(0,n.ObjectCreate)(i[e])}default:return t[e]=i[e]}}),s.overwrite=c((e,t,i)=>{switch((0,r.type)(i[e])){case"Array":return t[e]=i[e];case"Object":switch((0,r.type)(t[e])){case"Object":return t[e]=(0,s.overwrite)(t[e],i[e]);default:return t[e]=(0,s.overwrite)(a(i[e]),i[e])}default:return t[e]=i[e]}}),s.template=c},{"./alias":3,"./array":4,"./global":10,"./type":16}],6:[function(e,t,s){"use strict";var i;Object.defineProperty(s,"__esModule",{value:!0}),s.Cache=void 0;const n=e("./global"),r=e("./alias"),o=e("./clock"),c=e("./ixlist"),a=e("./assign"),u=e("./tuple"),h=e("./compare"),l=Symbol("size");function f(e,t,s,i,n){e=(0,r.min)(s+n,e);const o=100*t/s|0,c=(0,r.min)(100*s/e|0,100);return o*c+(100*i/n|0)*(100-c)|0}s.Cache=class{constructor(e,t={}){if(this.capacity=e,this.settings={space:0,age:n.Infinity,capture:{delete:!0,clear:!0}},this[i]=0,this.clock=0,this.clockR=0,this.memory=new n.Map,this.indexes={LRU:new c.IxList(this.capacity),LFU:new c.IxList(this.capacity)},this.stack={length:0},this.stats={LRU:(0,u.tuple)(0,0),LFU:(0,u.tuple)(0,0)},this.ratio=50,this.frequency=(0,r.max)(this.capacity/100|0,1),e<1)throw new Error("Spica: Cache: Capacity must be 1 or more.");(0,a.extend)(this.settings,t),this.space=this.settings.space}get length(){return this.indexes.LRU.length+this.indexes.LFU.length}get size(){return this[l]}resume(){if(0===this.stack.length)return;const{stack:e,settings:{disposer:t}}=this;for(;e.length>0;){const{key:s,value:i}=e[--e.length];t(i,s)}}dispose(e,{target:t,index:s,value:i,size:n},r){this.indexes[t].del(e,s),this.memory.delete(e),this.space&&(this[l]-=n),null==r||r(i,e)}secure(e,t){if(e<=0)return;const{LRU:s,LFU:i}=this.indexes;let n,r=!(arguments.length<2)&&void 0;for(;this.length===this.capacity||this.space&&this.size+e>this.space;){const e=s.length===+(n===s)||i.length>this.capacity*this.ratio/100||i.length>this.capacity/2&&i.last.value<this.clock-8*this.capacity?i:s,o=e.last;if(null!=r?r:(0,h.equal)(o.key,t)){r=!1,n=e,e.HEAD=o.index;continue}const c=this.memory.get(o.key);this.dispose(o.key,c,void 0),this.settings.disposer&&(this.stack[this.stack.length++]={key:o.key,value:c.value})}n&&n.length>0&&(n.HEAD=n.tail.index)}put(e,t,s=1,i=this.settings.age){var r,c;if(s<1)throw new Error("Spica: Cache: Size must be 1 or more.");if(i<1)throw new Error("Spica: Cache: Age must be 1 or more.");if(this.space&&s>this.space||i<=0)return null===(c=(r=this.settings).disposer)||void 0===c||c.call(r,t,e),!1;const a=i===n.Infinity?n.Infinity:(0,o.now)()+i,u=this.memory.get(e);if(u)return this.settings.disposer&&(this.stack[this.stack.length++]={key:e,value:u.value}),this.secure(s-u.size,e),this.space&&(this[l]+=s-u.size),u.value=t,u.size=s,u.expiry=a,this.resume(),!0;this.secure(s);const{LRU:h}=this.indexes;return this.space&&(this[l]+=s),this.memory.set(e,{target:"LRU",index:h.add(e,++this.clockR),value:t,size:s,expiry:a}),this.resume(),!1}set(e,t,s,i){return this.put(e,t,s,i),this}get(e){const t=this.memory.get(e);if(t){if(!(t.expiry!==n.Infinity&&t.expiry<=(0,o.now)()))return this.access(e,t),this.slide(),t.value;this.dispose(e,t,this.settings.disposer)}}has(e){const t=this.memory.get(e);return!(!t||t.expiry!==n.Infinity&&t.expiry<=(0,o.now)()&&(this.dispose(e,t,this.settings.disposer),1))}delete(e){const t=this.memory.get(e);return!!t&&(this.dispose(e,t,this.settings.capture.delete?this.settings.disposer:void 0),!0)}clear(){if(this[l]=0,this.ratio=50,this.indexes.LRU.clear(),this.indexes.LFU.clear(),this.stack={length:0},this.stats={LRU:[0,0],LFU:[0,0]},!this.settings.disposer||!this.settings.capture.clear)return void this.memory.clear();const e=this.memory;this.memory=new n.Map;for(const[t,{value:s}]of e)this.settings.disposer(s,t)}*[(i=l,Symbol.iterator)](){for(const[e,{value:t}]of this.memory)yield[e,t]}slide(){const{LRU:e,LFU:t}=this.stats,{capacity:s,ratio:i,indexes:n}=this;if((e[0]+t[0])%this.frequency)return;const r=s,o=e[1]+t[1]>0,c=+o&&f(r,e[0],e[0]+t[0],e[1],e[1]+t[1]),a=+o&&f(r,t[0],e[0]+t[0],t[1],e[1]+t[1])*n.LRU.length/n.LFU.length|0;o&&i<100&&a>c&&n.LFU.length>=s*i/100?++this.ratio:o&&i>10&&c>a&&n.LRU.length>=s*(100-i)/100&&--this.ratio,e[0]+t[0]>=r&&(this.stats={LRU:[0,e[0]],LFU:[0,t[0]]})}access(e,t){return this.accessLFU(e,t)||this.accessLRU(e,t)}accessLRU(e,t){if("LRU"!==t.target)return!1;const{LRU:s,LFU:i}=this.indexes,{index:n}=t;return++this.stats.LRU[0],++this.clock,++this.clockR,s.node(n).value+s.length/3>this.clockR?(s.put(e,this.clockR,n),s.moveToHead(n),!0):(s.del(e,n),t.target="LFU",t.index=i.add(e,this.clock),!0)}accessLFU(e,t){if("LFU"!==t.target)return!1;const{LFU:s}=this.indexes,{index:i}=t;return++this.stats.LFU[0],++this.clock,s.put(e,this.clock,i),s.moveToHead(i),!0}}},{"./alias":3,"./assign":5,"./clock":7,"./compare":8,"./global":10,"./ixlist":11,"./tuple":15}],7:[function(e,t,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0}),s.tick=s.wait=s.clock=s.now=void 0;const i=e("./global"),n=e("./alias"),r=e("./promise"),o=e("./exception");let c;s.now=function(){return void 0!==c?c:(f(()=>c=void 0),c=i.Date.now())},s.clock=Promise.resolve(void 0),s.wait=function(e){return 0===e?r.AtomicPromise.resolve(s.clock):new r.AtomicPromise(t=>void(0,i.setTimeout)(t,e))};let a=[],u=[],h=0;const l=Promise.resolve();function f(e){0===h&&l.then(d),h++===a.length?a.push(e):a[h-1]=e}function d(){const e=h;[h,a,u]=[0,u,a];for(let t=0;t<e;++t)try{u[t](),u[t]=void 0}catch(e){(0,o.causeAsyncException)(e)}u.length>1e3&&e<.5*u.length&&u.splice((0,n.floor)(.9*u.length),u.length)}s.tick=f},{"./alias":3,"./exception":9,"./global":10,"./promise":14}],8:[function(e,t,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0}),s.equal=void 0,s.equal=function(e,t){return e==e?e===t:t!=t}},{}],9:[function(e,t,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0}),s.causeAsyncException=void 0,s.causeAsyncException=function(e){Promise.reject(e)}},{}],10:[function(_dereq_,module,exports){"use strict";const global="undefined"!=typeof globalThis&&globalThis||"undefined"!=typeof self&&self||Function("return this")();eval("global.global = global"),module.exports=global},{}],11:[function(e,t,s){"use strict";var i=this&&this.__createBinding||(Object.create?function(e,t,s,i){void 0===i&&(i=s),Object.defineProperty(e,i,{enumerable:!0,get:function(){return t[s]}})}:function(e,t,s,i){void 0===i&&(i=s),e[i]=t[s]}),n=this&&this.__exportStar||function(e,t){for(var s in e)"default"===s||Object.prototype.hasOwnProperty.call(t,s)||i(t,e,s)};Object.defineProperty(s,"__esModule",{value:!0}),n(e("./list/ixlist"),s)},{"./list/ixlist":12}],12:[function(e,t,s){"use strict";var i,n;Object.defineProperty(s,"__esModule",{value:!0}),s.IxList=void 0;const r=e("../compare"),o=Symbol("cursor"),c=Symbol("length");s.IxList=class{constructor(e,t){this.capacity=e,this.index=t,this.nodes={},this.buffers={length:0},this.HEAD=0,this[i]=0,this[n]=0}get length(){return this[c]}get head(){return this.nodes[this.HEAD]}get tail(){if(0===this.length)return;const e=this.nodes;return e[e[this.HEAD].next]}get last(){if(0===this.length)return;const e=this.nodes;return e[e[this.HEAD].prev]}node(e){return this.nodes[e]}clear(){var e;this.nodes={},this.buffers={length:0},null===(e=this.index)||void 0===e||e.clear(),this.HEAD=0,this[o]=0,this[c]=0}add(e,t){var s,i;const n=this.nodes,a=n[this.HEAD];if(!a){const i=this.HEAD=this[o]=this.buffers.length>0?this.buffers[--this.buffers.length]:this.length;return++this[c],null===(s=this.index)||void 0===s||s.set(e,i),n[i]={index:i,key:e,value:t,next:i,prev:i},i}if(this.length<this.capacity){const s=this.HEAD=this[o]=this.buffers.length>0?this.buffers[--this.buffers.length]:this.length;return++this[c],null===(i=this.index)||void 0===i||i.set(e,s),n[s]={index:s,key:e,value:t,next:a.index,prev:a.prev},a.prev=n[a.prev].next=s,s}{const s=n[a.prev],i=this.HEAD=this[o]=s.index;return this.index&&!(0,r.equal)(s.key,e)&&(this.index.delete(s.key,s.index),this.index.set(e,i)),s.key=e,s.value=t,i}}put(e,t,s){const i=this.search(e,s);return i?(i.value=t,i.index):this.add(e,t)}set(e,t,s){return this.put(e,t,s),this}search(e,t=this[o]){var s;const i=this.nodes;let n;if((n=i[t])&&(0,r.equal)(n.key,e))return this[o]=t,n;if(!this.index)throw new Error("Spica: IxList: Invalid index.");return 0===this.length||n&&1===this.length?void 0:(n=i[t=null!==(s=this.index.get(e))&&void 0!==s?s:this.capacity])?(this[o]=t,n):void 0}find(e,t){if(!this.index)throw new Error("Spica: IxList: No index.");return this.search(e,t)}get(e,t){var s;return null===(s=this.find(e,t))||void 0===s?void 0:s.value}has(e,t){return void 0!==this.find(e,t)}del(e,t){var s;const i=this[o],n=this.search(e,t);if(!n)return;this[o]=i,--this[c],this.buffers[this.buffers.length++]=n.index,null===(s=this.index)||void 0===s||s.delete(n.key,n.index);const r=this.nodes;return r[n.prev].next=n.next,r[n.next].prev=n.prev,this.HEAD===n.index&&(this.HEAD=n.next),this[o]===n.index&&(this[o]=n.next),r[n.index]=void 0,n}delete(e,t){return void 0!==this.del(e,t)}unshift(e,t){return this.add(e,t)}shift(){const e=this.nodes[this.HEAD];return e&&this.del(e.key,e.index)}push(e,t){return this.HEAD=this.nodes[this.add(e,t)].next}pop(){if(0===this.length)return;const e=this.nodes,t=e[e[this.HEAD].prev];return t&&this.del(t.key,t.index)}*[(i=o,n=c,Symbol.iterator)](){const e=this.nodes;for(let t=e[this.HEAD],s=0;t&&s<this.length;(t=e[t.next])&&++s)yield[t.key,t.value]}insert(e,t){if(e===t)return!1;const s=this.nodes,i=s[e];if(!i)return!1;const n=s[t];if(!n)return!1;if(i.next===n.index)return!1;const r=s[n.prev],o=s[i.prev],c=s[i.next];return r.next=i.index,i.next=n.index,n.prev=i.index,i.prev=r.index,o.next=c.index,c.prev=o.index,!0}moveToHead(e){return!(this.length<=1)&&(e!==this.HEAD&&(!!this.nodes[e]&&(this.insert(e,this.HEAD),this.HEAD=e,!0)))}moveToPrev(e){if(this.length<=1)return!1;if(e===this.HEAD)return!1;const t=this.nodes[e];return!!t&&(this.insert(t.index,t.prev),t.next===this.HEAD&&(this.HEAD=t.index),!0)}swap(e,t){if(this.length<=1)return!1;if(e===t)return!1;const s=this.nodes,i=s[e],n=s[t];if(!i||!n)return!1;if(i.next===n.index)return this.moveToPrev(t);if(n.next===i.index)return this.moveToPrev(e);switch(this.insert(n.index,i.index),this.insert(i.index,n.next),this.HEAD){case i.index:this.HEAD=n.index;break;case n.index:this.HEAD=i.index}return!0}}},{"../compare":8}],13:[function(e,t,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0}),s.noop=void 0,s.noop=function(){}},{}],14:[function(e,t,s){"use strict";var i,n;Object.defineProperty(s,"__esModule",{value:!0}),s.never=s.isPromiseLike=s.Internal=s.AtomicPromise=void 0;const r=e("./global"),o=e("./alias"),c=e("./noop"),a=Symbol.for("spica/promise::internal");class u{constructor(e){this[i]="Promise",this[n]=new h;try{e(e=>void this[a].resolve(e),e=>void this[a].reject(e))}catch(e){this[a].reject(e)}}static get[Symbol.species](){return u}static all(e){return new u((t,s)=>{const i=(0,o.isArray)(e)?e:[...e],n=(0,r.Array)(i.length);let c=0;for(let e=0;e<i.length;++e){const r=i[e];if(d(r)){if(p(r)){const{status:t}=r[a];switch(t.state){case 2:n[e]=t.value,++c;continue;case 3:s(t.reason),e=i.length;continue}}r.then(s=>{n[e]=s,++c===i.length&&t(n)},t=>{s(t),e=i.length})}else n[e]=r,++c}c===i.length&&t(n)})}static race(e){return new u((t,s)=>{const i=(0,o.isArray)(e)?e:[...e];for(let e=0;e<i.length;++e){const n=i[e];if(!d(n))return t(n);if(p(n)){const{status:e}=n[a];switch(e.state){case 2:return t(e.value);case 3:return s(e.reason)}}}let n=!1;for(let e=0;e<i.length;++e){if(i[e].then(e=>{t(e),n=!0},e=>{s(e),n=!0}),n)return}})}static allSettled(e){return new u(t=>{const s=(0,o.isArray)(e)?e:[...e],i=(0,r.Array)(s.length);let n=0;for(let e=0;e<s.length;++e){const r=s[e];if(d(r)){if(p(r)){const{status:t}=r[a];switch(t.state){case 2:i[e]={status:"fulfilled",value:t.value},++n;continue;case 3:i[e]={status:"rejected",reason:t.reason},++n;continue}}r.then(r=>{i[e]={status:"fulfilled",value:r},++n===s.length&&t(i)},r=>{i[e]={status:"rejected",reason:r},++n===s.length&&t(i)})}else i[e]={status:"fulfilled",value:r},++n}n===s.length&&t(i)})}static resolve(e){return new u(t=>t(e))}static reject(e){return new u((t,s)=>s(e))}then(e,t){return new u((s,i)=>this[a].then(s,i,e,t))}catch(e){return this.then(void 0,e)}finally(e){return this.then(e,e).then(()=>this)}}s.AtomicPromise=u,i=Symbol.toStringTag,n=a;class h{constructor(){this.status={state:0},this.fulfillReactions=[],this.rejectReactions=[]}get isPending(){return 0===this.status.state}resolve(e){if(0===this.status.state){if(!d(e))return this.status={state:2,value:e},this.resume();if(p(e)){const t=e[a];switch(t.status.state){case 2:case 3:return this.status=t.status,this.resume();default:return t.then(()=>(this.status=t.status,this.resume()),()=>(this.status=t.status,this.resume()))}}this.status={state:1,promise:e},e.then(e=>{this.status={state:2,value:e},this.resume()},e=>{this.status={state:3,reason:e},this.resume()})}}reject(e){if(0===this.status.state)return this.status={state:3,reason:e},this.resume()}then(e,t,s,i){const{status:n,fulfillReactions:r,rejectReactions:o}=this;switch(n.state){case 2:if(0!==r.length)break;return f(e,t,e,s,n.value);case 3:if(0!==o.length)break;return f(e,t,t,i,n.reason)}r.push([e,t,e,s]),o.push([e,t,t,i])}resume(){const{status:e,fulfillReactions:t,rejectReactions:s}=this;switch(e.state){case 0:case 1:return;case 2:if(0!==s.length&&(this.rejectReactions=[]),0===t.length)return;return l(t,e.value),void(this.fulfillReactions=[]);case 3:if(0!==t.length&&(this.fulfillReactions=[]),0===s.length)return;return l(s,e.reason),void(this.rejectReactions=[])}}}function l(e,t){for(let s=0;s<e.length;++s){const i=e[s];f(i[0],i[1],i[2],i[3],t)}}function f(e,t,s,i,n){if(!i)return s(n);try{e(i(n))}catch(e){t(e)}}function d(e){return null!==e&&"object"==typeof e&&"function"==typeof e.then}function p(e){return a in e}s.Internal=h,s.isPromiseLike=d,s.never=new class e extends Promise{static get[Symbol.species](){return e}constructor(){super(c.noop)}then(){return this}catch(){return this}finally(){return this}}},{"./alias":3,"./global":10,"./noop":13}],15:[function(e,t,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0}),s.tuple=void 0,s.tuple=function(...e){return e}},{}],16:[function(e,t,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0}),s.isPrimitive=s.isType=s.type=void 0;const i=e("./alias"),n=Object.prototype.toString.call.bind(Object.prototype.toString),r=Object.prototype,o=Array.prototype;function c(e){if(void 0===e)return"undefined";if(null===e)return"null";const t=typeof e;if("object"===t){const t=(0,i.ObjectGetPrototypeOf)(e);return t===r||null===t?"Object":t===o?"Array":n(e).slice(8,-1)}return"function"===t?"Function":t}s.type=c,s.isType=function(e,t){return"object"===t?null!==e&&typeof e===t:"function"===t?typeof e===t:c(e)===t},s.isPrimitive=function(e){const t=typeof e;return"object"!==t&&"function"!==t||null===e}},{"./alias":3}],"dw-cache":[function(e,t,s){"use strict";var i=this&&this.__createBinding||(Object.create?function(e,t,s,i){void 0===i&&(i=s),Object.defineProperty(e,i,{enumerable:!0,get:function(){return t[s]}})}:function(e,t,s,i){void 0===i&&(i=s),e[i]=t[s]}),n=this&&this.__exportStar||function(e,t){for(var s in e)"default"===s||Object.prototype.hasOwnProperty.call(t,s)||i(t,e,s)};Object.defineProperty(s,"__esModule",{value:!0}),n(e("spica/cache"),s)},{"spica/cache":6}]},{},[1,2,"dw-cache"]),function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof module&&module.exports?module.exports=t():Object.assign(e,t())}("undefined"!=typeof self?self:this,function(){return require("dw-cache")}); |
{ | ||
"name": "dw-cache", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "Dual window cache adaptively coordinates the ratio of LRU to LFU using the two sliding windows.", | ||
@@ -55,5 +55,5 @@ "private": false, | ||
"power-assert": "^1.6.1", | ||
"spica": "0.0.466", | ||
"spica": "0.0.467", | ||
"tsify": "^5.0.2", | ||
"typescript": "4.3.0-dev.20210308", | ||
"typescript": "4.3.0-dev.20210309", | ||
"vinyl-buffer": "^1.0.1", | ||
@@ -60,0 +60,0 @@ "vinyl-source-stream": "^2.0.0" |
@@ -20,29 +20,29 @@ # Dual Window Cache | ||
``` | ||
'LRU hit rate even 100', 10.148 | ||
'DWC hit rate even 100', 10.1365 | ||
'LFU ratio even 100', 10, 10 | ||
'DWC / LRU hit rate ratio even 100', '99%' | ||
'LRU hit rate even 100', 9.9055 | ||
'DWC hit rate even 100', 9.952 | ||
'LFU ratio even 100', 25, 25 | ||
'DWC / LRU hit rate ratio even 100', '100%' | ||
'LRU hit rate uneven 100', 18.5135 | ||
'DWC hit rate uneven 100', 37.4355 | ||
'LFU ratio uneven 100', 100, 97 | ||
'LRU hit rate uneven 100', 18.61 | ||
'DWC hit rate uneven 100', 37.6625 | ||
'LFU ratio uneven 100', 99, 97 | ||
'DWC / LRU hit rate ratio uneven 100', '202%' | ||
'LRU hit rate uneven 100 transitive distribution', 18.3445 | ||
'DWC hit rate uneven 100 transitive distribution', 37.869 | ||
'LFU ratio uneven 100 transitive distribution', 99, 95 | ||
'DWC / LRU hit rate ratio uneven 100 transitive distribution', '206%' | ||
'LRU hit rate uneven 100 transitive distribution', 18.4585 | ||
'DWC hit rate uneven 100 transitive distribution', 37.8625 | ||
'LFU ratio uneven 100 transitive distribution', 100, 98 | ||
'DWC / LRU hit rate ratio uneven 100 transitive distribution', '205%' | ||
'LRU hit rate uneven 100 transitive bias', 17.4255 | ||
'DWC hit rate uneven 100 transitive bias', 16.398 | ||
'LFU ratio uneven 100 transitive bias', 39, 39 | ||
'LRU hit rate uneven 100 transitive bias', 17.553 | ||
'DWC hit rate uneven 100 transitive bias', 16.5685 | ||
'LFU ratio uneven 100 transitive bias', 53, 53 | ||
'DWC / LRU hit rate ratio uneven 100 transitive bias', '94%' | ||
'LRU hit rate uneven 100 sequential', 14.03 | ||
'DWC hit rate uneven 100 sequential', 39.202 | ||
'LFU ratio uneven 100 sequential', 100, 98 | ||
'DWC / LRU hit rate ratio uneven 100 sequential', '279%' | ||
'LRU hit rate uneven 100 sequential', 14.195 | ||
'DWC hit rate uneven 100 sequential', 39.3425 | ||
'LFU ratio uneven 100 sequential', 100, 97 | ||
'DWC / LRU hit rate ratio uneven 100 sequential', '277%' | ||
'LRU hit rate uneven 100 adversarial', 42.0645 | ||
'DWC hit rate uneven 100 adversarial', 42.6775 | ||
'LRU hit rate uneven 100 adversarial', 42.0015 | ||
'DWC hit rate uneven 100 adversarial', 42.6085 | ||
'LFU ratio uneven 100 adversarial', 10, 10 | ||
@@ -52,5 +52,5 @@ 'DWC / LRU hit rate ratio uneven 100 adversarial', '101%' | ||
https://github.com/falsandtru/spica/runs/2061824226 | ||
https://github.com/falsandtru/spica/runs/2066756277 | ||
### Benchmark (ops/sec) | ||
### Benchmark | ||
@@ -60,20 +60,20 @@ Slower x0.0-0.2 of [lru-cache](https://www.npmjs.com/package/lru-cache). | ||
``` | ||
'LRUCache get/set 100 x 4,363,797 ops/sec ±0.86% (61 runs sampled)' | ||
'LRUCache simulation 100 x 3,080,367 ops/sec ±1.70% (64 runs sampled)' | ||
'DW-Cache get/set 100 x 3,309,959 ops/sec ±0.62% (65 runs sampled)' | ||
'DW-Cache simulation 100 x 2,469,946 ops/sec ±3.19% (59 runs sampled)' | ||
'LRUCache get/set 1,000 x 3,052,910 ops/sec ±6.82% (49 runs sampled)' | ||
'LRUCache simulation 1,000 x 2,958,544 ops/sec ±1.29% (65 runs sampled)' | ||
'DW-Cache get/set 1,000 x 3,409,339 ops/sec ±0.94% (62 runs sampled)' | ||
'DW-Cache simulation 1,000 x 2,426,789 ops/sec ±3.66% (58 runs sampled)' | ||
'LRUCache get/set 10,000 x 2,718,037 ops/sec ±3.98% (50 runs sampled)' | ||
'LRUCache simulation 10,000 x 1,842,352 ops/sec ±3.79% (60 runs sampled)' | ||
'DW-Cache get/set 10,000 x 2,595,130 ops/sec ±3.02% (58 runs sampled)' | ||
'DW-Cache simulation 10,000 x 1,710,835 ops/sec ±3.31% (58 runs sampled)' | ||
'LRUCache get/set 100,000 x 1,463,442 ops/sec ±2.76% (56 runs sampled)' | ||
'LRUCache simulation 100,000 x 928,464 ops/sec ±3.91% (58 runs sampled)' | ||
'DW-Cache get/set 100,000 x 1,454,421 ops/sec ±4.33% (56 runs sampled)' | ||
'DW-Cache simulation 100,000 x 842,602 ops/sec ±2.69% (57 runs sampled)' | ||
``` | ||
https://github.com/falsandtru/spica/runs/2061836649 | ||
https://github.com/falsandtru/spica/runs/2066774887 | ||
@@ -80,0 +80,0 @@ ## API |
Sorry, the diff of this file is too big to display
525848
12392