data-structure-typed 1.45.0 → 1.45.2

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 (153) hide show
  1. package/.eslintrc.js +6 -6
  2. package/CHANGELOG.md +1 -1
  3. package/COMMANDS.md +6 -1
  4. package/README.md +18 -15
  5. package/benchmark/report.html +18 -15
  6. package/benchmark/report.json +157 -116
  7. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  8. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
  9. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  10. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  11. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  12. package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
  13. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  14. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  15. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
  16. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  17. package/dist/cjs/data-structures/hash/hash-map.d.ts +58 -58
  18. package/dist/cjs/data-structures/hash/hash-map.js +73 -73
  19. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  20. package/dist/cjs/data-structures/hash/tree-map.js.map +1 -1
  21. package/dist/cjs/data-structures/hash/tree-set.js.map +1 -1
  22. package/dist/cjs/data-structures/heap/heap.js +21 -12
  23. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  24. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  25. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  26. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  27. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  28. package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
  29. package/dist/cjs/data-structures/matrix/matrix2d.js.map +1 -1
  30. package/dist/cjs/data-structures/matrix/navigator.js.map +1 -1
  31. package/dist/cjs/data-structures/matrix/vector2d.js.map +1 -1
  32. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  33. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  34. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
  35. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  36. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  37. package/dist/cjs/data-structures/tree/tree.js.map +1 -1
  38. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  39. package/dist/cjs/utils/utils.js.map +1 -1
  40. package/dist/mjs/data-structures/hash/hash-map.d.ts +58 -58
  41. package/dist/mjs/data-structures/hash/hash-map.js +76 -76
  42. package/dist/mjs/data-structures/heap/heap.js +21 -12
  43. package/dist/umd/data-structure-typed.js +83 -83
  44. package/dist/umd/data-structure-typed.min.js +1 -1
  45. package/dist/umd/data-structure-typed.min.js.map +1 -1
  46. package/package.json +1 -1
  47. package/src/data-structures/binary-tree/avl-tree.ts +7 -7
  48. package/src/data-structures/binary-tree/binary-indexed-tree.ts +3 -3
  49. package/src/data-structures/binary-tree/binary-tree.ts +39 -31
  50. package/src/data-structures/binary-tree/bst.ts +12 -8
  51. package/src/data-structures/binary-tree/rb-tree.ts +17 -6
  52. package/src/data-structures/binary-tree/segment-tree.ts +1 -1
  53. package/src/data-structures/binary-tree/tree-multimap.ts +12 -9
  54. package/src/data-structures/graph/abstract-graph.ts +46 -31
  55. package/src/data-structures/graph/directed-graph.ts +10 -5
  56. package/src/data-structures/graph/map-graph.ts +8 -8
  57. package/src/data-structures/graph/undirected-graph.ts +9 -9
  58. package/src/data-structures/hash/hash-map.ts +103 -103
  59. package/src/data-structures/hash/hash-table.ts +1 -1
  60. package/src/data-structures/hash/tree-map.ts +2 -1
  61. package/src/data-structures/hash/tree-set.ts +2 -1
  62. package/src/data-structures/heap/heap.ts +30 -17
  63. package/src/data-structures/heap/max-heap.ts +3 -3
  64. package/src/data-structures/heap/min-heap.ts +3 -3
  65. package/src/data-structures/linked-list/doubly-linked-list.ts +1 -1
  66. package/src/data-structures/linked-list/singly-linked-list.ts +1 -1
  67. package/src/data-structures/matrix/matrix.ts +2 -2
  68. package/src/data-structures/matrix/matrix2d.ts +1 -1
  69. package/src/data-structures/matrix/navigator.ts +3 -3
  70. package/src/data-structures/matrix/vector2d.ts +2 -1
  71. package/src/data-structures/priority-queue/max-priority-queue.ts +3 -3
  72. package/src/data-structures/priority-queue/min-priority-queue.ts +3 -3
  73. package/src/data-structures/priority-queue/priority-queue.ts +3 -3
  74. package/src/data-structures/queue/deque.ts +5 -4
  75. package/src/data-structures/queue/queue.ts +2 -2
  76. package/src/data-structures/tree/tree.ts +1 -1
  77. package/src/data-structures/trie/trie.ts +1 -1
  78. package/src/interfaces/binary-tree.ts +2 -2
  79. package/src/interfaces/graph.ts +1 -1
  80. package/src/types/data-structures/binary-tree/avl-tree.ts +2 -2
  81. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
  82. package/src/types/data-structures/binary-tree/bst.ts +2 -2
  83. package/src/types/data-structures/binary-tree/rb-tree.ts +2 -2
  84. package/src/types/data-structures/binary-tree/tree-multimap.ts +2 -2
  85. package/src/types/data-structures/hash/hash-map.ts +6 -6
  86. package/src/types/data-structures/matrix/navigator.ts +1 -1
  87. package/src/types/utils/utils.ts +1 -1
  88. package/src/types/utils/validate-type.ts +18 -4
  89. package/src/utils/utils.ts +6 -6
  90. package/test/integration/all-in-one.ts +1 -1
  91. package/test/integration/avl-tree.test.ts +1 -1
  92. package/test/integration/bst.test.ts +19 -19
  93. package/test/integration/heap.test.js +1 -1
  94. package/test/integration/index.html +7 -7
  95. package/test/performance/data-structures/binary-tree/avl-tree.test.ts +4 -4
  96. package/test/performance/data-structures/binary-tree/binary-tree.test.ts +4 -4
  97. package/test/performance/data-structures/binary-tree/bst.test.ts +4 -4
  98. package/test/performance/data-structures/binary-tree/rb-tree.test.ts +9 -9
  99. package/test/performance/data-structures/comparation.test.ts +142 -0
  100. package/test/performance/data-structures/graph/directed-graph.test.ts +4 -4
  101. package/test/performance/data-structures/hash/hash-map.test.ts +8 -8
  102. package/test/performance/data-structures/heap/heap.test.ts +5 -5
  103. package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +7 -7
  104. package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +4 -4
  105. package/test/performance/data-structures/priority-queue/max-priority-queue.test.ts +7 -5
  106. package/test/performance/data-structures/priority-queue/priority-queue.test.ts +8 -8
  107. package/test/performance/data-structures/queue/deque.test.ts +6 -6
  108. package/test/performance/data-structures/queue/queue.test.ts +7 -7
  109. package/test/performance/data-structures/stack/stack.test.ts +8 -8
  110. package/test/performance/data-structures/trie/trie.test.ts +4 -4
  111. package/test/performance/reportor.ts +48 -20
  112. package/test/performance/types/reportor.ts +1 -1
  113. package/test/types/utils/json2html.ts +1 -1
  114. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +6 -6
  115. package/test/unit/data-structures/binary-tree/binary-index-tree.test.ts +12 -12
  116. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +46 -76
  117. package/test/unit/data-structures/binary-tree/bst.test.ts +44 -40
  118. package/test/unit/data-structures/binary-tree/overall.test.ts +17 -17
  119. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +9 -9
  120. package/test/unit/data-structures/binary-tree/segment-tree.test.ts +1 -1
  121. package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +35 -35
  122. package/test/unit/data-structures/graph/abstract-graph.test.ts +7 -7
  123. package/test/unit/data-structures/graph/directed-graph.test.ts +34 -14
  124. package/test/unit/data-structures/graph/map-graph.test.ts +1 -1
  125. package/test/unit/data-structures/graph/overall.test.ts +1 -1
  126. package/test/unit/data-structures/graph/undirected-graph.test.ts +1 -1
  127. package/test/unit/data-structures/hash/coordinate-map.test.ts +1 -1
  128. package/test/unit/data-structures/hash/coordinate-set.test.ts +1 -1
  129. package/test/unit/data-structures/hash/hash-map.test.ts +10 -12
  130. package/test/unit/data-structures/hash/hash-table.test.ts +1 -1
  131. package/test/unit/data-structures/heap/heap.test.ts +73 -23
  132. package/test/unit/data-structures/heap/max-heap.test.ts +2 -2
  133. package/test/unit/data-structures/heap/min-heap.test.ts +2 -2
  134. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +5 -5
  135. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +5 -5
  136. package/test/unit/data-structures/linked-list/skip-list.test.ts +1 -1
  137. package/test/unit/data-structures/matrix/matrix.test.ts +5 -5
  138. package/test/unit/data-structures/matrix/matrix2d.test.ts +3 -3
  139. package/test/unit/data-structures/matrix/navigator.test.ts +2 -2
  140. package/test/unit/data-structures/matrix/vector2d.test.ts +1 -1
  141. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +7 -7
  142. package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +1 -1
  143. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +19 -19
  144. package/test/unit/data-structures/queue/deque.test.ts +3 -3
  145. package/test/unit/data-structures/queue/queue.test.ts +3 -3
  146. package/test/unit/data-structures/stack/stack.test.ts +1 -1
  147. package/test/unit/data-structures/tree/tree.test.ts +1 -1
  148. package/test/unit/data-structures/trie/trie.test.ts +1 -1
  149. package/test/utils/array.ts +1 -1
  150. package/test/utils/big-o.ts +4 -4
  151. package/test/utils/index.ts +1 -0
  152. package/test/utils/json2html.ts +7 -3
  153. package/test/utils/performanc.ts +7 -0
