data-structure-typed 1.44.1 → 1.45.1

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 (161) hide show
  1. package/.eslintrc.js +6 -6
  2. package/CHANGELOG.md +1 -1
  3. package/README.md +15 -15
  4. package/benchmark/report.html +15 -15
  5. package/benchmark/report.json +121 -121
  6. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  7. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
  8. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  9. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  10. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  11. package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
  12. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  13. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  14. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
  15. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  16. package/dist/cjs/data-structures/hash/hash-map.d.ts +230 -37
  17. package/dist/cjs/data-structures/hash/hash-map.js +427 -115
  18. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  19. package/dist/cjs/data-structures/hash/tree-map.js.map +1 -1
  20. package/dist/cjs/data-structures/hash/tree-set.js.map +1 -1
  21. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  22. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  23. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  24. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  25. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  26. package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
  27. package/dist/cjs/data-structures/matrix/matrix2d.js.map +1 -1
  28. package/dist/cjs/data-structures/matrix/navigator.js.map +1 -1
  29. package/dist/cjs/data-structures/matrix/vector2d.js.map +1 -1
  30. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  31. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  32. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
  33. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  34. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  35. package/dist/cjs/data-structures/tree/tree.js.map +1 -1
  36. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  37. package/dist/cjs/types/data-structures/hash/hash-map.d.ts +15 -1
  38. package/dist/cjs/types/data-structures/hash/index.d.ts +6 -0
  39. package/dist/cjs/types/data-structures/hash/index.js +20 -0
  40. package/dist/cjs/types/data-structures/hash/index.js.map +1 -1
  41. package/dist/cjs/utils/utils.d.ts +3 -0
  42. package/dist/cjs/utils/utils.js +15 -1
  43. package/dist/cjs/utils/utils.js.map +1 -1
  44. package/dist/mjs/data-structures/hash/hash-map.d.ts +230 -37
  45. package/dist/mjs/data-structures/hash/hash-map.js +433 -121
  46. package/dist/mjs/types/data-structures/hash/hash-map.d.ts +15 -1
  47. package/dist/mjs/types/data-structures/hash/index.d.ts +6 -0
  48. package/dist/mjs/types/data-structures/hash/index.js +6 -1
  49. package/dist/mjs/utils/utils.d.ts +3 -0
  50. package/dist/mjs/utils/utils.js +11 -0
  51. package/dist/umd/data-structure-typed.js +533 -207
  52. package/dist/umd/data-structure-typed.min.js +1 -1
  53. package/dist/umd/data-structure-typed.min.js.map +1 -1
  54. package/package.json +2 -2
  55. package/src/data-structures/binary-tree/avl-tree.ts +7 -7
  56. package/src/data-structures/binary-tree/binary-indexed-tree.ts +3 -3
  57. package/src/data-structures/binary-tree/binary-tree.ts +39 -31
  58. package/src/data-structures/binary-tree/bst.ts +12 -8
  59. package/src/data-structures/binary-tree/rb-tree.ts +17 -6
  60. package/src/data-structures/binary-tree/segment-tree.ts +1 -1
  61. package/src/data-structures/binary-tree/tree-multimap.ts +12 -9
  62. package/src/data-structures/graph/abstract-graph.ts +46 -31
  63. package/src/data-structures/graph/directed-graph.ts +10 -5
  64. package/src/data-structures/graph/map-graph.ts +8 -8
  65. package/src/data-structures/graph/undirected-graph.ts +9 -9
  66. package/src/data-structures/hash/hash-map.ts +430 -123
  67. package/src/data-structures/hash/hash-table.ts +1 -1
  68. package/src/data-structures/hash/tree-map.ts +2 -1
  69. package/src/data-structures/hash/tree-set.ts +2 -1
  70. package/src/data-structures/heap/heap.ts +8 -5
  71. package/src/data-structures/heap/max-heap.ts +3 -3
  72. package/src/data-structures/heap/min-heap.ts +3 -3
  73. package/src/data-structures/linked-list/doubly-linked-list.ts +1 -1
  74. package/src/data-structures/linked-list/singly-linked-list.ts +1 -1
  75. package/src/data-structures/matrix/matrix.ts +2 -2
  76. package/src/data-structures/matrix/matrix2d.ts +1 -1
  77. package/src/data-structures/matrix/navigator.ts +3 -3
  78. package/src/data-structures/matrix/vector2d.ts +2 -1
  79. package/src/data-structures/priority-queue/max-priority-queue.ts +3 -3
  80. package/src/data-structures/priority-queue/min-priority-queue.ts +3 -3
  81. package/src/data-structures/priority-queue/priority-queue.ts +3 -3
  82. package/src/data-structures/queue/deque.ts +5 -4
  83. package/src/data-structures/queue/queue.ts +2 -2
  84. package/src/data-structures/tree/tree.ts +1 -1
  85. package/src/data-structures/trie/trie.ts +1 -1
  86. package/src/interfaces/binary-tree.ts +2 -2
  87. package/src/interfaces/graph.ts +1 -1
  88. package/src/types/data-structures/binary-tree/avl-tree.ts +2 -2
  89. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
  90. package/src/types/data-structures/binary-tree/bst.ts +2 -2
  91. package/src/types/data-structures/binary-tree/rb-tree.ts +2 -2
  92. package/src/types/data-structures/binary-tree/tree-multimap.ts +2 -2
  93. package/src/types/data-structures/hash/hash-map.ts +17 -1
  94. package/src/types/data-structures/hash/index.ts +7 -0
  95. package/src/types/data-structures/matrix/navigator.ts +1 -1
  96. package/src/types/utils/utils.ts +1 -1
  97. package/src/types/utils/validate-type.ts +18 -4
  98. package/src/utils/utils.ts +16 -3
  99. package/test/config.ts +1 -1
  100. package/test/integration/all-in-one.ts +1 -1
  101. package/test/integration/avl-tree.test.ts +1 -1
  102. package/test/integration/bst.test.ts +19 -19
  103. package/test/integration/heap.test.js +1 -1
  104. package/test/integration/index.html +7 -7
  105. package/test/performance/data-structures/binary-tree/avl-tree.test.ts +4 -4
  106. package/test/performance/data-structures/binary-tree/binary-tree.test.ts +4 -4
  107. package/test/performance/data-structures/binary-tree/bst.test.ts +4 -4
  108. package/test/performance/data-structures/binary-tree/rb-tree.test.ts +6 -6
  109. package/test/performance/data-structures/graph/directed-graph.test.ts +4 -4
  110. package/test/performance/data-structures/hash/hash-map.test.ts +6 -6
  111. package/test/performance/data-structures/heap/heap.test.ts +5 -5
  112. package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +6 -6
  113. package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +4 -4
  114. package/test/performance/data-structures/priority-queue/max-priority-queue.test.ts +7 -5
  115. package/test/performance/data-structures/priority-queue/priority-queue.test.ts +7 -7
  116. package/test/performance/data-structures/queue/deque.test.ts +5 -5
  117. package/test/performance/data-structures/queue/queue.test.ts +6 -6
  118. package/test/performance/data-structures/stack/stack.test.ts +6 -6
  119. package/test/performance/data-structures/trie/trie.test.ts +4 -4
  120. package/test/performance/reportor.ts +15 -13
  121. package/test/performance/types/reportor.ts +1 -1
  122. package/test/types/utils/json2html.ts +1 -1
  123. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +8 -8
  124. package/test/unit/data-structures/binary-tree/binary-index-tree.test.ts +12 -12
  125. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +46 -76
  126. package/test/unit/data-structures/binary-tree/bst.test.ts +50 -46
  127. package/test/unit/data-structures/binary-tree/overall.test.ts +18 -18
  128. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +21 -21
  129. package/test/unit/data-structures/binary-tree/segment-tree.test.ts +1 -1
  130. package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +37 -37
  131. package/test/unit/data-structures/graph/abstract-graph.test.ts +9 -8
  132. package/test/unit/data-structures/graph/directed-graph.test.ts +34 -14
  133. package/test/unit/data-structures/graph/map-graph.test.ts +1 -1
  134. package/test/unit/data-structures/graph/overall.test.ts +1 -1
  135. package/test/unit/data-structures/graph/undirected-graph.test.ts +2 -2
  136. package/test/unit/data-structures/hash/coordinate-map.test.ts +1 -1
  137. package/test/unit/data-structures/hash/coordinate-set.test.ts +1 -1
  138. package/test/unit/data-structures/hash/hash-map.test.ts +150 -21
  139. package/test/unit/data-structures/hash/hash-table.test.ts +1 -1
  140. package/test/unit/data-structures/heap/heap.test.ts +41 -29
  141. package/test/unit/data-structures/heap/max-heap.test.ts +6 -6
  142. package/test/unit/data-structures/heap/min-heap.test.ts +6 -6
  143. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +6 -6
  144. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +7 -7
  145. package/test/unit/data-structures/linked-list/skip-list.test.ts +5 -5
  146. package/test/unit/data-structures/matrix/matrix.test.ts +5 -5
  147. package/test/unit/data-structures/matrix/matrix2d.test.ts +3 -3
  148. package/test/unit/data-structures/matrix/navigator.test.ts +2 -2
  149. package/test/unit/data-structures/matrix/vector2d.test.ts +1 -1
  150. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +7 -7
  151. package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +1 -1
  152. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +19 -13
  153. package/test/unit/data-structures/queue/deque.test.ts +28 -28
  154. package/test/unit/data-structures/queue/queue.test.ts +3 -3
  155. package/test/unit/data-structures/stack/stack.test.ts +1 -1
  156. package/test/unit/data-structures/tree/tree.test.ts +1 -1
  157. package/test/unit/data-structures/trie/trie.test.ts +10 -10
  158. package/test/utils/array.ts +2 -2
  159. package/test/utils/big-o.ts +4 -4
  160. package/test/utils/json2html.ts +7 -3
  161. package/test/utils/number.ts +1 -1
