@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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- 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)}
5
+ 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)}
6
6
 
7
7
  // internal
8
8
  // owned
@@ -16,7 +16,7 @@ function a$1(t){return "boolean"==typeof t}function c$1(t){return "function"==ty
16
16
  */
17
17
 
18
18
  // module vars
19
- const { assertPositive } = C;
19
+ const { assertPositive: assertPositive$2 } = C;
20
20
 
21
21
  /**
22
22
  * A set that has a fixed capacity and automatically removes the oldest element when the capacity is reached.
@@ -31,7 +31,7 @@ class CappedSet {
31
31
  * @throws {Error} If capacity is less than or equal to 0
32
32
  */
33
33
  constructor (capacity) {
34
- assertPositive(capacity, 'capacity');
34
+ assertPositive$2(capacity, 'capacity');
35
35
  this.capacity = capacity;
36
36
  /**
37
37
  * 1. key is the Value stored in CappedSet
@@ -175,7 +175,7 @@ class CappedSet {
175
175
  }
176
176
  }
177
177
 
178
- 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}}
178
+ 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}}
179
179
 
180
180
  // 3rd
181
181
  // internal
@@ -722,10 +722,725 @@ class Hour24TimeWheelCache extends k {
722
722
  }
723
723
  }
724
724
 
725
- var index = { CappedSet, TimeWheelCache, Hour24TimeWheelCache };
725
+ // internal
726
+ // owned
727
+
728
+ /**
729
+ * @typedef {{
730
+ * value: any,
731
+ * prev: Node|undefined,
732
+ * next: Node|undefined
733
+ * }} Node
734
+ */
735
+
736
+ // module vars
737
+ const { assertNotNegative, assertPositive: assertPositive$1 } = C;
738
+
739
+ /**
740
+ * A doubly linked list implementation.
741
+ *
742
+ * @class LinkedList
743
+ */
744
+ class LinkedList {
745
+ /**
746
+ * Creates a new LinkedList instance.
747
+ * @constructor
748
+ */
749
+ constructor () {
750
+ /**
751
+ * @type {Node|undefined}
752
+ */
753
+ this._head = undefined;
754
+ /**
755
+ * @type {Node|undefined}
756
+ */
757
+ this._tail = undefined;
758
+ /**
759
+ * @type {number}
760
+ */
761
+ this._size = 0;
762
+ }
763
+
764
+ get size () {
765
+ return this._size
766
+ }
767
+
768
+ /**
769
+ * get the first element
770
+ */
771
+ get first () {
772
+ return this._head?.value
773
+ }
774
+
775
+ /**
776
+ * get the last element
777
+ */
778
+ get last () {
779
+ return this._tail?.value
780
+ }
781
+
782
+ [Symbol.iterator] () {
783
+ let current = this._head;
784
+ const iterator = {
785
+ next () {
786
+ if (current) {
787
+ const value = current.value;
788
+ current = current.next;
789
+ return { value, done: false }
790
+ }
791
+ return { value: undefined, done: true }
792
+ },
793
+ [Symbol.iterator] () {
794
+ return this
795
+ }
796
+ };
797
+ return iterator
798
+ }
799
+
800
+ /**
801
+ * Adds a value to the beginning of the linked list.
802
+ * @param {*} value - The value to add
803
+ * @returns {LinkedList} This linked list instance for chaining
804
+ */
805
+ addFirst (value) {
806
+ /**
807
+ * @type {Node}
808
+ */
809
+ const node = { value, prev: undefined, next: this._head };
810
+
811
+ if (this._head) {
812
+ this._head.prev = node;
813
+ } else {
814
+ this._tail = node;
815
+ }
816
+
817
+ this._head = node;
818
+ this._size++;
819
+ return this
820
+ }
821
+
822
+ /**
823
+ * Adds a value to the end of the linked list.
824
+ * @param {*} value - The value to add
825
+ * @returns {LinkedList} This linked list instance for chaining
826
+ */
827
+ addLast (value) {
828
+ /**
829
+ * @type {Node}
830
+ */
831
+ const node = { value, prev: this._tail, next: undefined };
832
+
833
+ if (this._tail) {
834
+ this._tail.next = node;
835
+ } else {
836
+ this._head = node;
837
+ }
838
+
839
+ this._tail = node;
840
+ this._size++;
841
+ return this
842
+ }
843
+
844
+ /**
845
+ * Adds a value to the end of the linked list.
846
+ * @param {*} value - The value to add
847
+ * @returns {LinkedList} This linked list instance for chaining
848
+ */
849
+ add (value) {
850
+ return this.addLast(value)
851
+ }
852
+
853
+ /**
854
+ * Removes and returns the first element from the linked list.
855
+ * @returns {*} The removed value, or undefined if the list is empty
856
+ */
857
+ removeFirst () {
858
+ if (!this._head) {
859
+ return undefined
860
+ }
861
+
862
+ const value = this._head.value;
863
+ this._head = this._head.next;
864
+
865
+ if (this._head) {
866
+ this._head.prev = undefined;
867
+ } else {
868
+ this._tail = undefined;
869
+ }
870
+
871
+ this._size--;
872
+ return value
873
+ }
874
+
875
+ /**
876
+ * Removes and returns the last element from the linked list.
877
+ * @returns {*} The removed value, or undefined if the list is empty
878
+ */
879
+ removeLast () {
880
+ if (!this._tail) {
881
+ return undefined
882
+ }
883
+
884
+ const value = this._tail.value;
885
+ this._tail = this._tail.prev;
886
+
887
+ if (this._tail) {
888
+ this._tail.next = undefined;
889
+ } else {
890
+ this._head = undefined;
891
+ }
892
+
893
+ this._size--;
894
+ return value
895
+ }
896
+
897
+ /**
898
+ * Removes the first occurrence of the specified value from the linked list.
899
+ * @param {*} value - The value to remove
900
+ * @param {function(*, *): boolean} [comparator] - Optional comparison function (a, b) => boolean
901
+ * @returns {boolean} True if the value was found and removed, false otherwise
902
+ */
903
+ remove (value, comparator) {
904
+ const compare = comparator || this._defaultComparator;
905
+ let current = this._head;
906
+
907
+ while (current) {
908
+ if (compare(current.value, value)) {
909
+ this._removeNode(current);
910
+ return true
911
+ }
912
+ current = current.next;
913
+ }
914
+
915
+ return false
916
+ }
917
+
918
+ /**
919
+ * Removes all occurrences of the specified value from the linked list.
920
+ * @param {*} value - The value to remove
921
+ * @param {function(*, *): boolean} [comparator] - Optional comparison function (a, b) => boolean
922
+ * @returns {number} The number of elements removed
923
+ */
924
+ removeAll (value, comparator) {
925
+ const compare = comparator || this._defaultComparator;
926
+ let removedCount = 0;
927
+ let current = this._head;
928
+
929
+ while (current) {
930
+ const next = current.next; // Store next before potential removal
931
+ if (compare(current.value, value)) {
932
+ this._removeNode(current);
933
+ removedCount++;
934
+ }
935
+ current = next;
936
+ }
937
+
938
+ return removedCount
939
+ }
940
+
941
+ /**
942
+ * Removes the element at the specified index.
943
+ * @param {number} index - The index of the element to remove
944
+ * @returns {*} The removed value, or undefined if index is out of bounds
945
+ */
946
+ removeAt (index) {
947
+ assertNotNegative(index, 'index');
948
+
949
+ if (index >= this._size) {
950
+ return undefined
951
+ }
952
+
953
+ if (index === 0) {
954
+ return this.removeFirst()
955
+ }
956
+
957
+ if (index === this._size - 1) {
958
+ return this.removeLast()
959
+ }
960
+
961
+ let current = this._head;
962
+ for (let i = 0; i < index; i++) {
963
+ current = current?.next;
964
+ }
965
+
966
+ if (current) {
967
+ const value = current.value;
968
+ this._removeNode(current);
969
+ return value
970
+ }
971
+
972
+ return undefined
973
+ }
974
+
975
+ /**
976
+ * Remove speicied count elements from head
977
+ * @param {number} count - The count of elements to remove
978
+ * @returns {boolean} True if any element was removed, false otherwise
979
+ */
980
+ removeFromHead (count) {
981
+ assertPositive$1(count, 'count');
982
+
983
+ // do nothing, it list is empty
984
+ if (this._size === 0) {
985
+ return false
986
+ }
987
+
988
+ // beyond size, remove all elements
989
+ if (count >= this._size) {
990
+ this.clear();
991
+ return true
992
+ }
993
+
994
+ // Find the node at the specified index
995
+ let current = this._head;
996
+ for (let i = 1; i < count; i++) {
997
+ if (!current) {
998
+ return false
999
+ }
1000
+ current = current.next;
1001
+ }
1002
+ // Remove the nodes
1003
+ if (current) {
1004
+ if (current.next) {
1005
+ this._head = current.next;
1006
+ this._head.prev = undefined;
1007
+ } else {
1008
+ this._head = undefined;
1009
+ this._tail = undefined;
1010
+ }
1011
+ this._size = this._size - count;
1012
+ return true
1013
+ }
1014
+
1015
+ return false
1016
+ }
1017
+
1018
+ /**
1019
+ * Remove specified count elements from tail
1020
+ * @param {number} count - The count of elements to remove
1021
+ * @returns {boolean} True if any element was removed, false otherwise
1022
+ */
1023
+ removeFromTail (count) {
1024
+ assertPositive$1(count, 'count');
1025
+
1026
+ // do nothing, if list is empty
1027
+ if (this._size === 0) {
1028
+ return false
1029
+ }
1030
+
1031
+ // beyond size, remove all elements
1032
+ if (count >= this._size) {
1033
+ this.clear();
1034
+ return true
1035
+ }
1036
+
1037
+ // Find the node at the specified position from tail
1038
+ let current = this._tail;
1039
+ for (let i = 1; i < count; i++) {
1040
+ if (!current) {
1041
+ return false
1042
+ }
1043
+ current = current.prev;
1044
+ }
1045
+ // Remove the nodes
1046
+ if (current) {
1047
+ if (current.prev) {
1048
+ this._tail = current.prev;
1049
+ this._tail.next = undefined;
1050
+ } else {
1051
+ this._head = undefined;
1052
+ this._tail = undefined;
1053
+ }
1054
+ this._size = this._size - count;
1055
+ return true
1056
+ }
1057
+
1058
+ return false
1059
+ }
1060
+
1061
+ /**
1062
+ * Checks if the linked list contains the specified value.
1063
+ * @param {*} value - The value to check for
1064
+ * @param {function(*, *): boolean} [comparator] - Optional comparison function (a, b) => boolean
1065
+ * @returns {boolean} True if the value exists, false otherwise
1066
+ */
1067
+ contains (value, comparator) {
1068
+ const compare = comparator || this._defaultComparator;
1069
+ let current = this._head;
1070
+ while (current) {
1071
+ if (compare(current.value, value)) {
1072
+ return true
1073
+ }
1074
+ current = current.next;
1075
+ }
1076
+ return false
1077
+ }
1078
+
1079
+ /**
1080
+ * Returns the index of the first occurrence of the specified value.
1081
+ * @param {*} value - The value to find
1082
+ * @param {function(*, *): boolean} [comparator] - Optional comparison function (a, b) => boolean
1083
+ * @returns {number} The index of the value, or -1 if not found
1084
+ */
1085
+ indexOf (value, comparator) {
1086
+ const compare = comparator || this._defaultComparator;
1087
+ let current = this._head;
1088
+ let index = 0;
1089
+ while (current) {
1090
+ if (compare(current.value, value)) {
1091
+ return index
1092
+ }
1093
+ current = current.next;
1094
+ index++;
1095
+ }
1096
+ return -1
1097
+ }
1098
+
1099
+ /**
1100
+ * Returns the index of the last occurrence of the specified value.
1101
+ * @param {*} value - The value to find
1102
+ * @param {function(*, *): boolean} [comparator] - Optional comparison function (a, b) => boolean
1103
+ * @returns {number} The index of the last occurrence, or -1 if not found
1104
+ */
1105
+ indexLastOf (value, comparator) {
1106
+ const compare = comparator || this._defaultComparator;
1107
+ let current = this._tail;
1108
+ let index = this._size - 1;
1109
+ while (current) {
1110
+ if (compare(current.value, value)) {
1111
+ return index
1112
+ }
1113
+ current = current.prev;
1114
+ index--;
1115
+ }
1116
+ return -1
1117
+ }
1118
+
1119
+ /**
1120
+ * Gets the value at the specified index.
1121
+ * @param {number} index - The index of the value to get
1122
+ * @returns {*} The value at the index, or undefined if index is out of bounds
1123
+ */
1124
+ get (index) {
1125
+ assertNotNegative(index, 'index');
1126
+
1127
+ if (index >= this._size) {
1128
+ return undefined
1129
+ }
1130
+
1131
+ let current = this._head;
1132
+ for (let i = 0; i < index; i++) {
1133
+ current = current?.next;
1134
+ }
1135
+
1136
+ return current?.value
1137
+ }
1138
+
1139
+ /**
1140
+ * Inserts a value at the specified index.
1141
+ * @param {number} index - The index at which to insert the value
1142
+ * @param {*} value - The value to insert
1143
+ * @returns {LinkedList} This linked list instance for chaining
1144
+ */
1145
+ insertAt (index, value) {
1146
+ assertNotNegative(index, 'index');
1147
+
1148
+ if (index === 0) {
1149
+ return this.addFirst(value)
1150
+ }
1151
+
1152
+ if (index >= this._size) {
1153
+ return this.addLast(value)
1154
+ }
1155
+
1156
+ let current = this._head;
1157
+ for (let i = 0; i < index - 1; i++) {
1158
+ current = current?.next;
1159
+ }
1160
+
1161
+ if (current) {
1162
+ /**
1163
+ * @type {Node}
1164
+ */
1165
+ const node = { value, prev: current, next: current.next };
1166
+ if (current.next) {
1167
+ current.next.prev = node;
1168
+ }
1169
+ current.next = node;
1170
+ this._size++;
1171
+ }
1172
+
1173
+ return this
1174
+ }
1175
+
1176
+ /**
1177
+ * Removes all elements from the linked list.
1178
+ */
1179
+ clear () {
1180
+ this._head = undefined;
1181
+ this._tail = undefined;
1182
+ this._size = 0;
1183
+ }
1184
+
1185
+ /**
1186
+ * Returns an array containing all the values in the linked list.
1187
+ * @returns {any[]} An array of all values
1188
+ */
1189
+ toArray () {
1190
+ const result = [];
1191
+ let current = this._head;
1192
+ while (current) {
1193
+ result.push(current.value);
1194
+ current = current.next;
1195
+ }
1196
+ return result
1197
+ }
1198
+
1199
+ /**
1200
+ * Returns an iterator of the values in the linked list.
1201
+ * @returns {Iterator<any>} An iterator object that yields the values of the linked list
1202
+ */
1203
+ values () {
1204
+ return this[Symbol.iterator]()
1205
+ }
1206
+
1207
+ /**
1208
+ * Returns a slice of the linked list as an array.
1209
+ * @param {number} [start=0] - The start index (inclusive). If negative, counts from the end.
1210
+ * @param {number} [end=this.size] - The end index (exclusive). If negative, counts from the end.
1211
+ * @returns {any[]} An array containing the sliced elements
1212
+ */
1213
+ slice (start = 0, end = this.size) {
1214
+ // Handle negative indices
1215
+ const normalizedStart = start < 0 ? Math.max(this.size + start, 0) : Math.min(start, this.size);
1216
+ const normalizedEnd = end < 0 ? Math.max(this.size + end, 0) : Math.min(end, this.size);
1217
+
1218
+ if (normalizedStart >= normalizedEnd) {
1219
+ return []
1220
+ }
1221
+
1222
+ if (start < 0) {
1223
+ return this._sliceNegative(normalizedStart, normalizedEnd)
1224
+ } else {
1225
+ return this._slicePositive(normalizedStart, normalizedEnd)
1226
+ }
1227
+ }
1228
+
1229
+ /**
1230
+ * Returns a string representation of the FixedLinkedList.
1231
+ * @returns {string} String representation
1232
+ */
1233
+ toString () {
1234
+ const partialElements = this.slice(0, 3);
1235
+ const partialString = this.size > 3 ? G.safeToString(partialElements) + '...' : G.safeToString(partialElements);
1236
+ return `LinkedList[${this.size}](${partialString})`
1237
+ }
1238
+
1239
+ /**
1240
+ * Slice implementation for positive indices (iterates from head to tail)
1241
+ * @param {number} start - Normalized start index (inclusive)
1242
+ * @param {number} end - Normalized end index (exclusive)
1243
+ * @returns {any[]} An array containing the sliced elements
1244
+ * @private
1245
+ */
1246
+ _slicePositive (start, end) {
1247
+ const result = [];
1248
+ let current = this._head;
1249
+ let index = 0;
1250
+
1251
+ // Move to the starting position
1252
+ while (current && index < start) {
1253
+ current = current.next;
1254
+ index++;
1255
+ }
1256
+
1257
+ // Collect elements from start to end
1258
+ while (current && index < end) {
1259
+ result.push(current.value);
1260
+ current = current.next;
1261
+ index++;
1262
+ }
1263
+
1264
+ return result
1265
+ }
1266
+
1267
+ /**
1268
+ * Slice implementation for negative indices (iterates from tail to head)
1269
+ * @param {number} start - Normalized start index (inclusive)
1270
+ * @param {number} end - Normalized end index (exclusive)
1271
+ * @returns {any[]} An array containing the sliced elements
1272
+ * @private
1273
+ */
1274
+ _sliceNegative (start, end) {
1275
+ const result = [];
1276
+ let current = this._tail;
1277
+ let index = this.size - 1;
1278
+
1279
+ // Move to the starting position
1280
+ while (current && index > start) {
1281
+ current = current.prev;
1282
+ index--;
1283
+ }
1284
+
1285
+ // Collect elements from start to end
1286
+ while (current && index < end) {
1287
+ result.push(current.value);
1288
+ current = current.next;
1289
+ index++;
1290
+ }
1291
+
1292
+ return result
1293
+ }
1294
+
1295
+ /**
1296
+ * Removes a node from the linked list.
1297
+ * @param {Node} node - The node to be removed
1298
+ * @private
1299
+ */
1300
+ _removeNode (node) {
1301
+ if (node.prev) {
1302
+ node.prev.next = node.next;
1303
+ } else {
1304
+ this._head = node.next;
1305
+ }
1306
+
1307
+ if (node.next) {
1308
+ node.next.prev = node.prev;
1309
+ } else {
1310
+ this._tail = node.prev;
1311
+ }
1312
+
1313
+ this._size--;
1314
+ }
1315
+
1316
+ /**
1317
+ * Default comparator for strict equality comparison.
1318
+ * @param {*} a - First value to compare
1319
+ * @param {*} b - Second value to compare
1320
+ * @returns {boolean} True if values are strictly equal
1321
+ * @private
1322
+ */
1323
+ _defaultComparator (a, b) {
1324
+ return a === b
1325
+ }
1326
+ }
1327
+
1328
+ // internal
1329
+ // owned
1330
+
1331
+ // module vars
1332
+ const { assertPositive } = C;
1333
+
1334
+ /**
1335
+ * A fixed-capacity linked list that automatically removes elements when capacity is exceeded.
1336
+ * When adding to the end (addLast), it removes the first element if capacity is full.
1337
+ * When adding to the beginning (addFirst), it removes the last element if capacity is full.
1338
+ *
1339
+ * @class FixedLinkedList
1340
+ * @extends LinkedList
1341
+ */
1342
+ class FixedLinkedList extends LinkedList {
1343
+ /**
1344
+ * Creates a new FixedLinkedList instance with a fixed capacity.
1345
+ * @constructor
1346
+ * @param {number} capacity - The maximum number of elements the list can hold (must be > 0)
1347
+ * @throws {Error} If capacity is less than or equal to 0
1348
+ */
1349
+ constructor (capacity) {
1350
+ assertPositive(capacity, 'capacity');
1351
+ super();
1352
+ this.capacity = Math.ceil(capacity);
1353
+ }
1354
+
1355
+ /**
1356
+ * Adds a value to the beginning of the linked list.
1357
+ * If the list is at capacity, removes the last element before adding.
1358
+ * @param {*} value - The value to add
1359
+ * @returns {FixedLinkedList} This linked list instance for chaining
1360
+ */
1361
+ addFirst (value) {
1362
+ if (this.size >= this.capacity) {
1363
+ this.removeLast();
1364
+ }
1365
+ super.addFirst(value);
1366
+ return this
1367
+ }
1368
+
1369
+ /**
1370
+ * Adds a value to the end of the linked list.
1371
+ * If the list is at capacity, removes the first element before adding.
1372
+ * @param {*} value - The value to add
1373
+ * @returns {FixedLinkedList} This linked list instance for chaining
1374
+ */
1375
+ addLast (value) {
1376
+ if (this.size >= this.capacity) {
1377
+ this.removeFirst();
1378
+ }
1379
+ super.addLast(value);
1380
+ return this
1381
+ }
1382
+
1383
+ /**
1384
+ * Adds a value to the end of the linked list.
1385
+ * If the list is at capacity, removes the first element before adding.
1386
+ * @param {*} value - The value to add
1387
+ * @returns {FixedLinkedList} This linked list instance for chaining
1388
+ */
1389
+ add (value) {
1390
+ return this.addLast(value)
1391
+ }
1392
+
1393
+ /**
1394
+ * Inserts a value at the specified index.
1395
+ * If the list is at capacity and index is not at the end, removes the first element before adding.
1396
+ * If the list is at capacity and index is at the end, removes the first element before adding.
1397
+ * @param {number} index - The index at which to insert the value
1398
+ * @param {*} value - The value to insert
1399
+ * @returns {FixedLinkedList} This linked list instance for chaining
1400
+ */
1401
+ insertAt (index, value) {
1402
+ // Remove an element if we're at capacity and not adding beyond current size
1403
+ if (this.size >= this.capacity) {
1404
+ // Always remove first element to maintain capacity
1405
+ this.removeFirst();
1406
+ }
1407
+ super.insertAt(index, value);
1408
+ return this
1409
+ }
1410
+
1411
+ /**
1412
+ * Returns the remaining capacity of the list.
1413
+ * @returns {number} The number of additional elements that can be added
1414
+ */
1415
+ get remainingCapacity () {
1416
+ return this.capacity - this.size
1417
+ }
1418
+
1419
+ /**
1420
+ * Checks if the list is at full capacity.
1421
+ * @returns {boolean} True if the list is full, false otherwise
1422
+ */
1423
+ get isFull () {
1424
+ return this.size >= this.capacity
1425
+ }
1426
+
1427
+ /**
1428
+ * Returns a string representation of the FixedLinkedList.
1429
+ * @returns {string} String representation
1430
+ */
1431
+ toString () {
1432
+ const partialElements = this.slice(0, 3);
1433
+ const partialString = this.size > 3 ? G.safeToString(partialElements) + '...' : G.safeToString(partialElements);
1434
+ return `FixedLinkedList[${this.size}/${this.capacity}](${partialString})`
1435
+ }
1436
+ }
1437
+
1438
+ var index = { CappedSet, TimeWheelCache, Hour24TimeWheelCache, LinkedList, FixedLinkedList };
726
1439
 
727
1440
  exports.CappedSet = CappedSet;
1441
+ exports.FixedLinkedList = FixedLinkedList;
728
1442
  exports.Hour24TimeWheelCache = Hour24TimeWheelCache;
1443
+ exports.LinkedList = LinkedList;
729
1444
  exports.TimeWheelCache = TimeWheelCache;
730
1445
  exports.default = index;
731
1446
  //# sourceMappingURL=index-dev.cjs.map