@@ -624,8 +624,8 @@ var dataStructureTyped = (() => {
624
624
  */
625
625
  constructor(node, sentinel, hashMap, iterateDirection = 0 /* DEFAULT */) {
626
626
  __publicField(this, "hashMap");
627
- __publicField(this, "_node");
628
627
  __publicField(this, "iterateDirection");
628
+ __publicField(this, "_node");
629
629
  __publicField(this, "_sentinel");
630
630
  this._node = node;
631
631
  this._sentinel = sentinel;
@@ -713,12 +713,12 @@ var dataStructureTyped = (() => {
713
713
  * `K` represents the type of the key and `V` represents the
714
714
  */
715
715
  constructor(hashMap = []) {
716
+ __publicField(this, "OBJ_KEY_INDEX", Symbol("OBJ_KEY_INDEX"));
716
717
  __publicField(this, "_nodes", []);
717
718
  __publicField(this, "_orgMap", {});
718
719
  __publicField(this, "_head");
719
720
  __publicField(this, "_tail");
720
721
  __publicField(this, "_sentinel");
721
- __publicField(this, "OBJ_KEY_INDEX", Symbol("OBJ_KEY_INDEX"));
722
722
  __publicField(this, "_size", 0);
723
723
  Object.setPrototypeOf(this._orgMap, null);
724
724
  this._sentinel = {};
@@ -730,6 +730,75 @@ var dataStructureTyped = (() => {
730
730
  get size() {
731
731
  return this._size;
732
732
  }
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);
742
+ }
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);
753
+ }
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
+ }
733
802
  /**
734
803
  * Time Complexity: O(1)
735
804
  * Space Complexity: O(1)
@@ -928,75 +997,6 @@ var dataStructureTyped = (() => {
928
997
  this._size = 0;
929
998
  this._head = this._tail = this._sentinel.prev = this._sentinel.next = this._sentinel;
930
999
  }
931
- /**
932
- * Time Complexity: O(1)
933
- * Space Complexity: O(1)
934
- *
935
- * The function returns a new iterator object for a HashMap.
936
- * @returns A new instance of the HashMapIterator class is being returned.
937
- */
938
- get begin() {
939
- return new HashMapIterator(this._head, this._sentinel, this);
940
- }
941
- /**
942
- * Time Complexity: O(1)
943
- * Space Complexity: O(1)
944
- *
945
- * The function returns a new HashMapIterator object with the _sentinel value as both the start and
946
- * end values.
947
- * @returns A new instance of the HashMapIterator class is being returned.
948
- */
949
- get end() {
950
- return new HashMapIterator(this._sentinel, this._sentinel, this);
951
- }
952
- /**
953
- * Time Complexity: O(1)
954
- * Space Complexity: O(1)
955
- *
956
- * The reverseBegin function returns a new HashMapIterator object that iterates over the elements of
957
- * a HashMap in reverse order.
958
- * @returns A new instance of the HashMapIterator class is being returned.
959
- */
960
- get reverseBegin() {
961
- return new HashMapIterator(this._tail, this._sentinel, this, 1 /* REVERSE */);
962
- }
963
- /**
964
- * Time Complexity: O(1)
965
- * Space Complexity: O(1)
966
- *
967
- * The reverseEnd function returns a new HashMapIterator object that iterates over the elements of a
968
- * HashMap in reverse order.
969
- * @returns A new instance of the HashMapIterator class is being returned.
970
- */
971
- get reverseEnd() {
972
- return new HashMapIterator(this._sentinel, this._sentinel, this, 1 /* REVERSE */);
973
- }
974
- /**
975
- * Time Complexity: O(1)
976
- * Space Complexity: O(1)
977
- *
978
- * The function returns the key-value pair at the front of a data structure.
979
- * @returns The front element of the data structure, represented as a tuple with a key (K) and a
980
- * value (V).
981
- */
982
- get front() {
983
- if (this._size === 0)
984
- return;
985
- return [this._head.key, this._head.value];
986
- }
987
- /**
988
- * Time Complexity: O(1)
989
- * Space Complexity: O(1)
990
- *
991
- * The function returns the key-value pair at the end of a data structure.
992
- * @returns The method is returning an array containing the key-value pair of the tail element in the
993
- * data structure.
994
- */
995
- get back() {
996
- if (this._size === 0)
997
- return;
998
- return [this._tail.key, this._tail.value];
999
- }
1000
1000
  /**
1001
1001
  * Time Complexity: O(n), where n is the number of elements in the HashMap.
1002
1002
  * Space Complexity: O(1)
@@ -3773,18 +3773,16 @@ var dataStructureTyped = (() => {
3773
3773
  * @param index - The index of the newly added element.
3774
3774
  */
3775
3775
  bubbleUp(index) {
3776
- const element = this.nodes[index];
3776
+ const item = this.nodes[index];
3777
3777
  while (index > 0) {
3778
- const parentIndex = Math.floor((index - 1) / 2);
3779
- const parent = this.nodes[parentIndex];
3780
- if (this.comparator(element, parent) < 0) {
3781
- this.nodes[index] = parent;
3782
- this.nodes[parentIndex] = element;
3783
- index = parentIndex;
3784
- } else {
3778
+ const parent = index - 1 >> 1;
3779
+ const parentItem = this.nodes[parent];
3780
+ if (this.comparator(parentItem, item) <= 0)
3785
3781
  break;
3786
- }
3782
+ this.nodes[index] = parentItem;
3783
+ index = parent;
3787
3784
  }
3785
+ this.nodes[index] = item;
3788
3786
  }
3789
3787
  /**
3790
3788
  * Time Complexity: O(log n)
@@ -3798,8 +3796,8 @@ var dataStructureTyped = (() => {
3798
3796
  * @param index - The index from which to start sinking.
3799
3797
  */
3800
3798
  sinkDown(index) {
3801
- const leftChildIndex = 2 * index + 1;
3802
- const rightChildIndex = 2 * index + 2;
3799
+ const leftChildIndex = index << 1 | 1;
3800
+ const rightChildIndex = leftChildIndex + 1;
3803
3801
  const length = this.nodes.length;
3804
3802
  let targetIndex = index;
3805
3803
  if (leftChildIndex < length && this.comparator(this.nodes[leftChildIndex], this.nodes[targetIndex]) < 0) {
@@ -7860,7 +7858,9 @@ var dataStructureTyped = (() => {
7860
7858
  return super.addMany(keysOrNodes, data).map((n) => n != null ? n : void 0);
7861
7859
  }
7862
7860
  const inserted = [];
7863
- const combinedArr = keysOrNodes.map((value, index) => [value, data == null ? void 0 : data[index]]);
7861
+ const combinedArr = keysOrNodes.map(
7862
+ (value, index) => [value, data == null ? void 0 : data[index]]
7863
+ );
7864
7864
  let sorted = [];
7865
7865
  function _isNodeOrUndefinedTuple(arr) {
7866
7866
  for (const [keyOrNode] of arr)