@creejs/commons-collection 2.0.4 → 2.0.5

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