data-structure-typed 1.46.1 → 1.46.3

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.
@@ -103,7 +103,6 @@ var dataStructureTyped = (() => {
103
103
  CoordinateMap: () => CoordinateMap,
104
104
  CoordinateSet: () => CoordinateSet,
105
105
  Deque: () => Deque,
106
- DequeIterator: () => DequeIterator,
107
106
  DirectedEdge: () => DirectedEdge,
108
107
  DirectedGraph: () => DirectedGraph,
109
108
  DirectedVertex: () => DirectedVertex,
@@ -113,7 +112,6 @@ var dataStructureTyped = (() => {
113
112
  FibonacciHeap: () => FibonacciHeap,
114
113
  FibonacciHeapNode: () => FibonacciHeapNode,
115
114
  HashMap: () => HashMap,
116
- HashMapIterator: () => HashMapIterator,
117
115
  HashTable: () => HashTable,
118
116
  HashTableNode: () => HashTableNode,
119
117
  Heap: () => Heap,
@@ -568,146 +566,7 @@ var dataStructureTyped = (() => {
568
566
  };
569
567
  var calcMinUnitsRequired = (totalQuantity, unitSize) => Math.floor((totalQuantity + unitSize - 1) / unitSize);
570
568
 
571
- // src/types/data-structures/binary-tree/binary-tree.ts
572
- var IterationType = /* @__PURE__ */ ((IterationType3) => {
573
- IterationType3["ITERATIVE"] = "ITERATIVE";
574
- IterationType3["RECURSIVE"] = "RECURSIVE";
575
- return IterationType3;
576
- })(IterationType || {});
577
- var FamilyPosition = /* @__PURE__ */ ((FamilyPosition2) => {
578
- FamilyPosition2["ROOT"] = "ROOT";
579
- FamilyPosition2["LEFT"] = "LEFT";
580
- FamilyPosition2["RIGHT"] = "RIGHT";
581
- FamilyPosition2["ROOT_LEFT"] = "ROOT_LEFT";
582
- FamilyPosition2["ROOT_RIGHT"] = "ROOT_RIGHT";
583
- FamilyPosition2["ISOLATED"] = "ISOLATED";
584
- FamilyPosition2["MAL_NODE"] = "MAL_NODE";
585
- return FamilyPosition2;
586
- })(FamilyPosition || {});
587
-
588
- // src/types/data-structures/binary-tree/rb-tree.ts
589
- var RBTNColor = /* @__PURE__ */ ((RBTNColor2) => {
590
- RBTNColor2[RBTNColor2["RED"] = 1] = "RED";
591
- RBTNColor2[RBTNColor2["BLACK"] = 0] = "BLACK";
592
- return RBTNColor2;
593
- })(RBTNColor || {});
594
-
595
- // src/types/helpers.ts
596
- var CP = /* @__PURE__ */ ((CP2) => {
597
- CP2["lt"] = "lt";
598
- CP2["eq"] = "eq";
599
- CP2["gt"] = "gt";
600
- return CP2;
601
- })(CP || {});
602
- var IterateDirection = /* @__PURE__ */ ((IterateDirection2) => {
603
- IterateDirection2[IterateDirection2["DEFAULT"] = 0] = "DEFAULT";
604
- IterateDirection2[IterateDirection2["REVERSE"] = 1] = "REVERSE";
605
- return IterateDirection2;
606
- })(IterateDirection || {});
607
-
608
569
  // src/data-structures/hash/hash-map.ts
609
- var HashMapIterator = class _HashMapIterator {
610
- /**
611
- * This is a constructor function for a linked list iterator in a HashMap data structure.
612
- * @param node - The `node` parameter is a reference to a `HashMapLinkedNode` object. This object
613
- * represents a node in a linked list used in a hash map data structure. It contains a key-value pair
614
- * and references to the previous and next nodes in the linked list.
615
- * @param sentinel - The `sentinel` parameter is a reference to a special node in a linked list. It
616
- * is used to mark the beginning or end of the list and is typically used in data structures like
617
- * hash maps or linked lists to simplify operations and boundary checks.
618
- * @param hashMap - A HashMap object that stores key-value pairs.
619
- * @param {IterateDirection} iterateDirection - The `iterateDirection` parameter is an optional
620
- * parameter that specifies the direction in which the iterator should iterate over the elements of
621
- * the HashMap. It can take one of the following values:
622
- * @returns The constructor does not return anything. It is used to initialize the properties and
623
- * methods of the object being created.
624
- */
625
- constructor(node, sentinel, hashMap, iterateDirection = 0 /* DEFAULT */) {
626
- __publicField(this, "hashMap");
627
- __publicField(this, "iterateDirection");
628
- __publicField(this, "_node");
629
- __publicField(this, "_sentinel");
630
- this._node = node;
631
- this._sentinel = sentinel;
632
- this.iterateDirection = iterateDirection;
633
- if (this.iterateDirection === 0 /* DEFAULT */) {
634
- this.prev = function() {
635
- if (this._node.prev === this._sentinel) {
636
- throwRangeError();
637
- }
638
- this._node = this._node.prev;
639
- return this;
640
- };
641
- this.next = function() {
642
- if (this._node === this._sentinel) {
643
- throwRangeError();
644
- }
645
- this._node = this._node.next;
646
- return this;
647
- };
648
- } else {
649
- this.prev = function() {
650
- if (this._node.next === this._sentinel) {
651
- throwRangeError();
652
- }
653
- this._node = this._node.next;
654
- return this;
655
- };
656
- this.next = function() {
657
- if (this._node === this._sentinel) {
658
- throwRangeError();
659
- }
660
- this._node = this._node.prev;
661
- return this;
662
- };
663
- }
664
- this.hashMap = hashMap;
665
- }
666
- /**
667
- * The above function returns a Proxy object that allows access to the key and value of a node in a
668
- * data structure.
669
- * @returns The code is returning a Proxy object.
670
- */
671
- get current() {
672
- if (this._node === this._sentinel) {
673
- throwRangeError();
674
- }
675
- return new Proxy([], {
676
- get: (target, prop) => {
677
- if (prop === "0")
678
- return this._node.key;
679
- else if (prop === "1")
680
- return this._node.value;
681
- target[0] = this._node.key;
682
- target[1] = this._node.value;
683
- return target[prop];
684
- },
685
- set: (_, prop, newValue) => {
686
- if (prop !== "1") {
687
- throw new TypeError(`prop should be string '1'`);
688
- }
689
- this._node.value = newValue;
690
- return true;
691
- }
692
- });
693
- }
694
- /**
695
- * The function checks if a node is accessible.
696
- * @returns a boolean value indicating whether the `_node` is not equal to the `_sentinel`.
697
- */
698
- isAccessible() {
699
- return this._node !== this._sentinel;
700
- }
701
- prev() {
702
- return this;
703
- }
704
- next() {
705
- return this;
706
- }
707
- clone() {
708
- return new _HashMapIterator(this._node, this._sentinel, this.hashMap, this.iterateDirection);
709
- }
710
- };
711
570
  var HashMap = class {
712
571
  /**
713
572
  * The constructor initializes a HashMap object with an optional initial set of key-value pairs.
@@ -733,49 +592,6 @@ var dataStructureTyped = (() => {
733
592
  get size() {
734
593
  return this._size;
735
594
  }
736
- /**
737
- * Time Complexity: O(1)
738
- * Space Complexity: O(1)
739
- *
740
- * The function returns a new iterator object for a HashMap.
741
- * @returns A new instance of the HashMapIterator class is being returned.
742
- */
743
- get begin() {
744
- return new HashMapIterator(this._head, this._sentinel, this);
745
- }
746
- /**
747
- * Time Complexity: O(1)
748
- * Space Complexity: O(1)
749
- *
750
- * The function returns a new HashMapIterator object with the _sentinel value as both the start and
751
- * end values.
752
- * @returns A new instance of the HashMapIterator class is being returned.
753
- */
754
- get end() {
755
- return new HashMapIterator(this._sentinel, this._sentinel, this);
756
- }
757
- /**
758
- * Time Complexity: O(1)
759
- * Space Complexity: O(1)
760
- *
761
- * The reverseBegin function returns a new HashMapIterator object that iterates over the elements of
762
- * a HashMap in reverse order.
763
- * @returns A new instance of the HashMapIterator class is being returned.
764
- */
765
- get reverseBegin() {
766
- return new HashMapIterator(this._tail, this._sentinel, this, 1 /* REVERSE */);
767
- }
768
- /**
769
- * Time Complexity: O(1)
770
- * Space Complexity: O(1)
771
- *
772
- * The reverseEnd function returns a new HashMapIterator object that iterates over the elements of a
773
- * HashMap in reverse order.
774
- * @returns A new instance of the HashMapIterator class is being returned.
775
- */
776
- get reverseEnd() {
777
- return new HashMapIterator(this._sentinel, this._sentinel, this, 1 /* REVERSE */);
778
- }
779
595
  /**
780
596
  * Time Complexity: O(1)
781
597
  * Space Complexity: O(1)
@@ -802,6 +618,27 @@ var dataStructureTyped = (() => {
802
618
  return;
803
619
  return [this._tail.key, this._tail.value];
804
620
  }
621
+ /**
622
+ * The `begin()` function in TypeScript iterates over a linked list and yields key-value pairs.
623
+ */
624
+ *begin() {
625
+ let node = this._head;
626
+ while (node !== this._sentinel) {
627
+ yield [node.key, node.value];
628
+ node = node.next;
629
+ }
630
+ }
631
+ /**
632
+ * The function `reverseBegin()` iterates over a linked list in reverse order, yielding each node's
633
+ * key and value.
634
+ */
635
+ *reverseBegin() {
636
+ let node = this._tail;
637
+ while (node !== this._sentinel) {
638
+ yield [node.key, node.value];
639
+ node = node.prev;
640
+ }
641
+ }
805
642
  /**
806
643
  * Time Complexity: O(1)
807
644
  * Space Complexity: O(1)
@@ -900,33 +737,6 @@ var dataStructureTyped = (() => {
900
737
  }
901
738
  return [node.key, node.value];
902
739
  }
903
- /**
904
- * Time Complexity: O(1)
905
- * Space Complexity: O(1)
906
- *
907
- * The function `getIterator` returns a new instance of `HashMapIterator` based on the provided key
908
- * and whether it is an object key or not.
909
- * @param {K} key - The `key` parameter is the key used to retrieve the iterator from the HashMap. It
910
- * can be of any type, depending on how the HashMap is implemented.
911
- * @param {boolean} [isObjectKey] - The `isObjectKey` parameter is an optional boolean parameter that
912
- * indicates whether the `key` parameter is an object key. If `isObjectKey` is `true`, it means that
913
- * the `key` parameter is an object and needs to be handled differently. If `isObjectKey` is `false`
914
- * @returns a new instance of the `HashMapIterator` class.
915
- */
916
- getIterator(key, isObjectKey) {
917
- let node;
918
- if (isObjectKey) {
919
- const index = key[this.OBJ_KEY_INDEX];
920
- if (index === void 0) {
921
- node = this._sentinel;
922
- } else {
923
- node = this._nodes[index];
924
- }
925
- } else {
926
- node = this._orgMap[key] || this._sentinel;
927
- }
928
- return new HashMapIterator(node, this._sentinel, this);
929
- }
930
740
  /**
931
741
  * Time Complexity: O(1)
932
742
  * Space Complexity: O(1)
@@ -3161,66 +2971,16 @@ var dataStructureTyped = (() => {
3161
2971
  };
3162
2972
 
3163
2973
  // src/data-structures/queue/deque.ts
3164
- var DequeIterator = class _DequeIterator {
3165
- constructor(index, deque, iterateDirection = 0 /* DEFAULT */) {
3166
- __publicField(this, "iterateDirection");
3167
- __publicField(this, "index");
3168
- __publicField(this, "deque");
3169
- this.index = index;
3170
- this.iterateDirection = iterateDirection;
3171
- if (this.iterateDirection === 0 /* DEFAULT */) {
3172
- this.prev = function() {
3173
- if (this.index === 0) {
3174
- throwRangeError();
3175
- }
3176
- this.index -= 1;
3177
- return this;
3178
- };
3179
- this.next = function() {
3180
- if (this.index === this.deque.size) {
3181
- throwRangeError();
3182
- }
3183
- this.index += 1;
3184
- return this;
3185
- };
3186
- } else {
3187
- this.prev = function() {
3188
- if (this.index === this.deque.size - 1) {
3189
- throwRangeError();
3190
- }
3191
- this.index += 1;
3192
- return this;
3193
- };
3194
- this.next = function() {
3195
- if (this.index === -1) {
3196
- throwRangeError();
3197
- }
3198
- this.index -= 1;
3199
- return this;
3200
- };
3201
- }
3202
- this.deque = deque;
3203
- }
3204
- get current() {
3205
- return this.deque.getAt(this.index);
3206
- }
3207
- set current(newElement) {
3208
- this.deque.setAt(this.index, newElement);
3209
- }
3210
- isAccessible() {
3211
- return this.index !== this.deque.size;
3212
- }
3213
- prev() {
3214
- return this;
3215
- }
3216
- next() {
3217
- return this;
3218
- }
3219
- clone() {
3220
- return new _DequeIterator(this.index, this.deque, this.iterateDirection);
3221
- }
3222
- };
3223
2974
  var Deque = class _Deque {
2975
+ /**
2976
+ * The constructor initializes a data structure with a specified bucket size and populates it with
2977
+ * elements from an iterable.
2978
+ * @param elements - The `elements` parameter is an iterable object (such as an array or a Set) that
2979
+ * contains the initial elements to be stored in the data structure. It can also be an object with a
2980
+ * `length` property or a `size` property, which represents the number of elements in the iterable.
2981
+ * @param bucketSize - The `bucketSize` parameter is the maximum number of elements that can be
2982
+ * stored in each bucket. It determines the size of each bucket in the data structure.
2983
+ */
3224
2984
  constructor(elements = [], bucketSize = 1 << 12) {
3225
2985
  __publicField(this, "_bucketFirst", 0);
3226
2986
  __publicField(this, "_firstInBucket", 0);
@@ -3232,9 +2992,15 @@ var dataStructureTyped = (() => {
3232
2992
  __publicField(this, "_size", 0);
3233
2993
  let _size;
3234
2994
  if ("length" in elements) {
3235
- _size = elements.length;
2995
+ if (elements.length instanceof Function)
2996
+ _size = elements.length();
2997
+ else
2998
+ _size = elements.length;
3236
2999
  } else {
3237
- _size = elements.size;
3000
+ if (elements.size instanceof Function)
3001
+ _size = elements.size();
3002
+ else
3003
+ _size = elements.size;
3238
3004
  }
3239
3005
  this._bucketSize = bucketSize;
3240
3006
  this._bucketCount = calcMinUnitsRequired(_size, this._bucketSize) || 1;
@@ -3254,6 +3020,11 @@ var dataStructureTyped = (() => {
3254
3020
  get size() {
3255
3021
  return this._size;
3256
3022
  }
3023
+ /**
3024
+ * The function returns the first element in a collection if it exists, otherwise it returns
3025
+ * undefined.
3026
+ * @returns The first element of the collection, of type E, is being returned.
3027
+ */
3257
3028
  get first() {
3258
3029
  if (this.size === 0)
3259
3030
  return;
@@ -3264,13 +3035,6 @@ var dataStructureTyped = (() => {
3264
3035
  return;
3265
3036
  return this._buckets[this._bucketLast][this._lastInBucket];
3266
3037
  }
3267
- /**
3268
- * Time Complexity: Amortized O(1) - Generally constant time, but resizing when the deque is full leads to O(n).
3269
- * Space Complexity: O(n) - In worst case, resizing doubles the array size.
3270
- */
3271
- empty() {
3272
- return this._size === 0;
3273
- }
3274
3038
  /**
3275
3039
  * Time Complexity: O(1) - Removes the last element.
3276
3040
  * Space Complexity: O(1) - Operates in-place.
@@ -3329,24 +3093,50 @@ var dataStructureTyped = (() => {
3329
3093
  popFirst() {
3330
3094
  return this.shift();
3331
3095
  }
3096
+ /**
3097
+ * The clear() function resets the state of the object by initializing all variables to their default
3098
+ * values.
3099
+ */
3332
3100
  clear() {
3333
3101
  this._buckets = [new Array(this._bucketSize)];
3334
3102
  this._bucketCount = 1;
3335
3103
  this._bucketFirst = this._bucketLast = this._size = 0;
3336
3104
  this._firstInBucket = this._lastInBucket = this._bucketSize >> 1;
3337
3105
  }
3338
- begin() {
3339
- return new DequeIterator(0, this);
3340
- }
3341
- end() {
3342
- return new DequeIterator(this.size, this);
3343
- }
3344
- reverseBegin() {
3345
- return new DequeIterator(this.size - 1, this, 1 /* REVERSE */);
3106
+ /**
3107
+ * The below function is a generator that yields elements from a collection one by one.
3108
+ */
3109
+ *begin() {
3110
+ let index = 0;
3111
+ while (index < this.size) {
3112
+ yield this.getAt(index);
3113
+ index++;
3114
+ }
3346
3115
  }
3347
- reverseEnd() {
3348
- return new DequeIterator(-1, this, 1 /* REVERSE */);
3116
+ /**
3117
+ * The function `reverseBegin()` is a generator that yields elements in reverse order starting from
3118
+ * the last element.
3119
+ */
3120
+ *reverseBegin() {
3121
+ let index = this.size - 1;
3122
+ while (index >= 0) {
3123
+ yield this.getAt(index);
3124
+ index--;
3125
+ }
3349
3126
  }
3127
+ /**
3128
+ * Time Complexity - Amortized O(1) (possible reallocation)
3129
+ * Space Complexity - O(n) (due to potential resizing).
3130
+ */
3131
+ /**
3132
+ * Time Complexity - Amortized O(1) (possible reallocation),
3133
+ * Space Complexity - O(n) (due to potential resizing).
3134
+ *
3135
+ * The push function adds an element to a data structure and reallocates memory if necessary.
3136
+ * @param {E} element - The `element` parameter represents the value that you want to add to the data
3137
+ * structure.
3138
+ * @returns The size of the data structure after the element has been pushed.
3139
+ */
3350
3140
  push(element) {
3351
3141
  if (this.size) {
3352
3142
  if (this._lastInBucket < this._bucketSize - 1) {
@@ -3365,6 +3155,18 @@ var dataStructureTyped = (() => {
3365
3155
  this._buckets[this._bucketLast][this._lastInBucket] = element;
3366
3156
  return this.size;
3367
3157
  }
3158
+ /**
3159
+ * Time Complexity: O(1)
3160
+ * Space Complexity: O(1)
3161
+ */
3162
+ /**
3163
+ * Time Complexity: O(1)
3164
+ * Space Complexity: O(1)
3165
+ *
3166
+ * The `pop()` function removes and returns the last element from a data structure, updating the
3167
+ * internal state variables accordingly.
3168
+ * @returns The element that was removed from the data structure is being returned.
3169
+ */
3368
3170
  pop() {
3369
3171
  if (this.size === 0)
3370
3172
  return;
@@ -3383,6 +3185,20 @@ var dataStructureTyped = (() => {
3383
3185
  this._size -= 1;
3384
3186
  return element;
3385
3187
  }
3188
+ /**
3189
+ * Time Complexity: Amortized O(1)
3190
+ * Space Complexity: O(n)
3191
+ */
3192
+ /**
3193
+ * Time Complexity: Amortized O(1)
3194
+ * Space Complexity: O(n)
3195
+ *
3196
+ * The `unshift` function adds an element to the beginning of an array-like data structure and
3197
+ * returns the new size of the structure.
3198
+ * @param {E} element - The `element` parameter represents the element that you want to add to the
3199
+ * beginning of the data structure.
3200
+ * @returns The size of the data structure after the element has been added.
3201
+ */
3386
3202
  unshift(element) {
3387
3203
  if (this.size) {
3388
3204
  if (this._firstInBucket > 0) {
@@ -3401,6 +3217,19 @@ var dataStructureTyped = (() => {
3401
3217
  this._buckets[this._bucketFirst][this._firstInBucket] = element;
3402
3218
  return this.size;
3403
3219
  }
3220
+ /**
3221
+ * Time Complexity: O(1)
3222
+ * Space Complexity: O(1)
3223
+ */
3224
+ /**
3225
+ * Time Complexity: O(1)
3226
+ * Space Complexity: O(1)
3227
+ *
3228
+ * The `shift()` function removes and returns the first element from a data structure, updating the
3229
+ * internal state variables accordingly.
3230
+ * @returns The element that is being removed from the beginning of the data structure is being
3231
+ * returned.
3232
+ */
3404
3233
  shift() {
3405
3234
  if (this.size === 0)
3406
3235
  return;
@@ -3419,6 +3248,20 @@ var dataStructureTyped = (() => {
3419
3248
  this._size -= 1;
3420
3249
  return element;
3421
3250
  }
3251
+ /**
3252
+ * Time Complexity: O(1)
3253
+ * Space Complexity: O(1)
3254
+ */
3255
+ /**
3256
+ * Time Complexity: O(1)
3257
+ * Space Complexity: O(1)
3258
+ *
3259
+ * The `getAt` function retrieves an element at a specified position in an array-like data structure.
3260
+ * @param {number} pos - The `pos` parameter represents the position of the element that you want to
3261
+ * retrieve from the data structure. It is of type `number` and should be a valid index within the
3262
+ * range of the data structure.
3263
+ * @returns The element at the specified position in the data structure is being returned.
3264
+ */
3422
3265
  getAt(pos) {
3423
3266
  rangeCheck(pos, 0, this.size - 1);
3424
3267
  const {
@@ -3427,6 +3270,20 @@ var dataStructureTyped = (() => {
3427
3270
  } = this._getBucketAndPosition(pos);
3428
3271
  return this._buckets[bucketIndex][indexInBucket];
3429
3272
  }
3273
+ /**
3274
+ * Time Complexity: O(1)
3275
+ * Space Complexity: O(1)
3276
+ */
3277
+ /**
3278
+ * Time Complexity: O(1)
3279
+ * Space Complexity: O(1)
3280
+ *
3281
+ * The `setAt` function sets an element at a specific position in an array-like data structure.
3282
+ * @param {number} pos - The `pos` parameter represents the position at which the element needs to be
3283
+ * set. It is of type `number`.
3284
+ * @param {E} element - The `element` parameter is the value that you want to set at the specified
3285
+ * position in the data structure.
3286
+ */
3430
3287
  setAt(pos, element) {
3431
3288
  rangeCheck(pos, 0, this.size - 1);
3432
3289
  const {
@@ -3435,6 +3292,25 @@ var dataStructureTyped = (() => {
3435
3292
  } = this._getBucketAndPosition(pos);
3436
3293
  this._buckets[bucketIndex][indexInBucket] = element;
3437
3294
  }
3295
+ /**
3296
+ * Time Complexity: O(n)
3297
+ * Space Complexity: O(n)
3298
+ */
3299
+ /**
3300
+ * Time Complexity: O(n)
3301
+ * Space Complexity: O(n)
3302
+ *
3303
+ * The `insertAt` function inserts one or more elements at a specified position in an array-like data
3304
+ * structure.
3305
+ * @param {number} pos - The `pos` parameter represents the position at which the element(s) should
3306
+ * be inserted. It is of type `number`.
3307
+ * @param {E} element - The `element` parameter represents the element that you want to insert into
3308
+ * the array at the specified position.
3309
+ * @param [num=1] - The `num` parameter represents the number of times the `element` should be
3310
+ * inserted at the specified position (`pos`). By default, it is set to 1, meaning that the `element`
3311
+ * will be inserted once. However, you can provide a different value for `num` if you want
3312
+ * @returns The size of the array after the insertion is being returned.
3313
+ */
3438
3314
  insertAt(pos, element, num = 1) {
3439
3315
  const length = this.size;
3440
3316
  rangeCheck(pos, 0, length);
@@ -3457,6 +3333,20 @@ var dataStructureTyped = (() => {
3457
3333
  }
3458
3334
  return this.size;
3459
3335
  }
3336
+ /**
3337
+ * Time Complexity: O(1)
3338
+ * Space Complexity: O(1)
3339
+ */
3340
+ /**
3341
+ * Time Complexity: O(1)
3342
+ * Space Complexity: O(1)
3343
+ *
3344
+ * The `cut` function updates the state of the object based on the given position and returns the
3345
+ * updated size.
3346
+ * @param {number} pos - The `pos` parameter represents the position at which the string should be
3347
+ * cut. It is a number that indicates the index of the character where the cut should be made.
3348
+ * @returns The method is returning the updated size of the data structure.
3349
+ */
3460
3350
  cut(pos) {
3461
3351
  if (pos < 0) {
3462
3352
  this.clear();
@@ -3471,6 +3361,21 @@ var dataStructureTyped = (() => {
3471
3361
  this._size = pos + 1;
3472
3362
  return this.size;
3473
3363
  }
3364
+ /**
3365
+ * Time Complexity: O(n)
3366
+ * Space Complexity: O(1)
3367
+ */
3368
+ /**
3369
+ * Time Complexity: O(n)
3370
+ * Space Complexity: O(1)
3371
+ *
3372
+ * The `deleteAt` function removes an element at a specified position in an array-like data
3373
+ * structure.
3374
+ * @param {number} pos - The `pos` parameter in the `deleteAt` function represents the position at
3375
+ * which an element needs to be deleted from the data structure. It is of type `number` and indicates
3376
+ * the index of the element to be deleted.
3377
+ * @returns The size of the data structure after the deletion operation is performed.
3378
+ */
3474
3379
  deleteAt(pos) {
3475
3380
  rangeCheck(pos, 0, this.size - 1);
3476
3381
  if (pos === 0)
@@ -3496,6 +3401,20 @@ var dataStructureTyped = (() => {
3496
3401
  }
3497
3402
  return this.size;
3498
3403
  }
3404
+ /**
3405
+ * Time Complexity: O(n)
3406
+ * Space Complexity: O(1)
3407
+ */
3408
+ /**
3409
+ * Time Complexity: O(n)
3410
+ * Space Complexity: O(1)
3411
+ *
3412
+ * The `delete` function removes all occurrences of a specified element from an array-like data
3413
+ * structure.
3414
+ * @param {E} element - The `element` parameter represents the element that you want to delete from
3415
+ * the data structure.
3416
+ * @returns The size of the data structure after the element has been deleted.
3417
+ */
3499
3418
  delete(element) {
3500
3419
  const size = this.size;
3501
3420
  if (size === 0)
@@ -3513,20 +3432,19 @@ var dataStructureTyped = (() => {
3513
3432
  this.cut(index - 1);
3514
3433
  return this.size;
3515
3434
  }
3516
- deleteByIterator(iter) {
3517
- const index = iter.index;
3518
- this.deleteAt(index);
3519
- iter = iter.next();
3520
- return iter;
3521
- }
3522
- findIterator(element) {
3523
- for (let i = 0; i < this.size; ++i) {
3524
- if (this.getAt(i) === element) {
3525
- return new DequeIterator(i, this);
3526
- }
3527
- }
3528
- return this.end();
3529
- }
3435
+ /**
3436
+ * Time Complexity: O(n)
3437
+ * Space Complexity: O(1)
3438
+ */
3439
+ /**
3440
+ * Time Complexity: O(n)
3441
+ * Space Complexity: O(1)
3442
+ *
3443
+ * The reverse() function reverses the order of the buckets and the elements within each bucket in a
3444
+ * data structure.
3445
+ * @returns The reverse() method is returning the object itself (this) after performing the reverse
3446
+ * operation on the buckets and updating the relevant properties.
3447
+ */
3530
3448
  reverse() {
3531
3449
  this._buckets.reverse().forEach(function(bucket) {
3532
3450
  bucket.reverse();
@@ -3538,6 +3456,18 @@ var dataStructureTyped = (() => {
3538
3456
  this._lastInBucket = this._bucketSize - _firstInBucket - 1;
3539
3457
  return this;
3540
3458
  }
3459
+ /**
3460
+ * Time Complexity: O(n)
3461
+ * Space Complexity: O(1)
3462
+ */
3463
+ /**
3464
+ * Time Complexity: O(n)
3465
+ * Space Complexity: O(1)
3466
+ *
3467
+ * The `unique()` function removes duplicate elements from an array-like data structure and returns
3468
+ * the number of unique elements.
3469
+ * @returns The size of the modified array is being returned.
3470
+ */
3541
3471
  unique() {
3542
3472
  if (this.size <= 1) {
3543
3473
  return this.size;
@@ -3554,6 +3484,20 @@ var dataStructureTyped = (() => {
3554
3484
  this.cut(index - 1);
3555
3485
  return this.size;
3556
3486
  }
3487
+ /**
3488
+ * Time Complexity: O(n log n)
3489
+ * Space Complexity: O(n)
3490
+ */
3491
+ /**
3492
+ * Time Complexity: O(n log n)
3493
+ * Space Complexity: O(n)
3494
+ *
3495
+ * The `sort` function sorts the elements in a data structure using a provided comparator function.
3496
+ * @param [comparator] - The `comparator` parameter is a function that takes in two elements `x` and
3497
+ * `y` of type `E` and returns a number. The comparator function is used to determine the order of
3498
+ * the elements in the sorted array.
3499
+ * @returns The method is returning the sorted instance of the object on which the method is called.
3500
+ */
3557
3501
  sort(comparator) {
3558
3502
  const arr = [];
3559
3503
  for (let i = 0; i < this.size; ++i) {
@@ -3565,6 +3509,19 @@ var dataStructureTyped = (() => {
3565
3509
  }
3566
3510
  return this;
3567
3511
  }
3512
+ /**
3513
+ * Time Complexity: O(n)
3514
+ * Space Complexity: O(n)
3515
+ */
3516
+ /**
3517
+ * Time Complexity: O(n)
3518
+ * Space Complexity: O(n)
3519
+ *
3520
+ * The `shrinkToFit` function reorganizes the elements in an array-like data structure to minimize
3521
+ * memory usage.
3522
+ * @returns Nothing is being returned. The function is using the `return` statement to exit early if
3523
+ * `this.size` is 0, but it does not return any value.
3524
+ */
3568
3525
  shrinkToFit() {
3569
3526
  if (this.size === 0)
3570
3527
  return;
@@ -3587,11 +3544,39 @@ var dataStructureTyped = (() => {
3587
3544
  this._bucketLast = newBuckets.length - 1;
3588
3545
  this._buckets = newBuckets;
3589
3546
  }
3547
+ /**
3548
+ * Time Complexity: O(n)
3549
+ * Space Complexity: O(1)
3550
+ */
3551
+ /**
3552
+ * Time Complexity: O(n)
3553
+ * Space Complexity: O(1)
3554
+ *
3555
+ * The `forEach` function iterates over each element in a deque and applies a callback function to
3556
+ * each element.
3557
+ * @param callback - The callback parameter is a function that will be called for each element in the
3558
+ * deque. It takes three parameters:
3559
+ */
3590
3560
  forEach(callback) {
3591
3561
  for (let i = 0; i < this.size; ++i) {
3592
3562
  callback(this.getAt(i), i, this);
3593
3563
  }
3594
3564
  }
3565
+ /**
3566
+ * Time Complexity: O(n)
3567
+ * Space Complexity: O(1)
3568
+ */
3569
+ /**
3570
+ * Time Complexity: O(n)
3571
+ * Space Complexity: O(1)
3572
+ *
3573
+ * The `find` function iterates over the elements in a deque and returns the first element for which
3574
+ * the callback function returns true, or undefined if no such element is found.
3575
+ * @param callback - A function that takes three parameters: element, index, and deque. It should
3576
+ * return a boolean value indicating whether the element satisfies a certain condition.
3577
+ * @returns The method `find` returns the first element in the deque that satisfies the condition
3578
+ * specified by the callback function. If no element satisfies the condition, it returns `undefined`.
3579
+ */
3595
3580
  find(callback) {
3596
3581
  for (let i = 0; i < this.size; ++i) {
3597
3582
  const element = this.getAt(i);
@@ -3601,6 +3586,17 @@ var dataStructureTyped = (() => {
3601
3586
  }
3602
3587
  return void 0;
3603
3588
  }
3589
+ /**
3590
+ * Time Complexity: O(n)
3591
+ * Space Complexity: O(n)
3592
+ */
3593
+ /**
3594
+ * Time Complexity: O(n)
3595
+ * Space Complexity: O(n)
3596
+ *
3597
+ * The `toArray` function converts the elements of a data structure into an array.
3598
+ * @returns The `toArray()` method is returning an array of elements of type `E`.
3599
+ */
3604
3600
  toArray() {
3605
3601
  const arr = [];
3606
3602
  for (let i = 0; i < this.size; ++i) {
@@ -3608,6 +3604,19 @@ var dataStructureTyped = (() => {
3608
3604
  }
3609
3605
  return arr;
3610
3606
  }
3607
+ /**
3608
+ * Time Complexity: O(n)
3609
+ * Space Complexity: O(n)
3610
+ */
3611
+ /**
3612
+ * Time Complexity: O(n)
3613
+ * Space Complexity: O(n)
3614
+ *
3615
+ * The `map` function takes a callback function and applies it to each element in the deque,
3616
+ * returning a new deque with the results.
3617
+ * @param callback - The `callback` parameter is a function that takes three arguments:
3618
+ * @returns The `map` method is returning a new `Deque` object with the transformed elements.
3619
+ */
3611
3620
  map(callback) {
3612
3621
  const newDeque = new _Deque([], this._bucketSize);
3613
3622
  for (let i = 0; i < this.size; ++i) {
@@ -3615,6 +3624,21 @@ var dataStructureTyped = (() => {
3615
3624
  }
3616
3625
  return newDeque;
3617
3626
  }
3627
+ /**
3628
+ * Time Complexity: O(n)
3629
+ * Space Complexity: O(n)
3630
+ */
3631
+ /**
3632
+ * Time Complexity: O(n)
3633
+ * Space Complexity: O(n)
3634
+ *
3635
+ * The `filter` function creates a new deque containing only the elements that satisfy the given
3636
+ * predicate function.
3637
+ * @param predicate - The `predicate` parameter is a function that takes three arguments: `element`,
3638
+ * `index`, and `deque`.
3639
+ * @returns The `filter` method is returning a new `Deque` object that contains only the elements
3640
+ * that satisfy the given `predicate` function.
3641
+ */
3618
3642
  filter(predicate) {
3619
3643
  const newDeque = new _Deque([], this._bucketSize);
3620
3644
  for (let i = 0; i < this.size; ++i) {
@@ -3625,6 +3649,23 @@ var dataStructureTyped = (() => {
3625
3649
  }
3626
3650
  return newDeque;
3627
3651
  }
3652
+ /**
3653
+ * Time Complexity: O(n)
3654
+ * Space Complexity: O(1)
3655
+ */
3656
+ /**
3657
+ * Time Complexity: O(n)
3658
+ * Space Complexity: O(1)
3659
+ *
3660
+ * The `reduce` function iterates over the elements of a deque and applies a callback function to
3661
+ * each element, accumulating a single value.
3662
+ * @param callback - The `callback` parameter is a function that takes four arguments:
3663
+ * @param {T} initialValue - The `initialValue` parameter is the initial value of the accumulator. It
3664
+ * is the value that will be passed as the first argument to the `callback` function when reducing
3665
+ * the elements of the deque.
3666
+ * @returns the final value of the accumulator after iterating over all elements in the deque and
3667
+ * applying the callback function to each element.
3668
+ */
3628
3669
  reduce(callback, initialValue) {
3629
3670
  let accumulator = initialValue;
3630
3671
  for (let i = 0; i < this.size; ++i) {
@@ -3632,6 +3673,21 @@ var dataStructureTyped = (() => {
3632
3673
  }
3633
3674
  return accumulator;
3634
3675
  }
3676
+ /**
3677
+ * Time Complexity: O(n)
3678
+ * Space Complexity: O(1)
3679
+ */
3680
+ /**
3681
+ * Time Complexity: O(n)
3682
+ * Space Complexity: O(1)
3683
+ *
3684
+ * The function "indexOf" returns the index of the first occurrence of a given element in an array,
3685
+ * or -1 if the element is not found.
3686
+ * @param {E} element - The "element" parameter represents the element that you want to find the
3687
+ * index of in the data structure.
3688
+ * @returns The indexOf function returns the index of the first occurrence of the specified element
3689
+ * in the data structure. If the element is not found, it returns -1.
3690
+ */
3635
3691
  indexOf(element) {
3636
3692
  for (let i = 0; i < this.size; ++i) {
3637
3693
  if (this.getAt(i) === element) {
@@ -3640,11 +3696,35 @@ var dataStructureTyped = (() => {
3640
3696
  }
3641
3697
  return -1;
3642
3698
  }
3699
+ /**
3700
+ * Time Complexity: O(n)
3701
+ * Space Complexity: O(1)
3702
+ */
3703
+ /**
3704
+ * Time Complexity: O(n)
3705
+ * Space Complexity: O(1)
3706
+ *
3707
+ * The above function is an implementation of the iterator protocol in TypeScript, allowing the
3708
+ * object to be iterated over using a for...of loop.
3709
+ */
3643
3710
  *[Symbol.iterator]() {
3644
3711
  for (let i = 0; i < this.size; ++i) {
3645
3712
  yield this.getAt(i);
3646
3713
  }
3647
3714
  }
3715
+ /**
3716
+ * Time Complexity: O(n)
3717
+ * Space Complexity: O(n)
3718
+ */
3719
+ /**
3720
+ * Time Complexity: O(n)
3721
+ * Space Complexity: O(n)
3722
+ *
3723
+ * The `_reallocate` function reallocates the buckets in an array, adding new buckets if needed.
3724
+ * @param {number} [needBucketNum] - The `needBucketNum` parameter is an optional number that
3725
+ * specifies the number of new buckets needed. If not provided, it will default to half of the
3726
+ * current bucket count (`this._bucketCount >> 1`) or 1 if the current bucket count is less than 2.
3727
+ */
3648
3728
  _reallocate(needBucketNum) {
3649
3729
  const newBuckets = [];
3650
3730
  const addBucketNum = needBucketNum || this._bucketCount >> 1 || 1;
@@ -3666,6 +3746,19 @@ var dataStructureTyped = (() => {
3666
3746
  this._buckets = newBuckets;
3667
3747
  this._bucketCount = newBuckets.length;
3668
3748
  }
3749
+ /**
3750
+ * Time Complexity: O(1)
3751
+ * Space Complexity: O(1)
3752
+ */
3753
+ /**
3754
+ * Time Complexity: O(1)
3755
+ * Space Complexity: O(1)
3756
+ *
3757
+ * The function calculates the bucket index and index within the bucket based on the given position.
3758
+ * @param {number} pos - The `pos` parameter represents the position within the data structure. It is
3759
+ * a number that indicates the index or position of an element within the structure.
3760
+ * @returns an object with two properties: "bucketIndex" and "indexInBucket".
3761
+ */
3669
3762
  _getBucketAndPosition(pos) {
3670
3763
  let bucketIndex;
3671
3764
  let indexInBucket;
@@ -6503,6 +6596,43 @@ var dataStructureTyped = (() => {
6503
6596
  }
6504
6597
  };
6505
6598
 
6599
+ // src/types/data-structures/binary-tree/binary-tree.ts
6600
+ var IterationType = /* @__PURE__ */ ((IterationType3) => {
6601
+ IterationType3["ITERATIVE"] = "ITERATIVE";
6602
+ IterationType3["RECURSIVE"] = "RECURSIVE";
6603
+ return IterationType3;
6604
+ })(IterationType || {});
6605
+ var FamilyPosition = /* @__PURE__ */ ((FamilyPosition2) => {
6606
+ FamilyPosition2["ROOT"] = "ROOT";
6607
+ FamilyPosition2["LEFT"] = "LEFT";
6608
+ FamilyPosition2["RIGHT"] = "RIGHT";
6609
+ FamilyPosition2["ROOT_LEFT"] = "ROOT_LEFT";
6610
+ FamilyPosition2["ROOT_RIGHT"] = "ROOT_RIGHT";
6611
+ FamilyPosition2["ISOLATED"] = "ISOLATED";
6612
+ FamilyPosition2["MAL_NODE"] = "MAL_NODE";
6613
+ return FamilyPosition2;
6614
+ })(FamilyPosition || {});
6615
+
6616
+ // src/types/data-structures/binary-tree/rb-tree.ts
6617
+ var RBTNColor = /* @__PURE__ */ ((RBTNColor2) => {
6618
+ RBTNColor2[RBTNColor2["RED"] = 1] = "RED";
6619
+ RBTNColor2[RBTNColor2["BLACK"] = 0] = "BLACK";
6620
+ return RBTNColor2;
6621
+ })(RBTNColor || {});
6622
+
6623
+ // src/types/helpers.ts
6624
+ var CP = /* @__PURE__ */ ((CP2) => {
6625
+ CP2["lt"] = "lt";
6626
+ CP2["eq"] = "eq";
6627
+ CP2["gt"] = "gt";
6628
+ return CP2;
6629
+ })(CP || {});
6630
+ var IterateDirection = /* @__PURE__ */ ((IterateDirection2) => {
6631
+ IterateDirection2[IterateDirection2["DEFAULT"] = 0] = "DEFAULT";
6632
+ IterateDirection2[IterateDirection2["REVERSE"] = 1] = "REVERSE";
6633
+ return IterateDirection2;
6634
+ })(IterateDirection || {});
6635
+
6506
6636
  // src/data-structures/binary-tree/binary-tree.ts
6507
6637
  var BinaryTreeNode = class {
6508
6638
  /**