@creejs/commons-collection 2.0.4 → 2.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,7 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.CommonsLang = {}));
5
5
  })(this, (function (exports) { 'use strict';
6
6
 
7
- function a$1(t){return "boolean"==typeof t}function c$1(t){return "function"==typeof t}function l$1(t){return null!=t&&"object"==typeof t&&!A(t)}function y(t){return null==t}function p$1(t){return !!m$1(t)&&t>0}function h$1(t){return !!m$1(t)&&t>=0}function g$1(t){return !!m$1(t)&&t<0}function w$1(t){return null===t}function d$1(t){return void 0===t}function m$1(t){return null!=t&&"number"==typeof t}function b$1(t){return null!=t&&"object"==typeof t}function A(t){return null!==t&&"object"==typeof t&&(t.constructor===Object||void 0===t.constructor)}function E(t){return null!=t&&"function"==typeof t.then}function N(t){return null!=t&&"string"==typeof t}function $(t){return null!=t&&"symbol"==typeof t}function O$1(t){return ArrayBuffer.isView(t)&&t.constructor!==DataView}function v$1(t){return t instanceof Int8Array}function j(t){return t instanceof Uint8Array}function P(t){return t instanceof Uint8ClampedArray}function S(t){return t instanceof Int16Array}function x(t){return t instanceof Uint16Array}function U(t){return t instanceof Int32Array}function T(t){return t instanceof Uint32Array}function I(t){return t instanceof Float32Array}function B(t){return t instanceof Float64Array}function k$1(t){return t instanceof BigInt64Array}function L$1(t){return t instanceof BigUint64Array}function F(t){return t instanceof ArrayBuffer}var C={assertNumber:q,assertPositive:_$1,assertNegative:function(t,r){if(!g$1(t))throw new Error(`${r?'"'+r+'" ':""}Not Negative: ${t}`)},assertNotNegative:J,assertBoolean:function(t,r){if(!a$1(t))throw new Error(`${r?'"'+r+'" ':""}Not Boolean: type=${typeof t} value=${Z(t)}`)},assertObject:R,assertPlainObject:function(t,r){if(!A(t))throw new Error(`${r?'"'+r+'" ':""}Not PlainObject: type=${typeof t} value=${Z(t)}`)},assertSymbol:function(t,r){if(!$(t))throw new Error(`${r?'"'+r+'" ':""}Not Symbol: type=${typeof t} value=${Z(t)}`)},assertFunction:W,assertInstance:function(t,r){if(!l$1(t))throw new Error(`${r?'"'+r+'" ':""}Not Class Instance: type=${typeof t} value=${Z(t)}`)},assertPromise:H,assertNil:function(t,r){if(!y(t))throw new Error(`${r?'"'+r+'" ':""}Neither Null nor Undefined: type=${typeof t} value=${Z(t)}`)},assertNotNil:V,assertNull:function(t,r){if(!w$1(t))throw new Error(`${r?'"'+r+'" ':""}Not Null: type=${typeof t} value=${Z(t)}`)},assertNotNull:function(t,r){if(w$1(t))throw new Error((r?'"'+r+'" ':"")+"Should Not Null")},assertUndefined:function(t,r){if(!d$1(t))throw new Error(`${r?'"'+r+'" ':""}Not Undefined: type=${typeof t} value=${Z(t)}`)},assertString:M,assertArray:D,assertStringOrSymbol:function(t,r){if(!N(t)&&!$(t))throw new Error(`${r?'"'+r+'" ':""}Not String or Symbol: type=${typeof t} value=${Z(t)}`)},assertInt8Array:function(t,r){if(v$1(t))throw new Error((r?'"'+r+'" ':"")+"Not Int8Array")},assertUint8Array:function(t,r){if(j(t))throw new Error((r?'"'+r+'" ':"")+"Not Uint8Array")},assertUint8ClampedArray:function(t,r){if(P(t))throw new Error((r?'"'+r+'" ':"")+"Not Uint8ClampedArray")},assertInt16Array:function(t,r){if(S(t))throw new Error((r?'"'+r+'" ':"")+"Not Int16Array")},assertUint16Array:function(t,r){if(x(t))throw new Error((r?'"'+r+'" ':"")+"Not Uint16Array")},assertInt32Array:function(t,r){if(U(t))throw new Error((r?'"'+r+'" ':"")+"Not Int32Array")},assertUint32Array:function(t,r){if(T(t))throw new Error((r?'"'+r+'" ':"")+"Not Uint32Array")},assertFloat32Array:function(t,r){if(I(t))throw new Error((r?'"'+r+'" ':"")+"Not Float32Array")},assertFloat64Array:function(t,r){if(B(t))throw new Error((r?'"'+r+'" ':"")+"Not Float64Array")},assertBigInt64Array:function(t,r){if(k$1(t))throw new Error((r?'"'+r+'" ':"")+"Not BigInt64Array")},assertBigUint64Array:function(t,r){if(L$1(t))throw new Error((r?'"'+r+'" ':"")+"Not BigUint64Array")},assertTypedArray:function(t,r){if(O$1(t))throw new Error((r?'"'+r+'" ':"")+"Not TypedArray")},assertArrayBuffer:z};function D(t,r){if(!Array.isArray(t))throw new Error(`${r?'"'+r+'" ':""}Not Array: type=${typeof t} value=${Z(t)}`)}function M(t,r){if(!N(t))throw new Error(`${r?'"'+r+'" ':""}Not String: type=${typeof t} value=${Z(t)}`)}function q(t,r){if(!m$1(t))throw new Error(`${r?'"'+r+'" ':""}Not Number: type=${typeof t} value=${Z(t)}`)}function _$1(t,r){if(!p$1(t))throw new Error(`${r?'"'+r+'" ':""}Not Positive: ${t}`)}function J(t,r){if(!h$1(t))throw new Error(`${r?'"'+r+'" ':""}Not "0 or Positive": ${t}`)}function R(t,r){if(!b$1(t))throw new Error(`${r?'"'+r+'" ':""}Not Object: type=${typeof t} value=${Z(t)}`)}function W(t,r){if(!c$1(t))throw new Error(`${r?'"'+r+'" ':""}Not Function: type=${typeof t} value=${Z(t)}`)}function H(t,r){if(!E(t))throw new Error(`${r?'"'+r+'" ':""}Not Promise: type=${typeof t} value=${Z(t)}`)}function V(t,r){if(y(t))throw new Error((r?'"'+r+'" ':"")+"Should Not Nil")}function z(t,r){if(!F(t))throw new Error((r?'"'+r+'" ':"")+"Not ArrayBuffer")}function Z(t){if(null===t)return "null";if(void 0===t)return "undefined";let r;try{r=JSON.stringify(t);}catch(e){r=t.toString();}return r}new TextDecoder;new TextEncoder;const dt=1e6;var mt={s2ns:1e9,ms2ns:dt,timestamp:function(){if("undefined"!=typeof performance&&"number"==typeof performance.timeOrigin){const t=performance.timeOrigin,r=performance.now();return Math.ceil((t+r)/dt)}return Date.now()},timestamp64:bt,lapseNano:At,lapseMillis:Et,timeoutNano:function(t,r){return At(t)>r},timeoutMillis:function(t,r){return Et(t)>r}};function bt(){if("undefined"!=typeof performance&&"number"==typeof performance.timeOrigin){const t=performance.timeOrigin,r=performance.now();return BigInt((t+r)*dt)}return BigInt(Date.now()*dt)}function At(t,r){return (r??bt())-t}function Et(t,r){r=r??bt();return BigInt(r-t)/BigInt(dt)}
7
+ function a$1(t){return "boolean"==typeof t}function c$1(t){return "function"==typeof t}function l$1(t){return null!=t&&"object"==typeof t&&!A(t)}function y(t){return null==t}function p$1(t){return !!m$1(t)&&t>0}function h$1(t){return !!m$1(t)&&t>=0}function g$1(t){return !!m$1(t)&&t<0}function w$1(t){return null===t}function d$1(t){return void 0===t}function m$1(t){return null!=t&&"number"==typeof t}function b$1(t){return null!=t&&"object"==typeof t}function A(t){return null!==t&&"object"==typeof t&&(t.constructor===Object||void 0===t.constructor)}function E(t){return null!=t&&"function"==typeof t.then}function N(t){return null!=t&&"string"==typeof t}function $(t){return null!=t&&"symbol"==typeof t}function O$1(t){return ArrayBuffer.isView(t)&&t.constructor!==DataView}function v$1(t){return t instanceof Int8Array}function P(t){return t instanceof Uint8Array}function j(t){return t instanceof Uint8ClampedArray}function S(t){return t instanceof Int16Array}function x(t){return t instanceof Uint16Array}function U(t){return t instanceof Int32Array}function T(t){return t instanceof Uint32Array}function I(t){return t instanceof Float32Array}function B(t){return t instanceof Float64Array}function k$1(t){return t instanceof BigInt64Array}function L$1(t){return t instanceof BigUint64Array}function F(t){return t instanceof ArrayBuffer}var C={assertNumber:q,assertPositive:_$1,assertNegative:function(t,r){if(!g$1(t))throw new Error(`${r?'"'+r+'" ':""}Not Negative: ${t}`)},assertNotNegative:R,assertBoolean:function(t,r){if(!a$1(t))throw new Error(`${r?'"'+r+'" ':""}Not Boolean: type=${typeof t} value=${Z(t)}`)},assertObject:J,assertPlainObject:function(t,r){if(!A(t))throw new Error(`${r?'"'+r+'" ':""}Not PlainObject: type=${typeof t} value=${Z(t)}`)},assertSymbol:function(t,r){if(!$(t))throw new Error(`${r?'"'+r+'" ':""}Not Symbol: type=${typeof t} value=${Z(t)}`)},assertFunction:W,assertInstance:function(t,r){if(!l$1(t))throw new Error(`${r?'"'+r+'" ':""}Not Class Instance: type=${typeof t} value=${Z(t)}`)},assertPromise:H,assertNil:function(t,r){if(!y(t))throw new Error(`${r?'"'+r+'" ':""}Neither Null nor Undefined: type=${typeof t} value=${Z(t)}`)},assertNotNil:V,assertNull:function(t,r){if(!w$1(t))throw new Error(`${r?'"'+r+'" ':""}Not Null: type=${typeof t} value=${Z(t)}`)},assertNotNull:function(t,r){if(w$1(t))throw new Error((r?'"'+r+'" ':"")+"Should Not Null")},assertUndefined:function(t,r){if(!d$1(t))throw new Error(`${r?'"'+r+'" ':""}Not Undefined: type=${typeof t} value=${Z(t)}`)},assertString:D,assertArray:M,assertStringOrSymbol:function(t,r){if(!N(t)&&!$(t))throw new Error(`${r?'"'+r+'" ':""}Not String or Symbol: type=${typeof t} value=${Z(t)}`)},assertInt8Array:function(t,r){if(v$1(t))throw new Error((r?'"'+r+'" ':"")+"Not Int8Array")},assertUint8Array:function(t,r){if(P(t))throw new Error((r?'"'+r+'" ':"")+"Not Uint8Array")},assertUint8ClampedArray:function(t,r){if(j(t))throw new Error((r?'"'+r+'" ':"")+"Not Uint8ClampedArray")},assertInt16Array:function(t,r){if(S(t))throw new Error((r?'"'+r+'" ':"")+"Not Int16Array")},assertUint16Array:function(t,r){if(x(t))throw new Error((r?'"'+r+'" ':"")+"Not Uint16Array")},assertInt32Array:function(t,r){if(U(t))throw new Error((r?'"'+r+'" ':"")+"Not Int32Array")},assertUint32Array:function(t,r){if(T(t))throw new Error((r?'"'+r+'" ':"")+"Not Uint32Array")},assertFloat32Array:function(t,r){if(I(t))throw new Error((r?'"'+r+'" ':"")+"Not Float32Array")},assertFloat64Array:function(t,r){if(B(t))throw new Error((r?'"'+r+'" ':"")+"Not Float64Array")},assertBigInt64Array:function(t,r){if(k$1(t))throw new Error((r?'"'+r+'" ':"")+"Not BigInt64Array")},assertBigUint64Array:function(t,r){if(L$1(t))throw new Error((r?'"'+r+'" ':"")+"Not BigUint64Array")},assertTypedArray:function(t,r){if(O$1(t))throw new Error((r?'"'+r+'" ':"")+"Not TypedArray")},assertArrayBuffer:z};function M(t,r){if(!Array.isArray(t))throw new Error(`${r?'"'+r+'" ':""}Not Array: type=${typeof t} value=${Z(t)}`)}function D(t,r){if(!N(t))throw new Error(`${r?'"'+r+'" ':""}Not String: type=${typeof t} value=${Z(t)}`)}function q(t,r){if(!m$1(t))throw new Error(`${r?'"'+r+'" ':""}Not Number: type=${typeof t} value=${Z(t)}`)}function _$1(t,r){if(!p$1(t))throw new Error(`${r?'"'+r+'" ':""}Not Positive: ${t}`)}function R(t,r){if(!h$1(t))throw new Error(`${r?'"'+r+'" ':""}Not "0 or Positive": ${t}`)}function J(t,r){if(!b$1(t))throw new Error(`${r?'"'+r+'" ':""}Not Object: type=${typeof t} value=${Z(t)}`)}function W(t,r){if(!c$1(t))throw new Error(`${r?'"'+r+'" ':""}Not Function: type=${typeof t} value=${Z(t)}`)}function H(t,r){if(!E(t))throw new Error(`${r?'"'+r+'" ':""}Not Promise: type=${typeof t} value=${Z(t)}`)}function V(t,r){if(y(t))throw new Error((r?'"'+r+'" ':"")+"Should Not Nil")}function z(t,r){if(!F(t))throw new Error((r?'"'+r+'" ':"")+"Not ArrayBuffer")}var G={isEmpty:K,assertNotEmpty:Y,isBlank:Q,assertNotBlank:function(t,r){if(Q(t))throw new Error(`${r?'"'+r+'" ':""}Is Blank: ${t}`)},capitalize:function(t){if(D(t),0===t.length)return t;const r=t.charAt(0),e=r.toUpperCase();return r===e?t:e+t.slice(1)},decapitalize:function(t){if(D(t),0===t.length)return t;const r=t.charAt(0),e=r.toLowerCase();return r===e?t:e+t.slice(1)},splitWithFixedLength:function(t,r,e=" "){if(D(t),q(r),D(e),0===t.length)return [];if(r<=0)throw new Error("length muse >=0");if(t.length<r)return [t.padEnd(r,e)];const n=[];for(let o=0;o<t.length;o+=r){const i=t.substring(o,o+r);n.push(i.padEnd(r,e));}return n},split:function(t,...r){D(t);if(0===t.length)return [];const e=[...r];0===r.length&&r.push(",");const n=X(t,...e);if(0===n.length)return [];const o=[];let i="",s=0;for(const{marker:r,index:e}of n)i=t.substring(s,e),o.push(i),s=e+r.length;return i=t.substring(s),o.push(i),o},findMarkerPositions:function(t,...r){if(D(t),0===r.length)throw new Error("At least one marker must be provided");const e=[];for(const n of new Set(r)){if(K(n))continue;D(n);let r=t.indexOf(n);for(;-1!==r;)e.push({marker:n,index:r}),r=t.indexOf(n,r+n.length);}return e.sort((t,r)=>t.index-r.index),e},findMarkerPositionsRegex:X,substringBefore:function(t,r){if(D(t),D(r),0===t.length||0===r.length)return;const e=t.indexOf(r);if(-1===e)return;return t.substring(0,e)},substringBeforeLast:function(t,r){if(D(t),D(r),0===t.length||0===r.length)return;const e=t.lastIndexOf(r);if(-1===e)return;return t.substring(0,e)},substringAfter:function(t,r){if(D(t),D(r),0===t.length||0===r.length)return;const e=t.indexOf(r);if(-1===e)return;return t.substring(e+r.length)},substringAfterLast:function(t,r){if(D(t),D(r),0===t.length||0===r.length)return;const e=t.lastIndexOf(r);if(-1===e)return;return t.substring(e+r.length)},substringBetween:function(t,r,e){Y(t),Y(r),Y(e);const n=t.indexOf(r);if(-1===n)return;const o=t.indexOf(e,n+r.length);if(-1===o)return;return t.substring(n+r.length,o)},substringBetweenGreedy:function(t,r,e){Y(t),Y(r),Y(e);const n=t.indexOf(r);if(-1===n)return;const o=t.lastIndexOf(e);if(-1===o||o<=n)return;return t.substring(n+r.length,o)},substringsBetween:function(t,r,e){Y(t),Y(r),Y(e);const n=[];let o=0;for(;;){const i=t.indexOf(r,o);if(-1===i)break;const s=t.indexOf(e,i+r.length);if(-1===s)break;n.push(t.substring(i+r.length,s)),o=s+e.length;}return n},safeToString:Z};function K(t){return null==t||(D(t),0===t.length)}function Y(t,r){if(K(t))throw new Error(`${r?'"'+r+'" ':""}IsEmpty String: ${t}`)}function Q(t){return null==t||(D(t),0===t.trim().length)}function X(t,...r){if(D(t),0===r.length)throw new Error("At least one marker must be provided");const e=[...new Set(r.filter(t=>null!=t))].map(t=>(D(t),t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"))),n=new RegExp(e.map(t=>`(${t})`).join("|"),"g"),o=[];let i=null;for(;null!==(i=n.exec(t));){for(let t=1;t<i.length;t++)if(i[t]){o.push({marker:r[t-1],index:i.index});break}0===i[0].length&&n.lastIndex++;}return o}function Z(t){if(null===t)return "null";if(void 0===t)return "undefined";const r=typeof t;if("string"===r)return t;if("symbol"===r)return `Symbol(${t.description})`;if("function"===r)return `Function ${t.name}(){}`;if(t instanceof String)return t.toString();if(Number.isNaN(t))return "NaN";if(t===1/0)return "Infinity";if(t===-1/0)return "-Infinity";if(t instanceof Error)return `${t.constructor.name}: ${t.message}`;if(t instanceof Promise)return "Promise";if(t instanceof Set)return `Set: ${Z(Array.from(t))}`;if(t instanceof Map)return `Map: ${Z(Array.from(t.entries()))}`;if(t instanceof RegExp)return t.toString();if(Array.isArray(t))return `[${t.map(Z).join(", ")}]`;let e;try{e=JSON.stringify(t);}catch(r){e=t.toString();}return e}new TextDecoder;new TextEncoder;const dt=1e6;var mt={s2ns:1e9,ms2ns:dt,timestamp:function(){if("undefined"!=typeof performance&&"number"==typeof performance.timeOrigin){const t=performance.timeOrigin,r=performance.now();return Math.ceil((t+r)/dt)}return Date.now()},timestamp64:bt,lapseNano:At,lapseMillis:Et,timeoutNano:function(t,r){return At(t)>r},timeoutMillis:function(t,r){return Et(t)>r}};function bt(){if("undefined"!=typeof performance&&"number"==typeof performance.timeOrigin){const t=performance.timeOrigin,r=performance.now();return BigInt((t+r)*dt)}return BigInt(Date.now()*dt)}function At(t,r){return (r??bt())-t}function Et(t,r){r=r??bt();return BigInt(r-t)/BigInt(dt)}
8
8
 
9
9
  // internal
10
10
  // owned
@@ -18,7 +18,7 @@
18
18
  */
19
19
 
20
20
  // module vars
21
- const { assertPositive } = C;
21
+ const { assertPositive: assertPositive$2 } = C;
22
22
 
23
23
  /**
24
24
  * A set that has a fixed capacity and automatically removes the oldest element when the capacity is reached.
@@ -33,7 +33,7 @@
33
33
  * @throws {Error} If capacity is less than or equal to 0
34
34
  */
35
35
  constructor (capacity) {
36
- assertPositive(capacity, 'capacity');
36
+ assertPositive$2(capacity, 'capacity');
37
37
  this.capacity = capacity;
38
38
  /**
39
39
  * 1. key is the Value stored in CappedSet
@@ -177,7 +177,7 @@
177
177
  }
178
178
  }
179
179
 
180
- var e={isFunction:t,isNil:s};function t(e){return "function"==typeof e}function s(e){return null==e}function n(e){return null!=e&&"string"==typeof e}var r={assertNumber:function(e,t){if(!function(e){return null!=e&&"number"==typeof e}(e))throw new Error(`${t?'"'+t+'" ':""}Not Number: type=${typeof e} value=${i(e)}`)},assertFunction:function(e,s){if(!t(e))throw new Error(`${s?'"'+s+'" ':""}Not Function: type=${typeof e} value=${i(e)}`)},assertNotNil:function(e,t){if(s(e))throw new Error((t?'"'+t+'" ':"")+"Should Not Nil")},assertString:function(e,t){if(!n(e))throw new Error(`${t?'"'+t+'" ':""}Not String: type=${typeof e} value=${i(e)}`)},assertStringOrSymbol:function(e,t){if(!n(e)&&!function(e){return null!=e&&"symbol"==typeof e}(e))throw new Error(`${t?'"'+t+'" ':""}Not String or Symbol: type=${typeof e} value=${i(e)}`)}};function i(e){if(null===e)return "null";if(void 0===e)return "undefined";let t;try{t=JSON.stringify(e);}catch(s){t=e.toString();}return t}new TextDecoder,new TextEncoder;const l="DOwner$#$",{assertFunction:a,assertNotNil:o}=r;class c{constructor(e,t,s=false){o(e,"event"),a(t,"callback"),this._event=e,this._callback=t,this._isOnce=!!s,this._owner=void 0;}set owner(e){this._owner=e;}get owner(){return this._owner===l?void 0:this._owner}get event(){return this._event}get isOnce(){return this._isOnce}isSameCallback(e){return this._callback===e}get callback(){return this._callback}invoke(...e){try{return this._callback(...e)}finally{if(this._isOnce)try{this._event._remove(this);}catch(e){console.warn(e);}}}listener(...e){return this.invoke(...e)}}const{isFunction:h,isNil:u}=e,{assertStringOrSymbol:_,assertFunction:f}=r;class m{static get DefaultOwner(){return l}constructor(e){_(e,"eventName"),this._name=e,this._callbacks=new Set,this._listeners=[],this._callback2Listeners=new Map,this._listener2Owner=new Map,this._owner2Listeners=new Map;}get name(){return this._name}isEmpty(){return 0===this._callbacks.size}rawListeners(){return [...this._listeners]}listenerCount(e){return null==e?this._listeners.length:this._callback2Listeners.get(e)?.size??0}callbacks(){return [...this.rawListeners().map(e=>e.callback)]}emit(...e){if(0===this._listeners.length)return false;for(const t of [...this._listeners])t.invoke(...e);return true}emitOwner(e,...t){if(0===this._listeners.length)return false;const s=this._owner2Listeners.get(e);if(null==s)return false;for(const e of [...s])e.invoke(...t);return true}hasListener(e){return !!h(e)&&this._callbacks.has(e)}hasOwner(e){return !u(e)&&this._owner2Listeners.has(e)}addListener(e,t){return this._addListener(e,t,false,false)}prependListener(e,t){return this._addListener(e,t,false,true)}addOnceListener(e,t){return this._addListener(e,t,true,false)}prependOnceListener(e,t){return this._addListener(e,t,true,true)}_addListener(e,t,s,n){if(u(e))return false;f(e),this._callbacks.has(e)||this._callbacks.add(e),t=t??l;const r=new c(this,e,s);r.owner=t,n?this._listeners.unshift(r):this._listeners.push(r),this._listener2Owner.set(r,t);let i=this._callback2Listeners.get(e);null==i&&(i=new Set,this._callback2Listeners.set(e,i)),i.add(r);let a=this._owner2Listeners.get(t);return null==a&&(a=new Set,this._owner2Listeners.set(t,a)),a.add(r),true}removeListener(e){if(u(e))return false;if(!this._callbacks.has(e))return false;this._callbacks.delete(e);const t=this._callback2Listeners.get(e);if(null==t)return false;this._callback2Listeners.delete(e);for(const e of t){ -1!==this._listeners.indexOf(e)&&this._listeners.splice(this._listeners.indexOf(e),1);const t=this._listener2Owner.get(e);if(null==t)continue;this._listener2Owner.delete(e);const s=this._owner2Listeners.get(t);null!=s&&(s.delete(e),0===s.size&&this._owner2Listeners.delete(t));}return true}_remove(e){const t=this._listeners.indexOf(e);-1!==t&&this._listeners.splice(t,1);const{callback:s}=e,n=this._callback2Listeners.get(s);null!=n&&(n.delete(e),0===n.size&&(this._callback2Listeners.delete(s),this._callbacks.delete(s)));const r=this._listener2Owner.get(e);if(null==r)return;this._listener2Owner.delete(e);const i=this._owner2Listeners.get(r);null!=i&&(i.delete(e),0===i.size&&this._owner2Listeners.delete(r));}removeAllListeners(e){if(u(e))return this._callbacks.clear(),this._listeners.length=0,this._callback2Listeners.clear(),this._listener2Owner.clear(),this._owner2Listeners.clear(),this;const t=this._owner2Listeners.get(e);if(null==t)return this;this._owner2Listeners.delete(e);for(const e of t){ -1!==this._listeners.indexOf(e)&&this._listeners.splice(this._listeners.indexOf(e),1),this._listener2Owner.delete(e);const{callback:t}=e,s=this._callback2Listeners.get(t);null!=s&&(s.delete(e),0===s.size&&(this._callback2Listeners.delete(t),this._callbacks.delete(t)));}return this}}const{isNil:d}=e,{assertString:w,assertFunction:L,assertNumber:v,assertStringOrSymbol:g,assertNotNil:p}=r,b=["on","once","addListener","prependListener","prependOnceListener","off","offAll","offOwner","removeAllListeners","removeListener","emit","emitOwner","setMaxListeners","getMaxListeners","hasOwner","listeners","listenerCount","eventNames","rawListeners"];let O=10;class k{static mixin(e){const t=new k;e.__emitter=t;for(const s of b){const n=t[s];e[s]=n.bind(t);}return e}static get defaultMaxListeners(){return O}static set defaultMaxListeners(e){v(e),O=e??10;}constructor(){this._name2Event=new Map,this._maxListeners=O;}addListener(e,t,s){return this.on(e,t,s)}prependListener(e,t,s){w(e),L(t),this._checkMaxListeners(e);return this._getOrCreateEvent(e).prependListener(t,s),this}prependOnceListener(e,t,s){w(e),L(t),this._checkMaxListeners(e);return this._getOrCreateEvent(e).prependOnceListener(t,s),this}emit(e,...t){const s=this._name2Event.get(e);return null!=s&&!s.isEmpty()&&(s.emit(...t),true)}emitOwner(e,t,...s){if(null==t)throw new Error('Missing "owner"');const n=this._name2Event.get(e);return null!=n&&!n.isEmpty()&&(n.emitOwner(t,...s),true)}eventNames(){return [...this._name2Event.keys()]}getMaxListeners(){return this._maxListeners}listenerCount(e,t){g(e,"eventName");const s=this._name2Event.get(e);return null==s||s.isEmpty()?0:s.listenerCount(t)}listeners(e){g(e,"eventName");const t=this._name2Event.get(e);return null==t||t.isEmpty()?[]:t.callbacks()}off(e,t){const s=this._name2Event.get(e);return null==s?this:(s.removeListener(t),s.isEmpty()?(this._name2Event.delete(e),this):this)}offAll(e,t){g(e,"eventName");const s=this._name2Event.get(e);return null==s?this:(s.removeAllListeners(t),s.isEmpty()?(this._name2Event.delete(e),this):this)}offOwner(e){p(e,"owner");const t=[...this._name2Event.values()];for(const s of t)s.removeAllListeners(e),s.isEmpty()&&this._name2Event.delete(s.name);return this}on(e,t,s){w(e),L(t),this._checkMaxListeners(e);return this._getOrCreateEvent(e).addListener(t,s),this}_checkMaxListeners(e){let t=0;0!==this._maxListeners&&this._maxListeners!==1/0&&(t=this.listenerCount(e))>=this._maxListeners&&console.warn(`maxlistenersexceededwarning: Possible EventEmitter memory leak detected. ${t} ${e} listeners added to [${this}]. Use emitter.setMaxListeners() to increase limit`);}once(e,t,s){w(e),L(t);return this._getOrCreateEvent(e).addOnceListener(t,s),this}rawListeners(e){return this._name2Event.get(e)?.rawListeners()||[]}removeAllListeners(e,t){return this.offAll(e,t)}removeListener(e,t){return this.off(e,t)}setMaxListeners(e){if(v(e),e<0)throw new RangeError("maxListeners must >=0");return this._maxListeners=e,this}_getOrCreateEvent(e){if(this._name2Event.has(e))return this._name2Event.get(e);const t=new m(e);return this._name2Event.set(e,t),t}hasOwner(e){if(d(e))return false;for(const t of this._name2Event.values())if(t.hasOwner(e))return true;return false}}
180
+ var e={isFunction:t,isNil:n};function t(e){return "function"==typeof e}function n(e){return null==e}function s(e){return null!=e&&"string"==typeof e}var r={assertNumber:function(e,t){if(!function(e){return null!=e&&"number"==typeof e}(e))throw new Error(`${t?'"'+t+'" ':""}Not Number: type=${typeof e} value=${i(e)}`)},assertFunction:function(e,n){if(!t(e))throw new Error(`${n?'"'+n+'" ':""}Not Function: type=${typeof e} value=${i(e)}`)},assertNotNil:function(e,t){if(n(e))throw new Error((t?'"'+t+'" ':"")+"Should Not Nil")},assertString:function(e,t){if(!s(e))throw new Error(`${t?'"'+t+'" ':""}Not String: type=${typeof e} value=${i(e)}`)},assertStringOrSymbol:function(e,t){if(!s(e)&&!function(e){return null!=e&&"symbol"==typeof e}(e))throw new Error(`${t?'"'+t+'" ':""}Not String or Symbol: type=${typeof e} value=${i(e)}`)}};function i(e){if(null===e)return "null";if(void 0===e)return "undefined";const t=typeof e;if("string"===t)return e;if("symbol"===t)return `Symbol(${e.description})`;if("function"===t)return `Function ${e.name}(){}`;if(e instanceof String)return e.toString();if(Number.isNaN(e))return "NaN";if(e===1/0)return "Infinity";if(e===-1/0)return "-Infinity";if(e instanceof Error)return `${e.constructor.name}: ${e.message}`;if(e instanceof Promise)return "Promise";if(e instanceof Set)return `Set: ${i(Array.from(e))}`;if(e instanceof Map)return `Map: ${i(Array.from(e.entries()))}`;if(e instanceof RegExp)return e.toString();if(Array.isArray(e))return `[${e.map(i).join(", ")}]`;let n;try{n=JSON.stringify(e);}catch(t){n=e.toString();}return n}new TextDecoder,new TextEncoder;const l="DOwner$#$",{assertFunction:a,assertNotNil:o}=r;class c{constructor(e,t,n=false){o(e,"event"),a(t,"callback"),this._event=e,this._callback=t,this._isOnce=!!n,this._owner=void 0;}set owner(e){this._owner=e;}get owner(){return this._owner===l?void 0:this._owner}get event(){return this._event}get isOnce(){return this._isOnce}isSameCallback(e){return this._callback===e}get callback(){return this._callback}invoke(...e){try{return this._callback(...e)}finally{if(this._isOnce)try{this._event._remove(this);}catch(e){console.warn(e);}}}listener(...e){return this.invoke(...e)}}const{isFunction:h,isNil:u}=e,{assertStringOrSymbol:_,assertFunction:f}=r;class m{static get DefaultOwner(){return l}constructor(e){_(e,"eventName"),this._name=e,this._callbacks=new Set,this._listeners=[],this._callback2Listeners=new Map,this._listener2Owner=new Map,this._owner2Listeners=new Map;}get name(){return this._name}isEmpty(){return 0===this._callbacks.size}rawListeners(){return [...this._listeners]}listenerCount(e){return null==e?this._listeners.length:this._callback2Listeners.get(e)?.size??0}callbacks(){return [...this.rawListeners().map(e=>e.callback)]}emit(...e){if(0===this._listeners.length)return false;for(const t of [...this._listeners])t.invoke(...e);return true}emitOwner(e,...t){if(0===this._listeners.length)return false;const n=this._owner2Listeners.get(e);if(null==n)return false;for(const e of [...n])e.invoke(...t);return true}hasListener(e){return !!h(e)&&this._callbacks.has(e)}hasOwner(e){return !u(e)&&this._owner2Listeners.has(e)}addListener(e,t){return this._addListener(e,t,false,false)}prependListener(e,t){return this._addListener(e,t,false,true)}addOnceListener(e,t){return this._addListener(e,t,true,false)}prependOnceListener(e,t){return this._addListener(e,t,true,true)}_addListener(e,t,n,s){if(u(e))return false;f(e),this._callbacks.has(e)||this._callbacks.add(e),t=t??l;const r=new c(this,e,n);r.owner=t,s?this._listeners.unshift(r):this._listeners.push(r),this._listener2Owner.set(r,t);let i=this._callback2Listeners.get(e);null==i&&(i=new Set,this._callback2Listeners.set(e,i)),i.add(r);let a=this._owner2Listeners.get(t);return null==a&&(a=new Set,this._owner2Listeners.set(t,a)),a.add(r),true}removeListener(e){if(u(e))return false;if(!this._callbacks.has(e))return false;this._callbacks.delete(e);const t=this._callback2Listeners.get(e);if(null==t)return false;this._callback2Listeners.delete(e);for(const e of t){ -1!==this._listeners.indexOf(e)&&this._listeners.splice(this._listeners.indexOf(e),1);const t=this._listener2Owner.get(e);if(null==t)continue;this._listener2Owner.delete(e);const n=this._owner2Listeners.get(t);null!=n&&(n.delete(e),0===n.size&&this._owner2Listeners.delete(t));}return true}_remove(e){const t=this._listeners.indexOf(e);-1!==t&&this._listeners.splice(t,1);const{callback:n}=e,s=this._callback2Listeners.get(n);null!=s&&(s.delete(e),0===s.size&&(this._callback2Listeners.delete(n),this._callbacks.delete(n)));const r=this._listener2Owner.get(e);if(null==r)return;this._listener2Owner.delete(e);const i=this._owner2Listeners.get(r);null!=i&&(i.delete(e),0===i.size&&this._owner2Listeners.delete(r));}removeAllListeners(e){if(u(e))return this._callbacks.clear(),this._listeners.length=0,this._callback2Listeners.clear(),this._listener2Owner.clear(),this._owner2Listeners.clear(),this;const t=this._owner2Listeners.get(e);if(null==t)return this;this._owner2Listeners.delete(e);for(const e of t){ -1!==this._listeners.indexOf(e)&&this._listeners.splice(this._listeners.indexOf(e),1),this._listener2Owner.delete(e);const{callback:t}=e,n=this._callback2Listeners.get(t);null!=n&&(n.delete(e),0===n.size&&(this._callback2Listeners.delete(t),this._callbacks.delete(t)));}return this}}const{isNil:d}=e,{assertString:w,assertFunction:L,assertNumber:v,assertStringOrSymbol:g,assertNotNil:p}=r,b=["on","once","addListener","prependListener","prependOnceListener","off","offAll","offOwner","removeAllListeners","removeListener","emit","emitOwner","setMaxListeners","getMaxListeners","hasOwner","listeners","listenerCount","eventNames","rawListeners"];let O=10;class k{static mixin(e){const t=new k;e.__emitter=t;for(const n of b){const s=t[n];e[n]=s.bind(t);}return e}static get defaultMaxListeners(){return O}static set defaultMaxListeners(e){v(e),O=e??10;}constructor(){this._name2Event=new Map,this._maxListeners=O;}addListener(e,t,n){return this.on(e,t,n)}prependListener(e,t,n){w(e),L(t),this._checkMaxListeners(e);return this._getOrCreateEvent(e).prependListener(t,n),this}prependOnceListener(e,t,n){w(e),L(t),this._checkMaxListeners(e);return this._getOrCreateEvent(e).prependOnceListener(t,n),this}emit(e,...t){const n=this._name2Event.get(e);return null!=n&&!n.isEmpty()&&(n.emit(...t),true)}emitOwner(e,t,...n){if(null==t)throw new Error('Missing "owner"');const s=this._name2Event.get(e);return null!=s&&!s.isEmpty()&&(s.emitOwner(t,...n),true)}eventNames(){return [...this._name2Event.keys()]}getMaxListeners(){return this._maxListeners}listenerCount(e,t){g(e,"eventName");const n=this._name2Event.get(e);return null==n||n.isEmpty()?0:n.listenerCount(t)}listeners(e){g(e,"eventName");const t=this._name2Event.get(e);return null==t||t.isEmpty()?[]:t.callbacks()}off(e,t){const n=this._name2Event.get(e);return null==n?this:(n.removeListener(t),n.isEmpty()?(this._name2Event.delete(e),this):this)}offAll(e,t){g(e,"eventName");const n=this._name2Event.get(e);return null==n?this:(n.removeAllListeners(t),n.isEmpty()?(this._name2Event.delete(e),this):this)}offOwner(e){p(e,"owner");const t=[...this._name2Event.values()];for(const n of t)n.removeAllListeners(e),n.isEmpty()&&this._name2Event.delete(n.name);return this}on(e,t,n){w(e),L(t),this._checkMaxListeners(e);return this._getOrCreateEvent(e).addListener(t,n),this}_checkMaxListeners(e){let t=0;0!==this._maxListeners&&this._maxListeners!==1/0&&(t=this.listenerCount(e))>=this._maxListeners&&console.warn(`maxlistenersexceededwarning: Possible EventEmitter memory leak detected. ${t} ${e} listeners added to [${this}]. Use emitter.setMaxListeners() to increase limit`);}once(e,t,n){w(e),L(t);return this._getOrCreateEvent(e).addOnceListener(t,n),this}rawListeners(e){return this._name2Event.get(e)?.rawListeners()||[]}removeAllListeners(e,t){return this.offAll(e,t)}removeListener(e,t){return this.off(e,t)}setMaxListeners(e){if(v(e),e<0)throw new RangeError("maxListeners must >=0");return this._maxListeners=e,this}_getOrCreateEvent(e){if(this._name2Event.has(e))return this._name2Event.get(e);const t=new m(e);return this._name2Event.set(e,t),t}hasOwner(e){if(d(e))return false;for(const t of this._name2Event.values())if(t.hasOwner(e))return true;return false}}
181
181
 
182
182
  // 3rd
183
183
  // internal
@@ -724,10 +724,725 @@
724
724
  }
725
725
  }
726
726
 
727
- var index = { CappedSet, TimeWheelCache, Hour24TimeWheelCache };
727
+ // internal
728
+ // owned
729
+
730
+ /**
731
+ * @typedef {{
732
+ * value: any,
733
+ * prev: Node|undefined,
734
+ * next: Node|undefined
735
+ * }} Node
736
+ */
737
+
738
+ // module vars
739
+ const { assertNotNegative, assertPositive: assertPositive$1 } = C;
740
+
741
+ /**
742
+ * A doubly linked list implementation.
743
+ *
744
+ * @class LinkedList
745
+ */
746
+ class LinkedList {
747
+ /**
748
+ * Creates a new LinkedList instance.
749
+ * @constructor
750
+ */
751
+ constructor () {
752
+ /**
753
+ * @type {Node|undefined}
754
+ */
755
+ this._head = undefined;
756
+ /**
757
+ * @type {Node|undefined}
758
+ */
759
+ this._tail = undefined;
760
+ /**
761
+ * @type {number}
762
+ */
763
+ this._size = 0;
764
+ }
765
+
766
+ get size () {
767
+ return this._size
768
+ }
769
+
770
+ /**
771
+ * get the first element
772
+ */
773
+ get first () {
774
+ return this._head?.value
775
+ }
776
+
777
+ /**
778
+ * get the last element
779
+ */
780
+ get last () {
781
+ return this._tail?.value
782
+ }
783
+
784
+ [Symbol.iterator] () {
785
+ let current = this._head;
786
+ const iterator = {
787
+ next () {
788
+ if (current) {
789
+ const value = current.value;
790
+ current = current.next;
791
+ return { value, done: false }
792
+ }
793
+ return { value: undefined, done: true }
794
+ },
795
+ [Symbol.iterator] () {
796
+ return this
797
+ }
798
+ };
799
+ return iterator
800
+ }
801
+
802
+ /**
803
+ * Adds a value to the beginning of the linked list.
804
+ * @param {*} value - The value to add
805
+ * @returns {LinkedList} This linked list instance for chaining
806
+ */
807
+ addFirst (value) {
808
+ /**
809
+ * @type {Node}
810
+ */
811
+ const node = { value, prev: undefined, next: this._head };
812
+
813
+ if (this._head) {
814
+ this._head.prev = node;
815
+ } else {
816
+ this._tail = node;
817
+ }
818
+
819
+ this._head = node;
820
+ this._size++;
821
+ return this
822
+ }
823
+
824
+ /**
825
+ * Adds a value to the end of the linked list.
826
+ * @param {*} value - The value to add
827
+ * @returns {LinkedList} This linked list instance for chaining
828
+ */
829
+ addLast (value) {
830
+ /**
831
+ * @type {Node}
832
+ */
833
+ const node = { value, prev: this._tail, next: undefined };
834
+
835
+ if (this._tail) {
836
+ this._tail.next = node;
837
+ } else {
838
+ this._head = node;
839
+ }
840
+
841
+ this._tail = node;
842
+ this._size++;
843
+ return this
844
+ }
845
+
846
+ /**
847
+ * Adds a value to the end of the linked list.
848
+ * @param {*} value - The value to add
849
+ * @returns {LinkedList} This linked list instance for chaining
850
+ */
851
+ add (value) {
852
+ return this.addLast(value)
853
+ }
854
+
855
+ /**
856
+ * Removes and returns the first element from the linked list.
857
+ * @returns {*} The removed value, or undefined if the list is empty
858
+ */
859
+ removeFirst () {
860
+ if (!this._head) {
861
+ return undefined
862
+ }
863
+
864
+ const value = this._head.value;
865
+ this._head = this._head.next;
866
+
867
+ if (this._head) {
868
+ this._head.prev = undefined;
869
+ } else {
870
+ this._tail = undefined;
871
+ }
872
+
873
+ this._size--;
874
+ return value
875
+ }
876
+
877
+ /**
878
+ * Removes and returns the last element from the linked list.
879
+ * @returns {*} The removed value, or undefined if the list is empty
880
+ */
881
+ removeLast () {
882
+ if (!this._tail) {
883
+ return undefined
884
+ }
885
+
886
+ const value = this._tail.value;
887
+ this._tail = this._tail.prev;
888
+
889
+ if (this._tail) {
890
+ this._tail.next = undefined;
891
+ } else {
892
+ this._head = undefined;
893
+ }
894
+
895
+ this._size--;
896
+ return value
897
+ }
898
+
899
+ /**
900
+ * Removes the first occurrence of the specified value from the linked list.
901
+ * @param {*} value - The value to remove
902
+ * @param {function(*, *): boolean} [comparator] - Optional comparison function (a, b) => boolean
903
+ * @returns {boolean} True if the value was found and removed, false otherwise
904
+ */
905
+ remove (value, comparator) {
906
+ const compare = comparator || this._defaultComparator;
907
+ let current = this._head;
908
+
909
+ while (current) {
910
+ if (compare(current.value, value)) {
911
+ this._removeNode(current);
912
+ return true
913
+ }
914
+ current = current.next;
915
+ }
916
+
917
+ return false
918
+ }
919
+
920
+ /**
921
+ * Removes all occurrences of the specified value from the linked list.
922
+ * @param {*} value - The value to remove
923
+ * @param {function(*, *): boolean} [comparator] - Optional comparison function (a, b) => boolean
924
+ * @returns {number} The number of elements removed
925
+ */
926
+ removeAll (value, comparator) {
927
+ const compare = comparator || this._defaultComparator;
928
+ let removedCount = 0;
929
+ let current = this._head;
930
+
931
+ while (current) {
932
+ const next = current.next; // Store next before potential removal
933
+ if (compare(current.value, value)) {
934
+ this._removeNode(current);
935
+ removedCount++;
936
+ }
937
+ current = next;
938
+ }
939
+
940
+ return removedCount
941
+ }
942
+
943
+ /**
944
+ * Removes the element at the specified index.
945
+ * @param {number} index - The index of the element to remove
946
+ * @returns {*} The removed value, or undefined if index is out of bounds
947
+ */
948
+ removeAt (index) {
949
+ assertNotNegative(index, 'index');
950
+
951
+ if (index >= this._size) {
952
+ return undefined
953
+ }
954
+
955
+ if (index === 0) {
956
+ return this.removeFirst()
957
+ }
958
+
959
+ if (index === this._size - 1) {
960
+ return this.removeLast()
961
+ }
962
+
963
+ let current = this._head;
964
+ for (let i = 0; i < index; i++) {
965
+ current = current?.next;
966
+ }
967
+
968
+ if (current) {
969
+ const value = current.value;
970
+ this._removeNode(current);
971
+ return value
972
+ }
973
+
974
+ return undefined
975
+ }
976
+
977
+ /**
978
+ * Remove speicied count elements from head
979
+ * @param {number} count - The count of elements to remove
980
+ * @returns {boolean} True if any element was removed, false otherwise
981
+ */
982
+ removeFromHead (count) {
983
+ assertPositive$1(count, 'count');
984
+
985
+ // do nothing, it list is empty
986
+ if (this._size === 0) {
987
+ return false
988
+ }
989
+
990
+ // beyond size, remove all elements
991
+ if (count >= this._size) {
992
+ this.clear();
993
+ return true
994
+ }
995
+
996
+ // Find the node at the specified index
997
+ let current = this._head;
998
+ for (let i = 1; i < count; i++) {
999
+ if (!current) {
1000
+ return false
1001
+ }
1002
+ current = current.next;
1003
+ }
1004
+ // Remove the nodes
1005
+ if (current) {
1006
+ if (current.next) {
1007
+ this._head = current.next;
1008
+ this._head.prev = undefined;
1009
+ } else {
1010
+ this._head = undefined;
1011
+ this._tail = undefined;
1012
+ }
1013
+ this._size = this._size - count;
1014
+ return true
1015
+ }
1016
+
1017
+ return false
1018
+ }
1019
+
1020
+ /**
1021
+ * Remove specified count elements from tail
1022
+ * @param {number} count - The count of elements to remove
1023
+ * @returns {boolean} True if any element was removed, false otherwise
1024
+ */
1025
+ removeFromTail (count) {
1026
+ assertPositive$1(count, 'count');
1027
+
1028
+ // do nothing, if list is empty
1029
+ if (this._size === 0) {
1030
+ return false
1031
+ }
1032
+
1033
+ // beyond size, remove all elements
1034
+ if (count >= this._size) {
1035
+ this.clear();
1036
+ return true
1037
+ }
1038
+
1039
+ // Find the node at the specified position from tail
1040
+ let current = this._tail;
1041
+ for (let i = 1; i < count; i++) {
1042
+ if (!current) {
1043
+ return false
1044
+ }
1045
+ current = current.prev;
1046
+ }
1047
+ // Remove the nodes
1048
+ if (current) {
1049
+ if (current.prev) {
1050
+ this._tail = current.prev;
1051
+ this._tail.next = undefined;
1052
+ } else {
1053
+ this._head = undefined;
1054
+ this._tail = undefined;
1055
+ }
1056
+ this._size = this._size - count;
1057
+ return true
1058
+ }
1059
+
1060
+ return false
1061
+ }
1062
+
1063
+ /**
1064
+ * Checks if the linked list contains the specified value.
1065
+ * @param {*} value - The value to check for
1066
+ * @param {function(*, *): boolean} [comparator] - Optional comparison function (a, b) => boolean
1067
+ * @returns {boolean} True if the value exists, false otherwise
1068
+ */
1069
+ contains (value, comparator) {
1070
+ const compare = comparator || this._defaultComparator;
1071
+ let current = this._head;
1072
+ while (current) {
1073
+ if (compare(current.value, value)) {
1074
+ return true
1075
+ }
1076
+ current = current.next;
1077
+ }
1078
+ return false
1079
+ }
1080
+
1081
+ /**
1082
+ * Returns the index of the first occurrence of the specified value.
1083
+ * @param {*} value - The value to find
1084
+ * @param {function(*, *): boolean} [comparator] - Optional comparison function (a, b) => boolean
1085
+ * @returns {number} The index of the value, or -1 if not found
1086
+ */
1087
+ indexOf (value, comparator) {
1088
+ const compare = comparator || this._defaultComparator;
1089
+ let current = this._head;
1090
+ let index = 0;
1091
+ while (current) {
1092
+ if (compare(current.value, value)) {
1093
+ return index
1094
+ }
1095
+ current = current.next;
1096
+ index++;
1097
+ }
1098
+ return -1
1099
+ }
1100
+
1101
+ /**
1102
+ * Returns the index of the last occurrence of the specified value.
1103
+ * @param {*} value - The value to find
1104
+ * @param {function(*, *): boolean} [comparator] - Optional comparison function (a, b) => boolean
1105
+ * @returns {number} The index of the last occurrence, or -1 if not found
1106
+ */
1107
+ indexLastOf (value, comparator) {
1108
+ const compare = comparator || this._defaultComparator;
1109
+ let current = this._tail;
1110
+ let index = this._size - 1;
1111
+ while (current) {
1112
+ if (compare(current.value, value)) {
1113
+ return index
1114
+ }
1115
+ current = current.prev;
1116
+ index--;
1117
+ }
1118
+ return -1
1119
+ }
1120
+
1121
+ /**
1122
+ * Gets the value at the specified index.
1123
+ * @param {number} index - The index of the value to get
1124
+ * @returns {*} The value at the index, or undefined if index is out of bounds
1125
+ */
1126
+ get (index) {
1127
+ assertNotNegative(index, 'index');
1128
+
1129
+ if (index >= this._size) {
1130
+ return undefined
1131
+ }
1132
+
1133
+ let current = this._head;
1134
+ for (let i = 0; i < index; i++) {
1135
+ current = current?.next;
1136
+ }
1137
+
1138
+ return current?.value
1139
+ }
1140
+
1141
+ /**
1142
+ * Inserts a value at the specified index.
1143
+ * @param {number} index - The index at which to insert the value
1144
+ * @param {*} value - The value to insert
1145
+ * @returns {LinkedList} This linked list instance for chaining
1146
+ */
1147
+ insertAt (index, value) {
1148
+ assertNotNegative(index, 'index');
1149
+
1150
+ if (index === 0) {
1151
+ return this.addFirst(value)
1152
+ }
1153
+
1154
+ if (index >= this._size) {
1155
+ return this.addLast(value)
1156
+ }
1157
+
1158
+ let current = this._head;
1159
+ for (let i = 0; i < index - 1; i++) {
1160
+ current = current?.next;
1161
+ }
1162
+
1163
+ if (current) {
1164
+ /**
1165
+ * @type {Node}
1166
+ */
1167
+ const node = { value, prev: current, next: current.next };
1168
+ if (current.next) {
1169
+ current.next.prev = node;
1170
+ }
1171
+ current.next = node;
1172
+ this._size++;
1173
+ }
1174
+
1175
+ return this
1176
+ }
1177
+
1178
+ /**
1179
+ * Removes all elements from the linked list.
1180
+ */
1181
+ clear () {
1182
+ this._head = undefined;
1183
+ this._tail = undefined;
1184
+ this._size = 0;
1185
+ }
1186
+
1187
+ /**
1188
+ * Returns an array containing all the values in the linked list.
1189
+ * @returns {any[]} An array of all values
1190
+ */
1191
+ toArray () {
1192
+ const result = [];
1193
+ let current = this._head;
1194
+ while (current) {
1195
+ result.push(current.value);
1196
+ current = current.next;
1197
+ }
1198
+ return result
1199
+ }
1200
+
1201
+ /**
1202
+ * Returns an iterator of the values in the linked list.
1203
+ * @returns {Iterator<any>} An iterator object that yields the values of the linked list
1204
+ */
1205
+ values () {
1206
+ return this[Symbol.iterator]()
1207
+ }
1208
+
1209
+ /**
1210
+ * Returns a slice of the linked list as an array.
1211
+ * @param {number} [start=0] - The start index (inclusive). If negative, counts from the end.
1212
+ * @param {number} [end=this.size] - The end index (exclusive). If negative, counts from the end.
1213
+ * @returns {any[]} An array containing the sliced elements
1214
+ */
1215
+ slice (start = 0, end = this.size) {
1216
+ // Handle negative indices
1217
+ const normalizedStart = start < 0 ? Math.max(this.size + start, 0) : Math.min(start, this.size);
1218
+ const normalizedEnd = end < 0 ? Math.max(this.size + end, 0) : Math.min(end, this.size);
1219
+
1220
+ if (normalizedStart >= normalizedEnd) {
1221
+ return []
1222
+ }
1223
+
1224
+ if (start < 0) {
1225
+ return this._sliceNegative(normalizedStart, normalizedEnd)
1226
+ } else {
1227
+ return this._slicePositive(normalizedStart, normalizedEnd)
1228
+ }
1229
+ }
1230
+
1231
+ /**
1232
+ * Returns a string representation of the FixedLinkedList.
1233
+ * @returns {string} String representation
1234
+ */
1235
+ toString () {
1236
+ const partialElements = this.slice(0, 3);
1237
+ const partialString = this.size > 3 ? G.safeToString(partialElements) + '...' : G.safeToString(partialElements);
1238
+ return `LinkedList[${this.size}](${partialString})`
1239
+ }
1240
+
1241
+ /**
1242
+ * Slice implementation for positive indices (iterates from head to tail)
1243
+ * @param {number} start - Normalized start index (inclusive)
1244
+ * @param {number} end - Normalized end index (exclusive)
1245
+ * @returns {any[]} An array containing the sliced elements
1246
+ * @private
1247
+ */
1248
+ _slicePositive (start, end) {
1249
+ const result = [];
1250
+ let current = this._head;
1251
+ let index = 0;
1252
+
1253
+ // Move to the starting position
1254
+ while (current && index < start) {
1255
+ current = current.next;
1256
+ index++;
1257
+ }
1258
+
1259
+ // Collect elements from start to end
1260
+ while (current && index < end) {
1261
+ result.push(current.value);
1262
+ current = current.next;
1263
+ index++;
1264
+ }
1265
+
1266
+ return result
1267
+ }
1268
+
1269
+ /**
1270
+ * Slice implementation for negative indices (iterates from tail to head)
1271
+ * @param {number} start - Normalized start index (inclusive)
1272
+ * @param {number} end - Normalized end index (exclusive)
1273
+ * @returns {any[]} An array containing the sliced elements
1274
+ * @private
1275
+ */
1276
+ _sliceNegative (start, end) {
1277
+ const result = [];
1278
+ let current = this._tail;
1279
+ let index = this.size - 1;
1280
+
1281
+ // Move to the starting position
1282
+ while (current && index > start) {
1283
+ current = current.prev;
1284
+ index--;
1285
+ }
1286
+
1287
+ // Collect elements from start to end
1288
+ while (current && index < end) {
1289
+ result.push(current.value);
1290
+ current = current.next;
1291
+ index++;
1292
+ }
1293
+
1294
+ return result
1295
+ }
1296
+
1297
+ /**
1298
+ * Removes a node from the linked list.
1299
+ * @param {Node} node - The node to be removed
1300
+ * @private
1301
+ */
1302
+ _removeNode (node) {
1303
+ if (node.prev) {
1304
+ node.prev.next = node.next;
1305
+ } else {
1306
+ this._head = node.next;
1307
+ }
1308
+
1309
+ if (node.next) {
1310
+ node.next.prev = node.prev;
1311
+ } else {
1312
+ this._tail = node.prev;
1313
+ }
1314
+
1315
+ this._size--;
1316
+ }
1317
+
1318
+ /**
1319
+ * Default comparator for strict equality comparison.
1320
+ * @param {*} a - First value to compare
1321
+ * @param {*} b - Second value to compare
1322
+ * @returns {boolean} True if values are strictly equal
1323
+ * @private
1324
+ */
1325
+ _defaultComparator (a, b) {
1326
+ return a === b
1327
+ }
1328
+ }
1329
+
1330
+ // internal
1331
+ // owned
1332
+
1333
+ // module vars
1334
+ const { assertPositive } = C;
1335
+
1336
+ /**
1337
+ * A fixed-capacity linked list that automatically removes elements when capacity is exceeded.
1338
+ * When adding to the end (addLast), it removes the first element if capacity is full.
1339
+ * When adding to the beginning (addFirst), it removes the last element if capacity is full.
1340
+ *
1341
+ * @class FixedLinkedList
1342
+ * @extends LinkedList
1343
+ */
1344
+ class FixedLinkedList extends LinkedList {
1345
+ /**
1346
+ * Creates a new FixedLinkedList instance with a fixed capacity.
1347
+ * @constructor
1348
+ * @param {number} capacity - The maximum number of elements the list can hold (must be > 0)
1349
+ * @throws {Error} If capacity is less than or equal to 0
1350
+ */
1351
+ constructor (capacity) {
1352
+ assertPositive(capacity, 'capacity');
1353
+ super();
1354
+ this.capacity = Math.ceil(capacity);
1355
+ }
1356
+
1357
+ /**
1358
+ * Adds a value to the beginning of the linked list.
1359
+ * If the list is at capacity, removes the last element before adding.
1360
+ * @param {*} value - The value to add
1361
+ * @returns {FixedLinkedList} This linked list instance for chaining
1362
+ */
1363
+ addFirst (value) {
1364
+ if (this.size >= this.capacity) {
1365
+ this.removeLast();
1366
+ }
1367
+ super.addFirst(value);
1368
+ return this
1369
+ }
1370
+
1371
+ /**
1372
+ * Adds a value to the end of the linked list.
1373
+ * If the list is at capacity, removes the first element before adding.
1374
+ * @param {*} value - The value to add
1375
+ * @returns {FixedLinkedList} This linked list instance for chaining
1376
+ */
1377
+ addLast (value) {
1378
+ if (this.size >= this.capacity) {
1379
+ this.removeFirst();
1380
+ }
1381
+ super.addLast(value);
1382
+ return this
1383
+ }
1384
+
1385
+ /**
1386
+ * Adds a value to the end of the linked list.
1387
+ * If the list is at capacity, removes the first element before adding.
1388
+ * @param {*} value - The value to add
1389
+ * @returns {FixedLinkedList} This linked list instance for chaining
1390
+ */
1391
+ add (value) {
1392
+ return this.addLast(value)
1393
+ }
1394
+
1395
+ /**
1396
+ * Inserts a value at the specified index.
1397
+ * If the list is at capacity and index is not at the end, removes the first element before adding.
1398
+ * If the list is at capacity and index is at the end, removes the first element before adding.
1399
+ * @param {number} index - The index at which to insert the value
1400
+ * @param {*} value - The value to insert
1401
+ * @returns {FixedLinkedList} This linked list instance for chaining
1402
+ */
1403
+ insertAt (index, value) {
1404
+ // Remove an element if we're at capacity and not adding beyond current size
1405
+ if (this.size >= this.capacity) {
1406
+ // Always remove first element to maintain capacity
1407
+ this.removeFirst();
1408
+ }
1409
+ super.insertAt(index, value);
1410
+ return this
1411
+ }
1412
+
1413
+ /**
1414
+ * Returns the remaining capacity of the list.
1415
+ * @returns {number} The number of additional elements that can be added
1416
+ */
1417
+ get remainingCapacity () {
1418
+ return this.capacity - this.size
1419
+ }
1420
+
1421
+ /**
1422
+ * Checks if the list is at full capacity.
1423
+ * @returns {boolean} True if the list is full, false otherwise
1424
+ */
1425
+ get isFull () {
1426
+ return this.size >= this.capacity
1427
+ }
1428
+
1429
+ /**
1430
+ * Returns a string representation of the FixedLinkedList.
1431
+ * @returns {string} String representation
1432
+ */
1433
+ toString () {
1434
+ const partialElements = this.slice(0, 3);
1435
+ const partialString = this.size > 3 ? G.safeToString(partialElements) + '...' : G.safeToString(partialElements);
1436
+ return `FixedLinkedList[${this.size}/${this.capacity}](${partialString})`
1437
+ }
1438
+ }
1439
+
1440
+ var index = { CappedSet, TimeWheelCache, Hour24TimeWheelCache, LinkedList, FixedLinkedList };
728
1441
 
729
1442
  exports.CappedSet = CappedSet;
1443
+ exports.FixedLinkedList = FixedLinkedList;
730
1444
  exports.Hour24TimeWheelCache = Hour24TimeWheelCache;
1445
+ exports.LinkedList = LinkedList;
731
1446
  exports.TimeWheelCache = TimeWheelCache;
732
1447
  exports.default = index;
733
1448