@@ -113,9 +113,11 @@ var dataStructureTyped = (() => {
113
113
  FibonacciHeap: () => FibonacciHeap,
114
114
  FibonacciHeapNode: () => FibonacciHeapNode,
115
115
  HashMap: () => HashMap,
116
+ HashMapIterator: () => HashMapIterator,
116
117
  HashTable: () => HashTable,
117
118
  HashTableNode: () => HashTableNode,
118
119
  Heap: () => Heap,
120
+ IterateDirection: () => IterateDirection,
119
121
  IterationType: () => IterationType,
120
122
  LinkedListQueue: () => LinkedListQueue,
121
123
  MapEdge: () => MapEdge,
@@ -155,7 +157,10 @@ var dataStructureTyped = (() => {
155
157
  Vector2D: () => Vector2D,
156
158
  arrayRemove: () => arrayRemove,
157
159
  getMSB: () => getMSB,
160
+ isObjOrFunc: () => isObjOrFunc,
158
161
  isThunk: () => isThunk,
162
+ rangeCheck: () => rangeCheck,
163
+ throwRangeError: () => throwRangeError,
159
164
  toThunk: () => toThunk,
160
165
  trampoline: () => trampoline,
161
166
  trampolineAsync: () => trampolineAsync,
@@ -488,148 +493,561 @@ var dataStructureTyped = (() => {
488
493
  var TreeSet = class {
489
494
  };
490
495
 
496
+ // src/utils/utils.ts
497
+ var uuidV4 = function() {
498
+ return "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".replace(/[x]/g, function(c) {
499
+ const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
500
+ return v.toString(16);
501
+ });
502
+ };
503
+ var arrayRemove = function(array, predicate) {
504
+ let i = -1, len = array ? array.length : 0;
505
+ const result = [];
506
+ while (++i < len) {
507
+ const value = array[i];
508
+ if (predicate(value, i, array)) {
509
+ result.push(value);
510
+ Array.prototype.splice.call(array, i--, 1);
511
+ len--;
512
+ }
513
+ }
514
+ return result;
515
+ };
516
+ var THUNK_SYMBOL = Symbol("thunk");
517
+ var isThunk = (fnOrValue) => {
518
+ return typeof fnOrValue === "function" && fnOrValue.__THUNK__ === THUNK_SYMBOL;
519
+ };
520
+ var toThunk = (fn) => {
521
+ const thunk = () => fn();
522
+ thunk.__THUNK__ = THUNK_SYMBOL;
523
+ return thunk;
524
+ };
525
+ var trampoline = (fn) => {
526
+ const cont = (...args) => toThunk(() => fn(...args));
527
+ return Object.assign(
528
+ (...args) => {
529
+ let result = fn(...args);
530
+ while (isThunk(result) && typeof result === "function") {
531
+ result = result();
532
+ }
533
+ return result;
534
+ },
535
+ { cont }
536
+ );
537
+ };
538
+ var trampolineAsync = (fn) => {
539
+ const cont = (...args) => toThunk(() => fn(...args));
540
+ return Object.assign(
541
+ (...args) => __async(void 0, null, function* () {
542
+ let result = yield fn(...args);
543
+ while (isThunk(result) && typeof result === "function") {
544
+ result = yield result();
545
+ }
546
+ return result;
547
+ }),
548
+ { cont }
549
+ );
550
+ };
551
+ var getMSB = (value) => {
552
+ if (value <= 0) {
553
+ return 0;
554
+ }
555
+ return 1 << 31 - Math.clz32(value);
556
+ };
557
+ var rangeCheck = (index, min, max, message = "Index out of bounds.") => {
558
+ if (index < min || index > max)
559
+ throw new RangeError(message);
560
+ };
561
+ var throwRangeError = (message = "The value is off-limits.") => {
562
+ throw new RangeError(message);
563
+ };
564
+ var isObjOrFunc = (input) => {
565
+ const inputType = typeof input;
566
+ return inputType === "object" && input !== null || inputType === "function";
567
+ };
568
+
569
+ // src/types/data-structures/binary-tree/binary-tree.ts
570
+ var IterationType = /* @__PURE__ */ ((IterationType3) => {
571
+ IterationType3["ITERATIVE"] = "ITERATIVE";
572
+ IterationType3["RECURSIVE"] = "RECURSIVE";
573
+ return IterationType3;
574
+ })(IterationType || {});
575
+ var FamilyPosition = /* @__PURE__ */ ((FamilyPosition2) => {
576
+ FamilyPosition2["ROOT"] = "ROOT";
577
+ FamilyPosition2["LEFT"] = "LEFT";
578
+ FamilyPosition2["RIGHT"] = "RIGHT";
579
+ FamilyPosition2["ROOT_LEFT"] = "ROOT_LEFT";
580
+ FamilyPosition2["ROOT_RIGHT"] = "ROOT_RIGHT";
581
+ FamilyPosition2["ISOLATED"] = "ISOLATED";
582
+ FamilyPosition2["MAL_NODE"] = "MAL_NODE";
583
+ return FamilyPosition2;
584
+ })(FamilyPosition || {});
585
+
586
+ // src/types/data-structures/binary-tree/rb-tree.ts
587
+ var RBTNColor = /* @__PURE__ */ ((RBTNColor2) => {
588
+ RBTNColor2[RBTNColor2["RED"] = 1] = "RED";
589
+ RBTNColor2[RBTNColor2["BLACK"] = 0] = "BLACK";
590
+ return RBTNColor2;
591
+ })(RBTNColor || {});
592
+
593
+ // src/types/data-structures/hash/hash-map.ts
594
+ var IterateDirection = /* @__PURE__ */ ((IterateDirection2) => {
595
+ IterateDirection2[IterateDirection2["DEFAULT"] = 0] = "DEFAULT";
596
+ IterateDirection2[IterateDirection2["REVERSE"] = 1] = "REVERSE";
597
+ return IterateDirection2;
598
+ })(IterateDirection || {});
599
+
600
+ // src/types/helpers.ts
601
+ var CP = /* @__PURE__ */ ((CP2) => {
602
+ CP2["lt"] = "lt";
603
+ CP2["eq"] = "eq";
604
+ CP2["gt"] = "gt";
605
+ return CP2;
606
+ })(CP || {});
607
+
491
608
  // src/data-structures/hash/hash-map.ts
492
- var HashMap = class {
609
+ var HashMapIterator = class {
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
+ }
493
666
  /**
494
- * The constructor initializes the properties of a hash table, including the initial capacity, load factor, capacity
495
- * multiplier, size, table array, and hash function.
496
- * @param [initialCapacity=16] - The initial capacity is the initial size of the hash table. It determines the number of
497
- * buckets or slots available for storing key-value pairs. The default value is 16.
498
- * @param [loadFactor=0.75] - The load factor is a measure of how full the hash table can be before it is resized. It is
499
- * a value between 0 and 1, where 1 means the hash table is completely full and 0 means it is completely empty. When the
500
- * load factor is reached, the hash table will
501
- * @param [hashFn] - The `hashFn` parameter is an optional parameter that represents the hash function used to calculate
502
- * the index of a key in the hash table. If a custom hash function is not provided, a default hash function is used. The
503
- * default hash function converts the key to a string, calculates the sum of the
504
- */
505
- constructor(initialCapacity = 16, loadFactor = 0.75, hashFn) {
506
- __publicField(this, "_initialCapacity");
507
- __publicField(this, "_loadFactor");
508
- __publicField(this, "_capacityMultiplier");
509
- __publicField(this, "_size");
510
- __publicField(this, "_table");
511
- __publicField(this, "_hashFn");
512
- this._initialCapacity = initialCapacity;
513
- this._loadFactor = loadFactor;
514
- this._capacityMultiplier = 2;
515
- this._size = 0;
516
- this._table = new Array(initialCapacity);
517
- this._hashFn = hashFn || ((key) => {
518
- const strKey = String(key);
519
- let hash = 0;
520
- for (let i = 0; i < strKey.length; i++) {
521
- hash += strKey.charCodeAt(i);
522
- }
523
- return hash % this.table.length;
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
+ }
524
692
  });
525
693
  }
526
- get initialCapacity() {
527
- return this._initialCapacity;
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;
528
700
  }
529
- get loadFactor() {
530
- return this._loadFactor;
701
+ prev() {
702
+ return this;
531
703
  }
532
- get capacityMultiplier() {
533
- return this._capacityMultiplier;
704
+ next() {
705
+ return this;
706
+ }
707
+ };
708
+ var HashMap = class {
709
+ /**
710
+ * The constructor initializes a HashMap object with an optional initial set of key-value pairs.
711
+ * @param hashMap - The `hashMap` parameter is an optional parameter of type `HashMapOptions<[K,
712
+ * V]>`. It is an array of key-value pairs, where each pair is represented as an array `[K, V]`. The
713
+ * `K` represents the type of the key and `V` represents the
714
+ */
715
+ constructor(hashMap = []) {
716
+ __publicField(this, "OBJ_KEY_INDEX", Symbol("OBJ_KEY_INDEX"));
717
+ __publicField(this, "_nodes", []);
718
+ __publicField(this, "_orgMap", {});
719
+ __publicField(this, "_head");
720
+ __publicField(this, "_tail");
721
+ __publicField(this, "_sentinel");
722
+ __publicField(this, "_size", 0);
723
+ Object.setPrototypeOf(this._orgMap, null);
724
+ this._sentinel = {};
725
+ this._sentinel.prev = this._sentinel.next = this._head = this._tail = this._sentinel;
726
+ hashMap.forEach((el) => {
727
+ this.set(el[0], el[1]);
728
+ });
534
729
  }
535
730
  get size() {
536
731
  return this._size;
537
732
  }
538
- get table() {
539
- return this._table;
733
+ /**
734
+ * Time Complexity: O(1)
735
+ * Space Complexity: O(1)
736
+ *
737
+ * The function returns a new iterator object for a HashMap.
738
+ * @returns A new instance of the HashMapIterator class is being returned.
739
+ */
740
+ get begin() {
741
+ return new HashMapIterator(this._head, this._sentinel, this);
540
742
  }
541
- get hashFn() {
542
- return this._hashFn;
743
+ /**
744
+ * Time Complexity: O(1)
745
+ * Space Complexity: O(1)
746
+ *
747
+ * The function returns a new HashMapIterator object with the _sentinel value as both the start and
748
+ * end values.
749
+ * @returns A new instance of the HashMapIterator class is being returned.
750
+ */
751
+ get end() {
752
+ return new HashMapIterator(this._sentinel, this._sentinel, this);
543
753
  }
544
- set(key, value) {
545
- const loadFactor = this.size / this.table.length;
546
- if (loadFactor >= this.loadFactor) {
547
- this.resizeTable(this.table.length * this.capacityMultiplier);
754
+ /**
755
+ * Time Complexity: O(1)
756
+ * Space Complexity: O(1)
757
+ *
758
+ * The reverseBegin function returns a new HashMapIterator object that iterates over the elements of
759
+ * a HashMap in reverse order.
760
+ * @returns A new instance of the HashMapIterator class is being returned.
761
+ */
762
+ get reverseBegin() {
763
+ return new HashMapIterator(this._tail, this._sentinel, this, 1 /* REVERSE */);
764
+ }
765
+ /**
766
+ * Time Complexity: O(1)
767
+ * Space Complexity: O(1)
768
+ *
769
+ * The reverseEnd function returns a new HashMapIterator object that iterates over the elements of a
770
+ * HashMap in reverse order.
771
+ * @returns A new instance of the HashMapIterator class is being returned.
772
+ */
773
+ get reverseEnd() {
774
+ return new HashMapIterator(this._sentinel, this._sentinel, this, 1 /* REVERSE */);
775
+ }
776
+ /**
777
+ * Time Complexity: O(1)
778
+ * Space Complexity: O(1)
779
+ *
780
+ * The function returns the key-value pair at the front of a data structure.
781
+ * @returns The front element of the data structure, represented as a tuple with a key (K) and a
782
+ * value (V).
783
+ */
784
+ get front() {
785
+ if (this._size === 0)
786
+ return;
787
+ return [this._head.key, this._head.value];
788
+ }
789
+ /**
790
+ * Time Complexity: O(1)
791
+ * Space Complexity: O(1)
792
+ *
793
+ * The function returns the key-value pair at the end of a data structure.
794
+ * @returns The method is returning an array containing the key-value pair of the tail element in the
795
+ * data structure.
796
+ */
797
+ get back() {
798
+ if (this._size === 0)
799
+ return;
800
+ return [this._tail.key, this._tail.value];
801
+ }
802
+ /**
803
+ * Time Complexity: O(1)
804
+ * Space Complexity: O(1)
805
+ *
806
+ * The `set` function adds a new key-value pair to a data structure, either using an object key or a
807
+ * string key.
808
+ * @param {K} key - The `key` parameter is the key to be set in the data structure. It can be of any
809
+ * type, but typically it is a string or symbol.
810
+ * @param {V} [value] - The `value` parameter is an optional parameter of type `V`. It represents the
811
+ * value associated with the key being set in the data structure.
812
+ * @param {boolean} isObjectKey - A boolean flag indicating whether the key is an object key or not.
813
+ * @returns the size of the data structure after the key-value pair has been set.
814
+ */
815
+ set(key, value, isObjectKey = isObjOrFunc(key)) {
816
+ let newTail;
817
+ if (isObjectKey) {
818
+ const index = key[this.OBJ_KEY_INDEX];
819
+ if (index !== void 0) {
820
+ this._nodes[index].value = value;
821
+ return this._size;
822
+ }
823
+ Object.defineProperty(key, this.OBJ_KEY_INDEX, {
824
+ value: this._nodes.length,
825
+ configurable: true
826
+ });
827
+ newTail = {
828
+ key,
829
+ value,
830
+ prev: this._tail,
831
+ next: this._sentinel
832
+ };
833
+ this._nodes.push(newTail);
834
+ } else {
835
+ const node = this._orgMap[key];
836
+ if (node) {
837
+ node.value = value;
838
+ return this._size;
839
+ }
840
+ this._orgMap[key] = newTail = {
841
+ key,
842
+ value,
843
+ prev: this._tail,
844
+ next: this._sentinel
845
+ };
548
846
  }
549
- const index = this._hash(key);
550
- if (!this.table[index]) {
551
- this.table[index] = [];
847
+ if (this._size === 0) {
848
+ this._head = newTail;
849
+ this._sentinel.next = newTail;
850
+ } else {
851
+ this._tail.next = newTail;
552
852
  }
553
- for (let i = 0; i < this.table[index].length; i++) {
554
- if (this.table[index][i][0] === key) {
555
- this.table[index][i][1] = value;
556
- return;
557
- }
853
+ this._tail = newTail;
854
+ this._sentinel.prev = newTail;
855
+ return ++this._size;
856
+ }
857
+ /**
858
+ * Time Complexity: O(1)
859
+ * Space Complexity: O(1)
860
+ *
861
+ * The function `get` retrieves the value associated with a given key from a map, either by using the
862
+ * key directly or by using an index stored in the key object.
863
+ * @param {K} key - The `key` parameter is the key used to retrieve a value from the map. It can be
864
+ * of any type, but typically it is a string or symbol.
865
+ * @param {boolean} isObjectKey - The `isObjectKey` parameter is a boolean flag that indicates
866
+ * whether the `key` parameter is an object key or not. If `isObjectKey` is `true`, it means that
867
+ * `key` is an object key. If `isObjectKey` is `false`, it means that `key`
868
+ * @returns The value associated with the given key is being returned. If the key is an object key,
869
+ * the value is retrieved from the `_nodes` array using the index stored in the `OBJ_KEY_INDEX`
870
+ * property of the key. If the key is a string key, the value is retrieved from the `_orgMap` object
871
+ * using the key itself. If the key is not found, `undefined` is
872
+ */
873
+ get(key, isObjectKey = isObjOrFunc(key)) {
874
+ if (isObjectKey) {
875
+ const index = key[this.OBJ_KEY_INDEX];
876
+ return index !== void 0 ? this._nodes[index].value : void 0;
558
877
  }
559
- this.table[index].push([key, value]);
560
- this._size++;
878
+ const node = this._orgMap[key];
879
+ return node ? node.value : void 0;
561
880
  }
562
- get(key) {
563
- const index = this._hash(key);
564
- if (!this.table[index]) {
565
- return void 0;
881
+ /**
882
+ * Time Complexity: O(n), where n is the index.
883
+ * Space Complexity: O(1)
884
+ *
885
+ * The function `getAt` retrieves the key-value pair at a specified index in a linked list.
886
+ * @param {number} index - The index parameter is a number that represents the position of the
887
+ * element we want to retrieve from the data structure.
888
+ * @returns The method `getAt(index: number)` is returning an array containing the key-value pair at
889
+ * the specified index in the data structure. The key-value pair is represented as a tuple `[K, V]`,
890
+ * where `K` is the key and `V` is the value.
891
+ */
892
+ getAt(index) {
893
+ rangeCheck(index, 0, this._size - 1);
894
+ let node = this._head;
895
+ while (index--) {
896
+ node = node.next;
566
897
  }
567
- for (const [k, v] of this.table[index]) {
568
- if (k === key) {
569
- return v;
898
+ return [node.key, node.value];
899
+ }
900
+ /**
901
+ * Time Complexity: O(1)
902
+ * Space Complexity: O(1)
903
+ *
904
+ * The function `getIterator` returns a new instance of `HashMapIterator` based on the provided key
905
+ * and whether it is an object key or not.
906
+ * @param {K} key - The `key` parameter is the key used to retrieve the iterator from the HashMap. It
907
+ * can be of any type, depending on how the HashMap is implemented.
908
+ * @param {boolean} [isObjectKey] - The `isObjectKey` parameter is an optional boolean parameter that
909
+ * indicates whether the `key` parameter is an object key. If `isObjectKey` is `true`, it means that
910
+ * the `key` parameter is an object and needs to be handled differently. If `isObjectKey` is `false`
911
+ * @returns a new instance of the `HashMapIterator` class.
912
+ */
913
+ getIterator(key, isObjectKey) {
914
+ let node;
915
+ if (isObjectKey) {
916
+ const index = key[this.OBJ_KEY_INDEX];
917
+ if (index === void 0) {
918
+ node = this._sentinel;
919
+ } else {
920
+ node = this._nodes[index];
570
921
  }
922
+ } else {
923
+ node = this._orgMap[key] || this._sentinel;
571
924
  }
572
- return void 0;
925
+ return new HashMapIterator(node, this._sentinel, this);
573
926
  }
574
- delete(key) {
575
- const index = this._hash(key);
576
- if (!this.table[index]) {
577
- return;
578
- }
579
- for (let i = 0; i < this.table[index].length; i++) {
580
- if (this.table[index][i][0] === key) {
581
- this.table[index].splice(i, 1);
582
- this._size--;
583
- const loadFactor = this.size / this.table.length;
584
- if (loadFactor < this.loadFactor / this.capacityMultiplier) {
585
- this.resizeTable(this.table.length / this.capacityMultiplier);
586
- }
587
- return;
588
- }
927
+ /**
928
+ * Time Complexity: O(1)
929
+ * Space Complexity: O(1)
930
+ *
931
+ * The `delete` function removes a key-value pair from a map-like data structure.
932
+ * @param {K} key - The `key` parameter is the key that you want to delete from the data structure.
933
+ * It can be of any type, but typically it is a string or an object.
934
+ * @param {boolean} isObjectKey - The `isObjectKey` parameter is a boolean flag that indicates
935
+ * whether the `key` parameter is an object key or not. If `isObjectKey` is `true`, it means that the
936
+ * `key` parameter is an object key. If `isObjectKey` is `false`, it means that the
937
+ * @returns a boolean value. It returns `true` if the deletion was successful, and `false` if the key
938
+ * was not found.
939
+ */
940
+ delete(key, isObjectKey = isObjOrFunc(key)) {
941
+ let node;
942
+ if (isObjectKey) {
943
+ const index = key[this.OBJ_KEY_INDEX];
944
+ if (index === void 0)
945
+ return false;
946
+ delete key[this.OBJ_KEY_INDEX];
947
+ node = this._nodes[index];
948
+ delete this._nodes[index];
949
+ } else {
950
+ node = this._orgMap[key];
951
+ if (node === void 0)
952
+ return false;
953
+ delete this._orgMap[key];
589
954
  }
955
+ this._deleteNode(node);
956
+ return true;
590
957
  }
591
- *entries() {
592
- for (const bucket of this.table) {
593
- if (bucket) {
594
- for (const [key, value] of bucket) {
595
- yield [key, value];
596
- }
597
- }
958
+ /**
959
+ * Time Complexity: O(n), where n is the index.
960
+ * Space Complexity: O(1)
961
+ *
962
+ * The `deleteAt` function deletes a node at a specified index in a linked list.
963
+ * @param {number} index - The index parameter represents the position at which the node should be
964
+ * deleted in the linked list.
965
+ * @returns The size of the list after deleting the element at the specified index.
966
+ */
967
+ deleteAt(index) {
968
+ rangeCheck(index, 0, this._size - 1);
969
+ let node = this._head;
970
+ while (index--) {
971
+ node = node.next;
598
972
  }
973
+ this._deleteNode(node);
974
+ return this._size;
599
975
  }
600
- [Symbol.iterator]() {
601
- return this.entries();
976
+ /**
977
+ * Time Complexity: O(1)
978
+ * Space Complexity: O(1)
979
+ *
980
+ * The function checks if a data structure is empty by comparing its size to zero.
981
+ * @returns The method is returning a boolean value indicating whether the size of the object is 0 or
982
+ * not.
983
+ */
984
+ isEmpty() {
985
+ return this._size === 0;
602
986
  }
987
+ /**
988
+ * Time Complexity: O(1)
989
+ * Space Complexity: O(1)
990
+ *
991
+ * The `clear` function clears all the elements in a data structure and resets its properties.
992
+ */
603
993
  clear() {
994
+ this._nodes = [];
995
+ this._orgMap = {};
996
+ Object.setPrototypeOf(this._orgMap, null);
604
997
  this._size = 0;
605
- this._table = new Array(this.initialCapacity);
998
+ this._head = this._tail = this._sentinel.prev = this._sentinel.next = this._sentinel;
606
999
  }
607
- isEmpty() {
608
- return this.size === 0;
1000
+ /**
1001
+ * Time Complexity: O(n), where n is the number of elements in the HashMap.
1002
+ * Space Complexity: O(1)
1003
+ *
1004
+ * The `forEach` function iterates over each element in a HashMap and executes a callback function on
1005
+ * each element.
1006
+ * @param callback - The callback parameter is a function that will be called for each element in the
1007
+ * HashMap. It takes three arguments:
1008
+ */
1009
+ forEach(callback) {
1010
+ let index = 0;
1011
+ let node = this._head;
1012
+ while (node !== this._sentinel) {
1013
+ callback([node.key, node.value], index++, this);
1014
+ node = node.next;
1015
+ }
609
1016
  }
610
- _hash(key) {
611
- return this._hashFn(key);
612
- }
613
- /**
614
- * The `resizeTable` function resizes the table used in a hash map by creating a new table with a specified capacity and
615
- * rehashing the key-value pairs from the old table into the new table.
616
- * @param {number} newCapacity - The newCapacity parameter is the desired capacity for the resized table. It represents
617
- * the number of buckets that the new table should have.
618
- */
619
- resizeTable(newCapacity) {
620
- const newTable = new Array(newCapacity);
621
- for (const bucket of this._table) {
622
- if (bucket) {
623
- for (const [key, value] of bucket) {
624
- const newIndex = this._hash(key) % newCapacity;
625
- if (!newTable[newIndex]) {
626
- newTable[newIndex] = [];
627
- }
628
- newTable[newIndex].push([key, value]);
629
- }
630
- }
1017
+ /**
1018
+ * Time Complexity: O(n), where n is the number of elements in the HashMap.
1019
+ * Space Complexity: O(1)
1020
+ *
1021
+ * The above function is an iterator that yields key-value pairs from a linked list.
1022
+ */
1023
+ *[Symbol.iterator]() {
1024
+ let node = this._head;
1025
+ while (node !== this._sentinel) {
1026
+ yield [node.key, node.value];
1027
+ node = node.next;
631
1028
  }
632
- this._table = newTable;
1029
+ }
1030
+ /**
1031
+ * Time Complexity: O(1)
1032
+ * Space Complexity: O(1)
1033
+ *
1034
+ * The `_deleteNode` function removes a node from a doubly linked list and updates the head and tail
1035
+ * pointers if necessary.
1036
+ * @param node - The `node` parameter is an instance of the `HashMapLinkedNode` class, which
1037
+ * represents a node in a linked list. It contains a key-value pair and references to the previous
1038
+ * and next nodes in the list.
1039
+ */
1040
+ _deleteNode(node) {
1041
+ const { prev, next } = node;
1042
+ prev.next = next;
1043
+ next.prev = prev;
1044
+ if (node === this._head) {
1045
+ this._head = next;
1046
+ }
1047
+ if (node === this._tail) {
1048
+ this._tail = prev;
1049
+ }
1050
+ this._size -= 1;
633
1051
  }
634
1052
  };
635
1053
 
@@ -3092,68 +3510,6 @@ var dataStructureTyped = (() => {
3092
3510
  }
3093
3511
  };
3094
3512
 
3095
- // src/utils/utils.ts
3096
- var uuidV4 = function() {
3097
- return "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".replace(/[x]/g, function(c) {
3098
- const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
3099
- return v.toString(16);
3100
- });
3101
- };
3102
- var arrayRemove = function(array, predicate) {
3103
- let i = -1, len = array ? array.length : 0;
3104
- const result = [];
3105
- while (++i < len) {
3106
- const value = array[i];
3107
- if (predicate(value, i, array)) {
3108
- result.push(value);
3109
- Array.prototype.splice.call(array, i--, 1);
3110
- len--;
3111
- }
3112
- }
3113
- return result;
3114
- };
3115
- var THUNK_SYMBOL = Symbol("thunk");
3116
- var isThunk = (fnOrValue) => {
3117
- return typeof fnOrValue === "function" && fnOrValue.__THUNK__ === THUNK_SYMBOL;
3118
- };
3119
- var toThunk = (fn) => {
3120
- const thunk = () => fn();
3121
- thunk.__THUNK__ = THUNK_SYMBOL;
3122
- return thunk;
3123
- };
3124
- var trampoline = (fn) => {
3125
- const cont = (...args) => toThunk(() => fn(...args));
3126
- return Object.assign(
3127
- (...args) => {
3128
- let result = fn(...args);
3129
- while (isThunk(result) && typeof result === "function") {
3130
- result = result();
3131
- }
3132
- return result;
3133
- },
3134
- { cont }
3135
- );
3136
- };
3137
- var trampolineAsync = (fn) => {
3138
- const cont = (...args) => toThunk(() => fn(...args));
3139
- return Object.assign(
3140
- (...args) => __async(void 0, null, function* () {
3141
- let result = yield fn(...args);
3142
- while (isThunk(result) && typeof result === "function") {
3143
- result = yield result();
3144
- }
3145
- return result;
3146
- }),
3147
- { cont }
3148
- );
3149
- };
3150
- var getMSB = (value) => {
3151
- if (value <= 0) {
3152
- return 0;
3153
- }
3154
- return 1 << 31 - Math.clz32(value);
3155
- };
3156
-
3157
3513
  // src/data-structures/heap/heap.ts
3158
3514
  var Heap = class _Heap {
3159
3515
  constructor(options) {
@@ -5793,38 +6149,6 @@ var dataStructureTyped = (() => {
5793
6149
  }
5794
6150
  };
5795
6151
 
5796
- // src/types/data-structures/binary-tree/binary-tree.ts
5797
- var IterationType = /* @__PURE__ */ ((IterationType3) => {
5798
- IterationType3["ITERATIVE"] = "ITERATIVE";
5799
- IterationType3["RECURSIVE"] = "RECURSIVE";
5800
- return IterationType3;
5801
- })(IterationType || {});
5802
- var FamilyPosition = /* @__PURE__ */ ((FamilyPosition2) => {
5803
- FamilyPosition2["ROOT"] = "ROOT";
5804
- FamilyPosition2["LEFT"] = "LEFT";
5805
- FamilyPosition2["RIGHT"] = "RIGHT";
5806
- FamilyPosition2["ROOT_LEFT"] = "ROOT_LEFT";
5807
- FamilyPosition2["ROOT_RIGHT"] = "ROOT_RIGHT";
5808
- FamilyPosition2["ISOLATED"] = "ISOLATED";
5809
- FamilyPosition2["MAL_NODE"] = "MAL_NODE";
5810
- return FamilyPosition2;
5811
- })(FamilyPosition || {});
5812
-
5813
- // src/types/data-structures/binary-tree/rb-tree.ts
5814
- var RBTNColor = /* @__PURE__ */ ((RBTNColor2) => {
5815
- RBTNColor2[RBTNColor2["RED"] = 1] = "RED";
5816
- RBTNColor2[RBTNColor2["BLACK"] = 0] = "BLACK";
5817
- return RBTNColor2;
5818
- })(RBTNColor || {});
5819
-
5820
- // src/types/helpers.ts
5821
- var CP = /* @__PURE__ */ ((CP2) => {
5822
- CP2["lt"] = "lt";
5823
- CP2["eq"] = "eq";
5824
- CP2["gt"] = "gt";
5825
- return CP2;
5826
- })(CP || {});
5827
-
5828
6152
  // src/data-structures/binary-tree/binary-tree.ts
5829
6153
  var BinaryTreeNode = class {
5830
6154
  /**
@@ -7536,7 +7860,9 @@ var dataStructureTyped = (() => {
7536
7860
  return super.addMany(keysOrNodes, data).map((n) => n != null ? n : void 0);
7537
7861
  }
7538
7862
  const inserted = [];
7539
- const combinedArr = keysOrNodes.map((value, index) => [value, data == null ? void 0 : data[index]]);
7863
+ const combinedArr = keysOrNodes.map(
7864
+ (value, index) => [value, data == null ? void 0 : data[index]]
7865
+ );
7540
7866
  let sorted = [];
7541
7867
  function _isNodeOrUndefinedTuple(arr) {
7542
7868
  for (const [keyOrNode] of arr)