data-structure-typed 1.53.8 → 1.54.0

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.
Files changed (115) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/CONTRIBUTING.md +1 -1
  3. package/dist/cjs/data-structures/base/iterable-entry-base.js +4 -4
  4. package/dist/cjs/data-structures/base/iterable-entry-base.js.map +1 -1
  5. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +34 -27
  6. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +62 -52
  7. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  8. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +3 -14
  9. package/dist/cjs/data-structures/binary-tree/avl-tree.js +22 -25
  10. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  11. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +32 -16
  12. package/dist/cjs/data-structures/binary-tree/binary-tree.js +43 -24
  13. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  14. package/dist/cjs/data-structures/binary-tree/bst.d.ts +14 -23
  15. package/dist/cjs/data-structures/binary-tree/bst.js +28 -29
  16. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  17. package/dist/cjs/data-structures/binary-tree/red-black-tree.d.ts +35 -28
  18. package/dist/cjs/data-structures/binary-tree/red-black-tree.js +52 -71
  19. package/dist/cjs/data-structures/binary-tree/red-black-tree.js.map +1 -1
  20. package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +18 -14
  21. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +36 -23
  22. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  23. package/dist/cjs/data-structures/graph/abstract-graph.js +2 -2
  24. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  25. package/dist/cjs/data-structures/hash/hash-map.d.ts +1 -1
  26. package/dist/cjs/data-structures/hash/hash-map.js +5 -5
  27. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  28. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +10 -10
  29. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +12 -12
  30. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  31. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +10 -10
  32. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +16 -16
  33. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  34. package/dist/cjs/interfaces/binary-tree.d.ts +1 -1
  35. package/dist/cjs/types/data-structures/base/base.d.ts +1 -1
  36. package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -2
  37. package/dist/cjs/types/data-structures/binary-tree/avl-tree.d.ts +2 -2
  38. package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +2 -2
  39. package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +3 -3
  40. package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +3 -3
  41. package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.d.ts +4 -4
  42. package/dist/mjs/data-structures/base/iterable-entry-base.js +4 -4
  43. package/dist/mjs/data-structures/base/iterable-entry-base.js.map +1 -1
  44. package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +34 -27
  45. package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +62 -52
  46. package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  47. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +3 -14
  48. package/dist/mjs/data-structures/binary-tree/avl-tree.js +22 -26
  49. package/dist/mjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  50. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +32 -16
  51. package/dist/mjs/data-structures/binary-tree/binary-tree.js +43 -24
  52. package/dist/mjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  53. package/dist/mjs/data-structures/binary-tree/bst.d.ts +14 -23
  54. package/dist/mjs/data-structures/binary-tree/bst.js +29 -30
  55. package/dist/mjs/data-structures/binary-tree/bst.js.map +1 -1
  56. package/dist/mjs/data-structures/binary-tree/red-black-tree.d.ts +35 -28
  57. package/dist/mjs/data-structures/binary-tree/red-black-tree.js +51 -71
  58. package/dist/mjs/data-structures/binary-tree/red-black-tree.js.map +1 -1
  59. package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +18 -14
  60. package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +36 -23
  61. package/dist/mjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  62. package/dist/mjs/data-structures/graph/abstract-graph.js +2 -2
  63. package/dist/mjs/data-structures/graph/abstract-graph.js.map +1 -1
  64. package/dist/mjs/data-structures/hash/hash-map.d.ts +1 -1
  65. package/dist/mjs/data-structures/hash/hash-map.js +5 -5
  66. package/dist/mjs/data-structures/hash/hash-map.js.map +1 -1
  67. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +10 -10
  68. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +12 -12
  69. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  70. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +10 -10
  71. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +16 -16
  72. package/dist/mjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  73. package/dist/mjs/interfaces/binary-tree.d.ts +1 -1
  74. package/dist/mjs/types/data-structures/base/base.d.ts +1 -1
  75. package/dist/mjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -2
  76. package/dist/mjs/types/data-structures/binary-tree/avl-tree.d.ts +2 -2
  77. package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +2 -2
  78. package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +3 -3
  79. package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +3 -3
  80. package/dist/mjs/types/data-structures/binary-tree/tree-multi-map.d.ts +4 -4
  81. package/dist/umd/data-structure-typed.js +258 -249
  82. package/dist/umd/data-structure-typed.min.js +3 -3
  83. package/dist/umd/data-structure-typed.min.js.map +1 -1
  84. package/package.json +6 -6
  85. package/src/data-structures/base/iterable-entry-base.ts +4 -4
  86. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +83 -64
  87. package/src/data-structures/binary-tree/avl-tree.ts +40 -34
  88. package/src/data-structures/binary-tree/binary-tree.ts +74 -30
  89. package/src/data-structures/binary-tree/bst.ts +57 -43
  90. package/src/data-structures/binary-tree/red-black-tree.ts +66 -70
  91. package/src/data-structures/binary-tree/tree-multi-map.ts +56 -30
  92. package/src/data-structures/graph/abstract-graph.ts +2 -2
  93. package/src/data-structures/hash/hash-map.ts +7 -7
  94. package/src/data-structures/linked-list/doubly-linked-list.ts +13 -13
  95. package/src/data-structures/linked-list/singly-linked-list.ts +17 -17
  96. package/src/interfaces/binary-tree.ts +4 -1
  97. package/src/types/data-structures/base/base.ts +1 -1
  98. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +2 -2
  99. package/src/types/data-structures/binary-tree/avl-tree.ts +2 -2
  100. package/src/types/data-structures/binary-tree/binary-tree.ts +2 -2
  101. package/src/types/data-structures/binary-tree/bst.ts +3 -3
  102. package/src/types/data-structures/binary-tree/rb-tree.ts +3 -3
  103. package/src/types/data-structures/binary-tree/tree-multi-map.ts +4 -4
  104. package/test/integration/index.html +3 -3
  105. package/test/performance/data-structures/binary-tree/binary-tree-overall.test.ts +3 -3
  106. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +12 -12
  107. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +10 -10
  108. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +10 -10
  109. package/test/unit/data-structures/binary-tree/bst.test.ts +11 -11
  110. package/test/unit/data-structures/binary-tree/data/cost-of-living-by-country.ts +259 -0
  111. package/test/unit/data-structures/binary-tree/overall.test.ts +2 -0
  112. package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +30 -10
  113. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +10 -10
  114. package/test/unit/data-structures/graph/directed-graph.test.ts +4 -4
  115. package/test/unit/data-structures/hash/hash-map.test.ts +12 -12
@@ -231,7 +231,7 @@ var dataStructureTyped = (() => {
231
231
  every(predicate, thisArg) {
232
232
  let index = 0;
233
233
  for (const item of this) {
234
- if (!predicate.call(thisArg, item[1], item[0], index++, this)) {
234
+ if (!predicate.call(thisArg, item[0], item[1], index++, this)) {
235
235
  return false;
236
236
  }
237
237
  }
@@ -255,7 +255,7 @@ var dataStructureTyped = (() => {
255
255
  some(predicate, thisArg) {
256
256
  let index = 0;
257
257
  for (const item of this) {
258
- if (predicate.call(thisArg, item[1], item[0], index++, this)) {
258
+ if (predicate.call(thisArg, item[0], item[1], index++, this)) {
259
259
  return true;
260
260
  }
261
261
  }
@@ -278,7 +278,7 @@ var dataStructureTyped = (() => {
278
278
  let index = 0;
279
279
  for (const item of this) {
280
280
  const [key, value] = item;
281
- callbackfn.call(thisArg, value, key, index++, this);
281
+ callbackfn.call(thisArg, key, value, index++, this);
282
282
  }
283
283
  }
284
284
  /**
@@ -302,7 +302,7 @@ var dataStructureTyped = (() => {
302
302
  let index = 0;
303
303
  for (const item of this) {
304
304
  const [key, value] = item;
305
- if (callbackfn.call(thisArg, value, key, index++, this)) return item;
305
+ if (callbackfn.call(thisArg, key, value, index++, this)) return item;
306
306
  }
307
307
  return;
308
308
  }
@@ -951,7 +951,7 @@ var dataStructureTyped = (() => {
951
951
  const resultMap = new _HashMap();
952
952
  let index = 0;
953
953
  for (const [key, value] of this) {
954
- resultMap.set(key, callbackfn.call(thisArg, value, key, index++, this));
954
+ resultMap.set(key, callbackfn.call(thisArg, key, value, index++, this));
955
955
  }
956
956
  return resultMap;
957
957
  }
@@ -975,7 +975,7 @@ var dataStructureTyped = (() => {
975
975
  const filteredMap = new _HashMap();
976
976
  let index = 0;
977
977
  for (const [key, value] of this) {
978
- if (predicate.call(thisArg, value, key, index++, this)) {
978
+ if (predicate.call(thisArg, key, value, index++, this)) {
979
979
  filteredMap.set(key, value);
980
980
  }
981
981
  }
@@ -1420,7 +1420,7 @@ var dataStructureTyped = (() => {
1420
1420
  const filteredMap = new _LinkedHashMap();
1421
1421
  let index = 0;
1422
1422
  for (const [key, value] of this) {
1423
- if (predicate.call(thisArg, value, key, index, this)) {
1423
+ if (predicate.call(thisArg, key, value, index, this)) {
1424
1424
  filteredMap.set(key, value);
1425
1425
  }
1426
1426
  index++;
@@ -1448,8 +1448,8 @@ var dataStructureTyped = (() => {
1448
1448
  const mappedMap = new _LinkedHashMap();
1449
1449
  let index = 0;
1450
1450
  for (const [key, value] of this) {
1451
- const newValue = callback.call(thisArg, value, key, index, this);
1452
- mappedMap.set(key, newValue);
1451
+ const [newKey, newValue] = callback.call(thisArg, key, value, index, this);
1452
+ mappedMap.set(newKey, newValue);
1453
1453
  index++;
1454
1454
  }
1455
1455
  return mappedMap;
@@ -1585,6 +1585,22 @@ var dataStructureTyped = (() => {
1585
1585
  get size() {
1586
1586
  return this._size;
1587
1587
  }
1588
+ /**
1589
+ * Time Complexity: O(n)
1590
+ * Space Complexity: O(n)
1591
+ *
1592
+ * The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given
1593
+ * array.
1594
+ * @param {E[]} data - The `data` parameter is an array of elements of type `E`.
1595
+ * @returns The `fromArray` function returns a `SinglyLinkedList` object.
1596
+ */
1597
+ static fromArray(data) {
1598
+ const singlyLinkedList = new _SinglyLinkedList();
1599
+ for (const item of data) {
1600
+ singlyLinkedList.push(item);
1601
+ }
1602
+ return singlyLinkedList;
1603
+ }
1588
1604
  /**
1589
1605
  * Time Complexity: O(1)
1590
1606
  * Space Complexity: O(1)
@@ -2170,22 +2186,6 @@ var dataStructureTyped = (() => {
2170
2186
  current = current.next;
2171
2187
  }
2172
2188
  }
2173
- /**
2174
- * Time Complexity: O(n)
2175
- * Space Complexity: O(n)
2176
- *
2177
- * The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given
2178
- * array.
2179
- * @param {E[]} data - The `data` parameter is an array of elements of type `E`.
2180
- * @returns The `fromArray` function returns a `SinglyLinkedList` object.
2181
- */
2182
- static fromArray(data) {
2183
- const singlyLinkedList = new _SinglyLinkedList();
2184
- for (const item of data) {
2185
- singlyLinkedList.push(item);
2186
- }
2187
- return singlyLinkedList;
2188
- }
2189
2189
  /**
2190
2190
  * The _isPredicate function in TypeScript checks if the input is a function that takes a
2191
2191
  * SinglyLinkedListNode as an argument and returns a boolean.
@@ -2356,6 +2356,18 @@ var dataStructureTyped = (() => {
2356
2356
  var _a;
2357
2357
  return (_a = this.tail) == null ? void 0 : _a.value;
2358
2358
  }
2359
+ /**
2360
+ * Time Complexity: O(n)
2361
+ * Space Complexity: O(n)
2362
+ *
2363
+ * The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
2364
+ * given array.
2365
+ * @param {E[]} data - The `data` parameter is an array of elements of type `E`.
2366
+ * @returns The `fromArray` function returns a DoublyLinkedList object.
2367
+ */
2368
+ static fromArray(data) {
2369
+ return new _DoublyLinkedList(data);
2370
+ }
2359
2371
  /**
2360
2372
  * Time Complexity: O(1)
2361
2373
  * Space Complexity: O(1)
@@ -2962,18 +2974,6 @@ var dataStructureTyped = (() => {
2962
2974
  }
2963
2975
  return count;
2964
2976
  }
2965
- /**
2966
- * Time Complexity: O(n)
2967
- * Space Complexity: O(n)
2968
- *
2969
- * The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
2970
- * given array.
2971
- * @param {E[]} data - The `data` parameter is an array of elements of type `E`.
2972
- * @returns The `fromArray` function returns a DoublyLinkedList object.
2973
- */
2974
- static fromArray(data) {
2975
- return new _DoublyLinkedList(data);
2976
- }
2977
2977
  /**
2978
2978
  * The function returns an iterator that iterates over the values of a linked list.
2979
2979
  */
@@ -6192,7 +6192,7 @@ var dataStructureTyped = (() => {
6192
6192
  const filtered = [];
6193
6193
  let index = 0;
6194
6194
  for (const [key, value] of this) {
6195
- if (predicate.call(thisArg, value, key, index, this)) {
6195
+ if (predicate.call(thisArg, key, value, index, this)) {
6196
6196
  filtered.push([key, value]);
6197
6197
  }
6198
6198
  index++;
@@ -6216,7 +6216,7 @@ var dataStructureTyped = (() => {
6216
6216
  const mapped = [];
6217
6217
  let index = 0;
6218
6218
  for (const [key, value] of this) {
6219
- mapped.push(callback.call(thisArg, value, key, index, this));
6219
+ mapped.push(callback.call(thisArg, key, value, index, this));
6220
6220
  index++;
6221
6221
  }
6222
6222
  return mapped;
@@ -7389,6 +7389,9 @@ var dataStructureTyped = (() => {
7389
7389
  __publicField(this, "parent");
7390
7390
  __publicField(this, "_left");
7391
7391
  __publicField(this, "_right");
7392
+ __publicField(this, "_height", 0);
7393
+ __publicField(this, "_color", "BLACK");
7394
+ __publicField(this, "_count", 1);
7392
7395
  this.key = key;
7393
7396
  this.value = value;
7394
7397
  }
@@ -7410,6 +7413,24 @@ var dataStructureTyped = (() => {
7410
7413
  }
7411
7414
  this._right = v;
7412
7415
  }
7416
+ get height() {
7417
+ return this._height;
7418
+ }
7419
+ set height(value) {
7420
+ this._height = value;
7421
+ }
7422
+ get color() {
7423
+ return this._color;
7424
+ }
7425
+ set color(value) {
7426
+ this._color = value;
7427
+ }
7428
+ get count() {
7429
+ return this._count;
7430
+ }
7431
+ set count(value) {
7432
+ this._count = value;
7433
+ }
7413
7434
  get familyPosition() {
7414
7435
  const that = this;
7415
7436
  if (!this.parent) {
@@ -7471,6 +7492,9 @@ var dataStructureTyped = (() => {
7471
7492
  return this._toEntryFn;
7472
7493
  }
7473
7494
  /**
7495
+ * Time Complexity: O(1)
7496
+ * Space Complexity: O(1)
7497
+ *
7474
7498
  * The function creates a new binary tree node with a specified key and optional value.
7475
7499
  * @param {K} key - The `key` parameter is the key of the node being created in the binary tree.
7476
7500
  * @param {V} [value] - The `value` parameter in the `createNode` function is optional, meaning it is
@@ -8733,7 +8757,7 @@ var dataStructureTyped = (() => {
8733
8757
  const newTree = this.createTree();
8734
8758
  let index = 0;
8735
8759
  for (const [key, value] of this) {
8736
- if (predicate.call(thisArg, value, key, index++, this)) {
8760
+ if (predicate.call(thisArg, key, value, index++, this)) {
8737
8761
  newTree.add([key, value]);
8738
8762
  }
8739
8763
  }
@@ -8743,34 +8767,29 @@ var dataStructureTyped = (() => {
8743
8767
  * Time Complexity: O(n)
8744
8768
  * Space Complexity: O(n)
8745
8769
  *
8746
- * The `map` function iterates over key-value pairs in a tree data structure, applies a callback
8747
- * function to each value, and returns a new tree with the updated values.
8748
- * @param callback - The `callback` parameter in the `map` method is a function that will be called
8749
- * on each entry in the tree. It takes four arguments:
8750
- * @param {any} [thisArg] - The `thisArg` parameter in the `map` function is an optional parameter
8751
- * that specifies the value to be passed as `this` when executing the callback function. If provided,
8752
- * the `thisArg` value will be used as the `this` value within the callback function. If `thisArg
8753
- * @returns The `map` method is returning a new tree with the entries modified by the provided
8754
- * callback function. Each entry in the original tree is passed to the callback function, and the
8755
- * result of the callback function is added to the new tree.
8756
- */
8757
- map(callback, thisArg) {
8758
- const newTree = this.createTree();
8770
+ * The `map` function in TypeScript creates a new BinaryTree by applying a callback function to each
8771
+ * entry in the original BinaryTree.
8772
+ * @param callback - A function that will be called for each entry in the current binary tree. It
8773
+ * takes the key, value (which can be undefined), and an array containing the mapped key and value as
8774
+ * arguments.
8775
+ * @param [options] - The `options` parameter in the `map` method is of type `BinaryTreeOptions<MK,
8776
+ * MV, MR>`. It is an optional parameter that allows you to specify additional options for the binary
8777
+ * tree being created during the mapping process. These options could include things like custom
8778
+ * comparators, initial
8779
+ * @param {any} [thisArg] - The `thisArg` parameter in the `map` method is used to specify the value
8780
+ * of `this` when executing the `callback` function. It allows you to set the context (value of
8781
+ * `this`) within the callback function. If `thisArg` is provided, it will be passed
8782
+ * @returns The `map` function is returning a new `BinaryTree` instance filled with entries that are
8783
+ * the result of applying the provided `callback` function to each entry in the original tree.
8784
+ */
8785
+ map(callback, options, thisArg) {
8786
+ const newTree = new _BinaryTree([], options);
8759
8787
  let index = 0;
8760
8788
  for (const [key, value] of this) {
8761
- newTree.add([key, callback.call(thisArg, value, key, index++, this)]);
8789
+ newTree.add(callback.call(thisArg, key, value, index++, this));
8762
8790
  }
8763
8791
  return newTree;
8764
8792
  }
8765
- // // TODO Type error, need to return a TREE<NV> that is a value type only for callback function.
8766
- // // map<NV>(callback: (entry: [K, V | undefined], tree: this) => NV) {
8767
- // // const newTree = this.createTree();
8768
- // // for (const [key, value] of this) {
8769
- // // newTree.add(key, callback([key, value], this));
8770
- // // }
8771
- // // return newTree;
8772
- // // }
8773
- //
8774
8793
  /**
8775
8794
  * Time Complexity: O(n)
8776
8795
  * Space Complexity: O(n)
@@ -8801,7 +8820,7 @@ var dataStructureTyped = (() => {
8801
8820
  if (opts.isShowRedBlackNIL) output += `S for Sentinel Node(NIL)
8802
8821
  `;
8803
8822
  const display = (root) => {
8804
- const [lines, , ,] = this._displayAux(root, opts);
8823
+ const [lines, ,] = this._displayAux(root, opts);
8805
8824
  let paragraph = "";
8806
8825
  for (const line of lines) {
8807
8826
  paragraph += line + "\n";
@@ -9301,22 +9320,22 @@ var dataStructureTyped = (() => {
9301
9320
  if (a < b) return -1;
9302
9321
  return 0;
9303
9322
  }
9304
- if (this._extractComparable) {
9305
- if (this._extractComparable(a) > this._extractComparable(b)) return 1;
9306
- if (this._extractComparable(a) < this._extractComparable(b)) return -1;
9323
+ if (this._specifyComparable) {
9324
+ if (this._specifyComparable(a) > this._specifyComparable(b)) return 1;
9325
+ if (this._specifyComparable(a) < this._specifyComparable(b)) return -1;
9307
9326
  return 0;
9308
9327
  }
9309
9328
  if (typeof a === "object" || typeof b === "object") {
9310
9329
  throw TypeError(
9311
- `When comparing object types, a custom extractComparable must be defined in the constructor's options parameter.`
9330
+ `When comparing object types, a custom specifyComparable must be defined in the constructor's options parameter.`
9312
9331
  );
9313
9332
  }
9314
9333
  return 0;
9315
9334
  });
9316
- __publicField(this, "_extractComparable");
9335
+ __publicField(this, "_specifyComparable");
9317
9336
  if (options) {
9318
- const { extractComparable, isReverse } = options;
9319
- if (typeof extractComparable === "function") this._extractComparable = extractComparable;
9337
+ const { specifyComparable, isReverse } = options;
9338
+ if (typeof specifyComparable === "function") this._specifyComparable = specifyComparable;
9320
9339
  if (isReverse !== void 0) this._isReverse = isReverse;
9321
9340
  }
9322
9341
  if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
@@ -9358,7 +9377,7 @@ var dataStructureTyped = (() => {
9358
9377
  return new _BST([], __spreadValues({
9359
9378
  iterationType: this.iterationType,
9360
9379
  isMapMode: this._isMapMode,
9361
- extractComparable: this._extractComparable,
9380
+ specifyComparable: this._specifyComparable,
9362
9381
  toEntryFn: this._toEntryFn,
9363
9382
  isReverse: this._isReverse
9364
9383
  }, options));
@@ -9415,7 +9434,7 @@ var dataStructureTyped = (() => {
9415
9434
  * this._DEFAULT_COMPARATOR`.
9416
9435
  */
9417
9436
  isKey(key) {
9418
- return isComparable(key, this._extractComparable !== void 0);
9437
+ return isComparable(key, this._specifyComparable !== void 0);
9419
9438
  }
9420
9439
  /**
9421
9440
  * Time Complexity: O(log n)
@@ -9450,7 +9469,7 @@ var dataStructureTyped = (() => {
9450
9469
  this._size++;
9451
9470
  return true;
9452
9471
  }
9453
- current = current.left;
9472
+ if (current.left !== null) current = current.left;
9454
9473
  } else {
9455
9474
  if (current.right === void 0) {
9456
9475
  current.right = newNode;
@@ -9458,7 +9477,7 @@ var dataStructureTyped = (() => {
9458
9477
  this._size++;
9459
9478
  return true;
9460
9479
  }
9461
- current = current.right;
9480
+ if (current.right !== null) current = current.right;
9462
9481
  }
9463
9482
  }
9464
9483
  return false;
@@ -9557,18 +9576,6 @@ var dataStructureTyped = (() => {
9557
9576
  }
9558
9577
  return inserted;
9559
9578
  }
9560
- /**
9561
- * Time Complexity: O(n)
9562
- * Space Complexity: O(1)
9563
- *
9564
- * The `merge` function overrides the base class method by adding elements from another
9565
- * binary search tree.
9566
- * @param anotherTree - `anotherTree` is an instance of a Binary Search Tree (BST) with key type `K`,
9567
- * value type `V`, return type `R`, node type `NODE`, and tree type `TREE`.
9568
- */
9569
- merge(anotherTree) {
9570
- this.addMany(anotherTree, [], false);
9571
- }
9572
9579
  /**
9573
9580
  * Time Complexity: O(log n)
9574
9581
  * Space Complexity: O(k + log n)
@@ -9915,7 +9922,7 @@ var dataStructureTyped = (() => {
9915
9922
  while (stack.length > 0 || node) {
9916
9923
  if (node) {
9917
9924
  stack.push(node);
9918
- node = node.left;
9925
+ if (node.left !== null) node = node.left;
9919
9926
  } else {
9920
9927
  node = stack[stack.length - 1];
9921
9928
  if (!node.right || last === node.right) {
@@ -9942,12 +9949,12 @@ var dataStructureTyped = (() => {
9942
9949
  return this._comparator;
9943
9950
  }
9944
9951
  /**
9945
- * This function returns the value of the `_extractComparable` property.
9946
- * @returns The method `extractComparable()` is being returned, which is a getter method for the
9947
- * `_extractComparable` property.
9952
+ * This function returns the value of the `_specifyComparable` property.
9953
+ * @returns The method `specifyComparable()` is being returned, which is a getter method for the
9954
+ * `_specifyComparable` property.
9948
9955
  */
9949
- get extractComparable() {
9950
- return this._extractComparable;
9956
+ get specifyComparable() {
9957
+ return this._specifyComparable;
9951
9958
  }
9952
9959
  /**
9953
9960
  * The function sets the root of a tree-like structure and updates the parent property of the new
@@ -9963,6 +9970,14 @@ var dataStructureTyped = (() => {
9963
9970
  _compare(a, b) {
9964
9971
  return this._isReverse ? -this._comparator(a, b) : this._comparator(a, b);
9965
9972
  }
9973
+ map(callback, options, thisArg) {
9974
+ const newTree = new _BST([], options);
9975
+ let index = 0;
9976
+ for (const [key, value] of this) {
9977
+ newTree.add(callback.call(thisArg, key, value, index++, this));
9978
+ }
9979
+ return newTree;
9980
+ }
9966
9981
  };
9967
9982
 
9968
9983
  // src/data-structures/binary-tree/binary-indexed-tree.ts
@@ -10540,23 +10555,6 @@ var dataStructureTyped = (() => {
10540
10555
  */
10541
10556
  constructor(key, value) {
10542
10557
  super(key, value);
10543
- __publicField(this, "_height");
10544
- this._height = 0;
10545
- }
10546
- /**
10547
- * The function returns the value of the height property.
10548
- * @returns The height of the object.
10549
- */
10550
- get height() {
10551
- return this._height;
10552
- }
10553
- /**
10554
- * The above function sets the value of the height property.
10555
- * @param {number} value - The value parameter is a number that represents the new height value to be
10556
- * set.
10557
- */
10558
- set height(value) {
10559
- this._height = value;
10560
10558
  }
10561
10559
  };
10562
10560
  var AVLTree = class _AVLTree extends BST {
@@ -10598,7 +10596,7 @@ var dataStructureTyped = (() => {
10598
10596
  return new _AVLTree([], __spreadValues({
10599
10597
  iterationType: this.iterationType,
10600
10598
  isMapMode: this._isMapMode,
10601
- extractComparable: this._extractComparable,
10599
+ specifyComparable: this._specifyComparable,
10602
10600
  toEntryFn: this._toEntryFn,
10603
10601
  isReverse: this._isReverse
10604
10602
  }, options));
@@ -10654,6 +10652,14 @@ var dataStructureTyped = (() => {
10654
10652
  }
10655
10653
  return deletedResults;
10656
10654
  }
10655
+ map(callback, options, thisArg) {
10656
+ const newTree = new _AVLTree([], options);
10657
+ let index = 0;
10658
+ for (const [key, value] of this) {
10659
+ newTree.add(callback.call(thisArg, key, value, index++, this));
10660
+ }
10661
+ return newTree;
10662
+ }
10657
10663
  /**
10658
10664
  * Time Complexity: O(1)
10659
10665
  * Space Complexity: O(1)
@@ -10729,7 +10735,7 @@ var dataStructureTyped = (() => {
10729
10735
  _balanceLL(A) {
10730
10736
  const parentOfA = A.parent;
10731
10737
  const B = A.left;
10732
- A.parent = B;
10738
+ if (B !== null) A.parent = B;
10733
10739
  if (B && B.right) {
10734
10740
  B.right.parent = A;
10735
10741
  }
@@ -10764,11 +10770,11 @@ var dataStructureTyped = (() => {
10764
10770
  if (B) {
10765
10771
  C = B.right;
10766
10772
  }
10767
- if (A) A.parent = C;
10768
- if (B) B.parent = C;
10773
+ if (A && C !== null) A.parent = C;
10774
+ if (B && C !== null) B.parent = C;
10769
10775
  if (C) {
10770
10776
  if (C.left) {
10771
- C.left.parent = B;
10777
+ if (B !== null) C.left.parent = B;
10772
10778
  }
10773
10779
  if (C.right) {
10774
10780
  C.right.parent = A;
@@ -10806,7 +10812,7 @@ var dataStructureTyped = (() => {
10806
10812
  _balanceRR(A) {
10807
10813
  const parentOfA = A.parent;
10808
10814
  const B = A.right;
10809
- A.parent = B;
10815
+ if (B !== null) A.parent = B;
10810
10816
  if (B) {
10811
10817
  if (B.left) {
10812
10818
  B.left.parent = A;
@@ -10845,14 +10851,14 @@ var dataStructureTyped = (() => {
10845
10851
  if (B) {
10846
10852
  C = B.left;
10847
10853
  }
10848
- A.parent = C;
10849
- if (B) B.parent = C;
10854
+ if (C !== null) A.parent = C;
10855
+ if (B && C !== null) B.parent = C;
10850
10856
  if (C) {
10851
10857
  if (C.left) {
10852
10858
  C.left.parent = A;
10853
10859
  }
10854
10860
  if (C.right) {
10855
- C.right.parent = B;
10861
+ if (B !== null) C.right.parent = B;
10856
10862
  }
10857
10863
  C.parent = parentOfA;
10858
10864
  }
@@ -10947,23 +10953,8 @@ var dataStructureTyped = (() => {
10947
10953
  */
10948
10954
  constructor(key, value, color = "BLACK") {
10949
10955
  super(key, value);
10950
- __publicField(this, "_color");
10951
10956
  this._color = color;
10952
10957
  }
10953
- /**
10954
- * The function returns the color value of a variable.
10955
- * @returns The color value stored in the private variable `_color`.
10956
- */
10957
- get color() {
10958
- return this._color;
10959
- }
10960
- /**
10961
- * The function sets the color property to the specified value.
10962
- * @param {RBTNColor} value - The value parameter is of type RBTNColor.
10963
- */
10964
- set color(value) {
10965
- this._color = value;
10966
- }
10967
10958
  };
10968
10959
  var RedBlackTree = class _RedBlackTree extends BST {
10969
10960
  /**
@@ -10972,7 +10963,7 @@ var dataStructureTyped = (() => {
10972
10963
  * iterable object that can contain either keys, nodes, entries, or raw elements. It is used to
10973
10964
  * initialize the RBTree with the provided elements.
10974
10965
  * @param [options] - The `options` parameter is an optional object that can be passed to the
10975
- * constructor. It is of type `RBTreeOptions<K, V, R>`. This object can contain various options for
10966
+ * constructor. It is of type `RedBlackTreeOptions<K, V, R>`. This object can contain various options for
10976
10967
  * configuring the behavior of the Red-Black Tree. The specific properties and their meanings would
10977
10968
  * depend on the implementation
10978
10969
  */
@@ -11018,7 +11009,7 @@ var dataStructureTyped = (() => {
11018
11009
  return new _RedBlackTree([], __spreadValues({
11019
11010
  iterationType: this.iterationType,
11020
11011
  isMapMode: this._isMapMode,
11021
- extractComparable: this._extractComparable,
11012
+ specifyComparable: this._specifyComparable,
11022
11013
  toEntryFn: this._toEntryFn
11023
11014
  }, options));
11024
11015
  }
@@ -11035,41 +11026,6 @@ var dataStructureTyped = (() => {
11035
11026
  isNode(keyNodeEntryOrRaw) {
11036
11027
  return keyNodeEntryOrRaw instanceof RedBlackTreeNode;
11037
11028
  }
11038
- // /**
11039
- // * Time Complexity: O(1)
11040
- // * Space Complexity: O(1)
11041
- // */
11042
- //
11043
- // /**
11044
- // * Time Complexity: O(1)
11045
- // * Space Complexity: O(1)
11046
- // *
11047
- // * The function `keyValueNodeEntryRawToNodeAndValue` takes a key, value, or entry and returns a node if it is
11048
- // * valid, otherwise it returns undefined.
11049
- // * @param {BTNRep<K, V, NODE>} keyNodeEntryOrRaw - The key, value, or entry to convert.
11050
- // * @param {V} [value] - The value associated with the key (if `keyNodeEntryOrRaw` is a key).
11051
- // * @returns {NODE | undefined} - The corresponding Red-Black Tree node, or `undefined` if conversion fails.
11052
- // */
11053
- // override keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R, value?: V): NODE | undefined {
11054
- //
11055
- // if (keyNodeEntryOrRaw === null || keyNodeEntryOrRaw === undefined) return;
11056
- // if (this.isNode(keyNodeEntryOrRaw)) return keyNodeEntryOrRaw;
11057
- //
11058
- // if (this._toEntryFn) {
11059
- // const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw as R);
11060
- // if (this.isKey(key)) return this.createNode(key, value ?? entryValue, 'RED');
11061
- // }
11062
- //
11063
- // if (this.isEntry(keyNodeEntryOrRaw)) {
11064
- // const [key, value] = keyNodeEntryOrRaw;
11065
- // if (key === undefined || key === null) return;
11066
- // else return this.createNode(key, value, 'RED');
11067
- // }
11068
- //
11069
- // if (this.isKey(keyNodeEntryOrRaw)) return this.createNode(keyNodeEntryOrRaw, value, 'RED');
11070
- //
11071
- // return ;
11072
- // }
11073
11029
  /**
11074
11030
  * Time Complexity: O(1)
11075
11031
  * Space Complexity: O(1)
@@ -11142,8 +11098,10 @@ var dataStructureTyped = (() => {
11142
11098
  let originalColor = nodeToDelete.color;
11143
11099
  let replacementNode;
11144
11100
  if (!this.isRealNode(nodeToDelete.left)) {
11145
- replacementNode = nodeToDelete.right;
11146
- this._transplant(nodeToDelete, nodeToDelete.right);
11101
+ if (nodeToDelete.right !== null) {
11102
+ replacementNode = nodeToDelete.right;
11103
+ this._transplant(nodeToDelete, nodeToDelete.right);
11104
+ }
11147
11105
  } else if (!this.isRealNode(nodeToDelete.right)) {
11148
11106
  replacementNode = nodeToDelete.left;
11149
11107
  this._transplant(nodeToDelete, nodeToDelete.left);
@@ -11151,14 +11109,16 @@ var dataStructureTyped = (() => {
11151
11109
  const successor = this.getLeftMost((node) => node, nodeToDelete.right);
11152
11110
  if (successor) {
11153
11111
  originalColor = successor.color;
11154
- replacementNode = successor.right;
11112
+ if (successor.right !== null) replacementNode = successor.right;
11155
11113
  if (successor.parent === nodeToDelete) {
11156
11114
  if (this.isRealNode(replacementNode)) {
11157
11115
  replacementNode.parent = successor;
11158
11116
  }
11159
11117
  } else {
11160
- this._transplant(successor, successor.right);
11161
- successor.right = nodeToDelete.right;
11118
+ if (successor.right !== null) {
11119
+ this._transplant(successor, successor.right);
11120
+ successor.right = nodeToDelete.right;
11121
+ }
11162
11122
  if (this.isRealNode(successor.right)) {
11163
11123
  successor.right.parent = successor;
11164
11124
  }
@@ -11240,7 +11200,7 @@ var dataStructureTyped = (() => {
11240
11200
  node.parent = parent;
11241
11201
  if (!parent) {
11242
11202
  this._setRoot(node);
11243
- } else if (node.key < parent.key) {
11203
+ } else if (this._compare(node.key, parent.key) < 0) {
11244
11204
  parent.left = node;
11245
11205
  } else {
11246
11206
  parent.right = node;
@@ -11281,7 +11241,7 @@ var dataStructureTyped = (() => {
11281
11241
  * structure. It can either be a valid node or `undefined`.
11282
11242
  */
11283
11243
  _insertFixup(z) {
11284
- var _a, _b, _c, _d;
11244
+ var _a, _b, _c, _d, _e;
11285
11245
  while (((_a = z == null ? void 0 : z.parent) == null ? void 0 : _a.color) === "RED") {
11286
11246
  if (z.parent === ((_b = z.parent.parent) == null ? void 0 : _b.left)) {
11287
11247
  const y = z.parent.parent.right;
@@ -11302,7 +11262,7 @@ var dataStructureTyped = (() => {
11302
11262
  }
11303
11263
  }
11304
11264
  } else {
11305
- const y = (_d = (_c = z == null ? void 0 : z.parent) == null ? void 0 : _c.parent) == null ? void 0 : _d.left;
11265
+ const y = (_e = (_d = (_c = z == null ? void 0 : z.parent) == null ? void 0 : _c.parent) == null ? void 0 : _d.left) != null ? _e : void 0;
11306
11266
  if ((y == null ? void 0 : y.color) === "RED") {
11307
11267
  z.parent.color = "BLACK";
11308
11268
  y.color = "BLACK";
@@ -11447,6 +11407,34 @@ var dataStructureTyped = (() => {
11447
11407
  x.right = y;
11448
11408
  y.parent = x;
11449
11409
  }
11410
+ /**
11411
+ * Time Complexity: O(n)
11412
+ * Space Complexity: O(n)
11413
+ *
11414
+ * The `map` function in TypeScript overrides the default behavior to create a new Red-Black Tree by
11415
+ * applying a callback to each entry in the original tree.
11416
+ * @param callback - A function that will be called for each entry in the tree, with parameters
11417
+ * representing the key, value, index, and the tree itself. It should return an entry for the new
11418
+ * tree.
11419
+ * @param [options] - The `options` parameter in the `map` method is of type `RedBlackTreeOptions<MK, MV,
11420
+ * MR>`. This parameter allows you to specify additional options or configurations for the Red-Black
11421
+ * Tree that will be created during the mapping process. These options could include things like
11422
+ * custom comparators
11423
+ * @param {any} [thisArg] - The `thisArg` parameter in the `override map` function is used to specify
11424
+ * the value of `this` when executing the `callback` function. It allows you to set the context
11425
+ * (value of `this`) for the callback function. This can be useful when you want to access properties
11426
+ * or
11427
+ * @returns A new Red-Black Tree is being returned, where each entry has been transformed using the
11428
+ * provided callback function.
11429
+ */
11430
+ map(callback, options, thisArg) {
11431
+ const newTree = new _RedBlackTree([], options);
11432
+ let index = 0;
11433
+ for (const [key, value] of this) {
11434
+ newTree.add(callback.call(thisArg, key, value, index++, this));
11435
+ }
11436
+ return newTree;
11437
+ }
11450
11438
  };
11451
11439
 
11452
11440
  // src/data-structures/binary-tree/avl-tree-multi-map.ts
@@ -11463,24 +11451,8 @@ var dataStructureTyped = (() => {
11463
11451
  */
11464
11452
  constructor(key, value, count = 1) {
11465
11453
  super(key, value);
11466
- __publicField(this, "_count", 1);
11467
11454
  this.count = count;
11468
11455
  }
11469
- /**
11470
- * The function returns the value of the protected variable _count.
11471
- * @returns The count property of the object, which is of type number.
11472
- */
11473
- get count() {
11474
- return this._count;
11475
- }
11476
- /**
11477
- * The above function sets the value of the count property.
11478
- * @param {number} value - The value parameter is of type number, which means it can accept any
11479
- * numeric value.
11480
- */
11481
- set count(value) {
11482
- this._count = value;
11483
- }
11484
11456
  };
11485
11457
  var AVLTreeMultiMap = class _AVLTreeMultiMap extends AVLTree {
11486
11458
  /**
@@ -11542,7 +11514,7 @@ var dataStructureTyped = (() => {
11542
11514
  return new _AVLTreeMultiMap([], __spreadValues({
11543
11515
  iterationType: this.iterationType,
11544
11516
  isMapMode: this._isMapMode,
11545
- extractComparable: this._extractComparable,
11517
+ specifyComparable: this._specifyComparable,
11546
11518
  toEntryFn: this._toEntryFn,
11547
11519
  isReverse: this._isReverse
11548
11520
  }, options));
@@ -11557,35 +11529,6 @@ var dataStructureTyped = (() => {
11557
11529
  isNode(keyNodeEntryOrRaw) {
11558
11530
  return keyNodeEntryOrRaw instanceof AVLTreeMultiMapNode;
11559
11531
  }
11560
- /**
11561
- * The function `keyValueNodeEntryRawToNodeAndValue` converts a key, value, entry, or raw element into
11562
- * a node object.
11563
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The
11564
- * `keyNodeEntryOrRaw` parameter can be of type `R` or `BTNRep<K, V, NODE>`.
11565
- * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
11566
- * `override` function. It represents the value associated with the key in the data structure. If no
11567
- * value is provided, it will default to `undefined`.
11568
- * @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
11569
- * times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
11570
- * @returns either a NODE object or undefined.
11571
- */
11572
- _keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count = 1) {
11573
- if (keyNodeEntryOrRaw === void 0 || keyNodeEntryOrRaw === null) return [void 0, void 0];
11574
- if (this.isNode(keyNodeEntryOrRaw)) return [keyNodeEntryOrRaw, value];
11575
- if (this.isEntry(keyNodeEntryOrRaw)) {
11576
- const [key, entryValue] = keyNodeEntryOrRaw;
11577
- if (key === void 0 || key === null) return [void 0, void 0];
11578
- const finalValue = value != null ? value : entryValue;
11579
- return [this.createNode(key, finalValue, count), finalValue];
11580
- }
11581
- if (this.isRaw(keyNodeEntryOrRaw)) {
11582
- const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw);
11583
- const finalValue = value != null ? value : entryValue;
11584
- if (this.isKey(key)) return [this.createNode(key, finalValue, count), finalValue];
11585
- }
11586
- if (this.isKey(keyNodeEntryOrRaw)) return [this.createNode(keyNodeEntryOrRaw, value, count), value];
11587
- return [void 0, void 0];
11588
- }
11589
11532
  /**
11590
11533
  * Time Complexity: O(log n)
11591
11534
  * Space Complexity: O(1)
@@ -11646,7 +11589,7 @@ var dataStructureTyped = (() => {
11646
11589
  } else {
11647
11590
  if (!curr.left) {
11648
11591
  if (!parent) {
11649
- if (curr.right !== void 0) this._setRoot(curr.right);
11592
+ if (curr.right !== void 0 && curr.right !== null) this._setRoot(curr.right);
11650
11593
  } else {
11651
11594
  const { familyPosition: fp } = curr;
11652
11595
  if (fp === "LEFT" || fp === "ROOT_LEFT") {
@@ -11752,6 +11695,61 @@ var dataStructureTyped = (() => {
11752
11695
  if (this._isMapMode) cloned._store = this._store;
11753
11696
  return cloned;
11754
11697
  }
11698
+ /**
11699
+ * The `map` function in TypeScript overrides the default behavior to create a new AVLTreeMultiMap
11700
+ * with modified entries based on a provided callback.
11701
+ * @param callback - The `callback` parameter is a function that will be called for each entry in the
11702
+ * AVLTreeMultiMap. It takes four arguments:
11703
+ * @param [options] - The `options` parameter in the `override map` function is of type
11704
+ * `AVLTreeMultiMapOptions<MK, MV, MR>`. This parameter allows you to provide additional
11705
+ * configuration options when creating a new `AVLTreeMultiMap` instance within the `map` function.
11706
+ * These options
11707
+ * @param {any} [thisArg] - The `thisArg` parameter in the `override map` function is used to specify
11708
+ * the value of `this` when executing the `callback` function. It allows you to set the context
11709
+ * (value of `this`) for the callback function. This can be useful when you want to access properties
11710
+ * or
11711
+ * @returns The `map` method is returning a new `AVLTreeMultiMap` instance with the entries
11712
+ * transformed by the provided `callback` function. Each entry in the original tree is passed to the
11713
+ * `callback` function along with the index and the original tree itself. The transformed entries are
11714
+ * then added to the new `AVLTreeMultiMap` instance, which is returned at the end.
11715
+ */
11716
+ map(callback, options, thisArg) {
11717
+ const newTree = new _AVLTreeMultiMap([], options);
11718
+ let index = 0;
11719
+ for (const [key, value] of this) {
11720
+ newTree.add(callback.call(thisArg, key, value, index++, this));
11721
+ }
11722
+ return newTree;
11723
+ }
11724
+ /**
11725
+ * The function `keyValueNodeEntryRawToNodeAndValue` converts a key, value, entry, or raw element into
11726
+ * a node object.
11727
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The
11728
+ * `keyNodeEntryOrRaw` parameter can be of type `R` or `BTNRep<K, V, NODE>`.
11729
+ * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
11730
+ * `override` function. It represents the value associated with the key in the data structure. If no
11731
+ * value is provided, it will default to `undefined`.
11732
+ * @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
11733
+ * times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
11734
+ * @returns either a NODE object or undefined.
11735
+ */
11736
+ _keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count = 1) {
11737
+ if (keyNodeEntryOrRaw === void 0 || keyNodeEntryOrRaw === null) return [void 0, void 0];
11738
+ if (this.isNode(keyNodeEntryOrRaw)) return [keyNodeEntryOrRaw, value];
11739
+ if (this.isEntry(keyNodeEntryOrRaw)) {
11740
+ const [key, entryValue] = keyNodeEntryOrRaw;
11741
+ if (key === void 0 || key === null) return [void 0, void 0];
11742
+ const finalValue = value != null ? value : entryValue;
11743
+ return [this.createNode(key, finalValue, count), finalValue];
11744
+ }
11745
+ if (this.isRaw(keyNodeEntryOrRaw)) {
11746
+ const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw);
11747
+ const finalValue = value != null ? value : entryValue;
11748
+ if (this.isKey(key)) return [this.createNode(key, finalValue, count), finalValue];
11749
+ }
11750
+ if (this.isKey(keyNodeEntryOrRaw)) return [this.createNode(keyNodeEntryOrRaw, value, count), value];
11751
+ return [void 0, void 0];
11752
+ }
11755
11753
  /**
11756
11754
  * Time Complexity: O(1)
11757
11755
  * Space Complexity: O(1)
@@ -11819,24 +11817,8 @@ var dataStructureTyped = (() => {
11819
11817
  */
11820
11818
  constructor(key, value, count = 1, color = "BLACK") {
11821
11819
  super(key, value, color);
11822
- __publicField(this, "_count", 1);
11823
11820
  this.count = count;
11824
11821
  }
11825
- /**
11826
- * The function returns the value of the private variable _count.
11827
- * @returns The count property of the object, which is of type number.
11828
- */
11829
- get count() {
11830
- return this._count;
11831
- }
11832
- /**
11833
- * The above function sets the value of the count property.
11834
- * @param {number} value - The value parameter is of type number, which means it can accept any
11835
- * numeric value.
11836
- */
11837
- set count(value) {
11838
- this._count = value;
11839
- }
11840
11822
  };
11841
11823
  var TreeMultiMap = class _TreeMultiMap extends RedBlackTree {
11842
11824
  /**
@@ -11902,7 +11884,7 @@ var dataStructureTyped = (() => {
11902
11884
  return new _TreeMultiMap([], __spreadValues({
11903
11885
  iterationType: this.iterationType,
11904
11886
  isMapMode: this._isMapMode,
11905
- extractComparable: this._extractComparable,
11887
+ specifyComparable: this._specifyComparable,
11906
11888
  toEntryFn: this._toEntryFn
11907
11889
  }, options));
11908
11890
  }
@@ -11999,10 +11981,12 @@ var dataStructureTyped = (() => {
11999
11981
  let originalColor = nodeToDelete.color;
12000
11982
  let replacementNode;
12001
11983
  if (!this.isRealNode(nodeToDelete.left)) {
12002
- replacementNode = nodeToDelete.right;
11984
+ if (nodeToDelete.right !== null) replacementNode = nodeToDelete.right;
12003
11985
  if (ignoreCount || nodeToDelete.count <= 1) {
12004
- this._transplant(nodeToDelete, nodeToDelete.right);
12005
- this._count -= nodeToDelete.count;
11986
+ if (nodeToDelete.right !== null) {
11987
+ this._transplant(nodeToDelete, nodeToDelete.right);
11988
+ this._count -= nodeToDelete.count;
11989
+ }
12006
11990
  } else {
12007
11991
  nodeToDelete.count--;
12008
11992
  this._count--;
@@ -12024,15 +12008,17 @@ var dataStructureTyped = (() => {
12024
12008
  const successor = this.getLeftMost((node) => node, nodeToDelete.right);
12025
12009
  if (successor) {
12026
12010
  originalColor = successor.color;
12027
- replacementNode = successor.right;
12011
+ if (successor.right !== null) replacementNode = successor.right;
12028
12012
  if (successor.parent === nodeToDelete) {
12029
12013
  if (this.isRealNode(replacementNode)) {
12030
12014
  replacementNode.parent = successor;
12031
12015
  }
12032
12016
  } else {
12033
12017
  if (ignoreCount || nodeToDelete.count <= 1) {
12034
- this._transplant(successor, successor.right);
12035
- this._count -= nodeToDelete.count;
12018
+ if (successor.right !== null) {
12019
+ this._transplant(successor, successor.right);
12020
+ this._count -= nodeToDelete.count;
12021
+ }
12036
12022
  } else {
12037
12023
  nodeToDelete.count--;
12038
12024
  this._count--;
@@ -12189,6 +12175,29 @@ var dataStructureTyped = (() => {
12189
12175
  newNode.count = oldNode.count + newNode.count;
12190
12176
  return super._replaceNode(oldNode, newNode);
12191
12177
  }
12178
+ /**
12179
+ * The `map` function in TypeScript overrides the default behavior to create a new TreeMultiMap with
12180
+ * modified entries based on a provided callback.
12181
+ * @param callback - The `callback` parameter is a function that will be called for each entry in the
12182
+ * map. It takes four arguments:
12183
+ * @param [options] - The `options` parameter in the `override map` function is of type
12184
+ * `TreeMultiMapOptions<MK, MV, MR>`. This parameter allows you to provide additional configuration
12185
+ * options when creating a new `TreeMultiMap` instance within the `map` function. These options could
12186
+ * include things like
12187
+ * @param {any} [thisArg] - The `thisArg` parameter in the `override map` function is used to specify
12188
+ * the value of `this` when executing the `callback` function. It allows you to set the context
12189
+ * (value of `this`) for the callback function when it is called within the `map` function. This
12190
+ * @returns A new TreeMultiMap instance is being returned, which is populated with entries generated
12191
+ * by the provided callback function.
12192
+ */
12193
+ map(callback, options, thisArg) {
12194
+ const newTree = new _TreeMultiMap([], options);
12195
+ let index = 0;
12196
+ for (const [key, value] of this) {
12197
+ newTree.add(callback.call(thisArg, key, value, index++, this));
12198
+ }
12199
+ return newTree;
12200
+ }
12192
12201
  };
12193
12202
 
12194
12203
  // src/data-structures/priority-queue/priority-queue.ts