data-structure-typed 1.51.8 → 1.52.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 (216) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +13 -13
  3. package/benchmark/report.html +13 -13
  4. package/benchmark/report.json +152 -152
  5. package/dist/cjs/data-structures/base/index.d.ts +2 -1
  6. package/dist/cjs/data-structures/base/index.js +2 -1
  7. package/dist/cjs/data-structures/base/index.js.map +1 -1
  8. package/dist/cjs/data-structures/base/iterable-element-base.d.ts +171 -0
  9. package/dist/cjs/data-structures/base/iterable-element-base.js +226 -0
  10. package/dist/cjs/data-structures/base/iterable-element-base.js.map +1 -0
  11. package/dist/cjs/data-structures/base/{iterable-base.d.ts → iterable-entry-base.d.ts} +4 -147
  12. package/dist/cjs/data-structures/base/{iterable-base.js → iterable-entry-base.js} +13 -190
  13. package/dist/cjs/data-structures/base/iterable-entry-base.js.map +1 -0
  14. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +106 -68
  15. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +119 -87
  16. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  17. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +82 -62
  18. package/dist/cjs/data-structures/binary-tree/avl-tree.js +78 -59
  19. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  20. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +318 -226
  21. package/dist/cjs/data-structures/binary-tree/binary-tree.js +475 -363
  22. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  23. package/dist/cjs/data-structures/binary-tree/bst.d.ts +192 -202
  24. package/dist/cjs/data-structures/binary-tree/bst.js +207 -249
  25. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  26. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +73 -74
  27. package/dist/cjs/data-structures/binary-tree/rb-tree.js +107 -98
  28. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  29. package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +92 -75
  30. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +105 -93
  31. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  32. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +10 -15
  33. package/dist/cjs/data-structures/graph/abstract-graph.js +10 -15
  34. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  35. package/dist/cjs/data-structures/hash/hash-map.d.ts +33 -40
  36. package/dist/cjs/data-structures/hash/hash-map.js +40 -55
  37. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  38. package/dist/cjs/data-structures/heap/heap.d.ts +43 -114
  39. package/dist/cjs/data-structures/heap/heap.js +59 -127
  40. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  41. package/dist/cjs/data-structures/heap/max-heap.d.ts +50 -4
  42. package/dist/cjs/data-structures/heap/max-heap.js +76 -10
  43. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  44. package/dist/cjs/data-structures/heap/min-heap.d.ts +51 -5
  45. package/dist/cjs/data-structures/heap/min-heap.js +68 -11
  46. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  47. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +22 -28
  48. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +26 -28
  49. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  50. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +22 -25
  51. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +29 -26
  52. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  53. package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +50 -4
  54. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +79 -10
  55. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  56. package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +51 -5
  57. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +71 -11
  58. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  59. package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +50 -4
  60. package/dist/cjs/data-structures/priority-queue/priority-queue.js +70 -1
  61. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
  62. package/dist/cjs/data-structures/queue/deque.d.ts +21 -20
  63. package/dist/cjs/data-structures/queue/deque.js +29 -23
  64. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  65. package/dist/cjs/data-structures/queue/queue.d.ts +8 -28
  66. package/dist/cjs/data-structures/queue/queue.js +15 -31
  67. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  68. package/dist/cjs/data-structures/stack/stack.d.ts +17 -22
  69. package/dist/cjs/data-structures/stack/stack.js +25 -24
  70. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  71. package/dist/cjs/data-structures/trie/trie.d.ts +19 -14
  72. package/dist/cjs/data-structures/trie/trie.js +27 -16
  73. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  74. package/dist/cjs/interfaces/binary-tree.d.ts +7 -7
  75. package/dist/cjs/types/common.d.ts +1 -2
  76. package/dist/cjs/types/data-structures/base/base.d.ts +5 -2
  77. package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +3 -4
  78. package/dist/cjs/types/data-structures/binary-tree/avl-tree.d.ts +3 -4
  79. package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +5 -5
  80. package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +4 -5
  81. package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +3 -4
  82. package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.d.ts +3 -4
  83. package/dist/cjs/types/data-structures/heap/heap.d.ts +3 -2
  84. package/dist/cjs/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
  85. package/dist/cjs/types/data-structures/linked-list/singly-linked-list.d.ts +2 -1
  86. package/dist/cjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  87. package/dist/cjs/types/data-structures/queue/deque.d.ts +3 -2
  88. package/dist/cjs/types/data-structures/queue/queue.d.ts +2 -1
  89. package/dist/cjs/types/data-structures/stack/stack.d.ts +2 -1
  90. package/dist/cjs/types/data-structures/trie/trie.d.ts +3 -2
  91. package/dist/cjs/utils/utils.js +3 -5
  92. package/dist/cjs/utils/utils.js.map +1 -1
  93. package/dist/mjs/data-structures/base/index.d.ts +2 -1
  94. package/dist/mjs/data-structures/base/index.js +2 -1
  95. package/dist/mjs/data-structures/base/iterable-element-base.d.ts +171 -0
  96. package/dist/mjs/data-structures/base/iterable-element-base.js +222 -0
  97. package/dist/mjs/data-structures/base/{iterable-base.d.ts → iterable-entry-base.d.ts} +4 -147
  98. package/dist/mjs/data-structures/base/{iterable-base.js → iterable-entry-base.js} +10 -186
  99. package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +106 -68
  100. package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +119 -87
  101. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +82 -62
  102. package/dist/mjs/data-structures/binary-tree/avl-tree.js +78 -59
  103. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +318 -226
  104. package/dist/mjs/data-structures/binary-tree/binary-tree.js +476 -364
  105. package/dist/mjs/data-structures/binary-tree/bst.d.ts +192 -202
  106. package/dist/mjs/data-structures/binary-tree/bst.js +211 -255
  107. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +73 -74
  108. package/dist/mjs/data-structures/binary-tree/rb-tree.js +107 -98
  109. package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +92 -75
  110. package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +105 -93
  111. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +10 -15
  112. package/dist/mjs/data-structures/graph/abstract-graph.js +10 -15
  113. package/dist/mjs/data-structures/hash/hash-map.d.ts +33 -40
  114. package/dist/mjs/data-structures/hash/hash-map.js +41 -55
  115. package/dist/mjs/data-structures/heap/heap.d.ts +43 -114
  116. package/dist/mjs/data-structures/heap/heap.js +60 -128
  117. package/dist/mjs/data-structures/heap/max-heap.d.ts +50 -4
  118. package/dist/mjs/data-structures/heap/max-heap.js +79 -10
  119. package/dist/mjs/data-structures/heap/min-heap.d.ts +51 -5
  120. package/dist/mjs/data-structures/heap/min-heap.js +68 -11
  121. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +22 -28
  122. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +26 -28
  123. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +22 -25
  124. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +29 -26
  125. package/dist/mjs/data-structures/priority-queue/max-priority-queue.d.ts +50 -4
  126. package/dist/mjs/data-structures/priority-queue/max-priority-queue.js +82 -10
  127. package/dist/mjs/data-structures/priority-queue/min-priority-queue.d.ts +51 -5
  128. package/dist/mjs/data-structures/priority-queue/min-priority-queue.js +71 -11
  129. package/dist/mjs/data-structures/priority-queue/priority-queue.d.ts +50 -4
  130. package/dist/mjs/data-structures/priority-queue/priority-queue.js +70 -1
  131. package/dist/mjs/data-structures/queue/deque.d.ts +21 -20
  132. package/dist/mjs/data-structures/queue/deque.js +29 -23
  133. package/dist/mjs/data-structures/queue/queue.d.ts +8 -28
  134. package/dist/mjs/data-structures/queue/queue.js +15 -31
  135. package/dist/mjs/data-structures/stack/stack.d.ts +17 -22
  136. package/dist/mjs/data-structures/stack/stack.js +25 -24
  137. package/dist/mjs/data-structures/trie/trie.d.ts +19 -14
  138. package/dist/mjs/data-structures/trie/trie.js +27 -16
  139. package/dist/mjs/interfaces/binary-tree.d.ts +7 -7
  140. package/dist/mjs/types/common.d.ts +1 -2
  141. package/dist/mjs/types/data-structures/base/base.d.ts +5 -2
  142. package/dist/mjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +3 -4
  143. package/dist/mjs/types/data-structures/binary-tree/avl-tree.d.ts +3 -4
  144. package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +5 -5
  145. package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +4 -5
  146. package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +3 -4
  147. package/dist/mjs/types/data-structures/binary-tree/tree-multi-map.d.ts +3 -4
  148. package/dist/mjs/types/data-structures/heap/heap.d.ts +3 -2
  149. package/dist/mjs/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
  150. package/dist/mjs/types/data-structures/linked-list/singly-linked-list.d.ts +2 -1
  151. package/dist/mjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  152. package/dist/mjs/types/data-structures/queue/deque.d.ts +3 -2
  153. package/dist/mjs/types/data-structures/queue/queue.d.ts +2 -1
  154. package/dist/mjs/types/data-structures/stack/stack.d.ts +2 -1
  155. package/dist/mjs/types/data-structures/trie/trie.d.ts +3 -2
  156. package/dist/mjs/utils/utils.js +3 -5
  157. package/dist/umd/data-structure-typed.js +1949 -1481
  158. package/dist/umd/data-structure-typed.min.js +2 -2
  159. package/dist/umd/data-structure-typed.min.js.map +1 -1
  160. package/package.json +6 -6
  161. package/src/data-structures/base/index.ts +2 -1
  162. package/src/data-structures/base/iterable-element-base.ts +250 -0
  163. package/src/data-structures/base/{iterable-base.ts → iterable-entry-base.ts} +22 -213
  164. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +144 -95
  165. package/src/data-structures/binary-tree/avl-tree.ts +96 -69
  166. package/src/data-structures/binary-tree/binary-tree.ts +535 -403
  167. package/src/data-structures/binary-tree/bst.ts +247 -277
  168. package/src/data-structures/binary-tree/rb-tree.ts +123 -103
  169. package/src/data-structures/binary-tree/tree-multi-map.ts +127 -102
  170. package/src/data-structures/graph/abstract-graph.ts +10 -10
  171. package/src/data-structures/hash/hash-map.ts +46 -53
  172. package/src/data-structures/heap/heap.ts +71 -152
  173. package/src/data-structures/heap/max-heap.ts +88 -13
  174. package/src/data-structures/heap/min-heap.ts +78 -15
  175. package/src/data-structures/linked-list/doubly-linked-list.ts +32 -32
  176. package/src/data-structures/linked-list/singly-linked-list.ts +37 -29
  177. package/src/data-structures/priority-queue/max-priority-queue.ts +94 -13
  178. package/src/data-structures/priority-queue/min-priority-queue.ts +84 -15
  179. package/src/data-structures/priority-queue/priority-queue.ts +81 -4
  180. package/src/data-structures/queue/deque.ts +37 -26
  181. package/src/data-structures/queue/queue.ts +23 -36
  182. package/src/data-structures/stack/stack.ts +31 -26
  183. package/src/data-structures/trie/trie.ts +35 -20
  184. package/src/interfaces/binary-tree.ts +9 -9
  185. package/src/types/common.ts +1 -2
  186. package/src/types/data-structures/base/base.ts +14 -6
  187. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +3 -4
  188. package/src/types/data-structures/binary-tree/avl-tree.ts +3 -4
  189. package/src/types/data-structures/binary-tree/binary-tree.ts +6 -6
  190. package/src/types/data-structures/binary-tree/bst.ts +4 -5
  191. package/src/types/data-structures/binary-tree/rb-tree.ts +3 -4
  192. package/src/types/data-structures/binary-tree/tree-multi-map.ts +3 -4
  193. package/src/types/data-structures/heap/heap.ts +4 -1
  194. package/src/types/data-structures/linked-list/doubly-linked-list.ts +3 -1
  195. package/src/types/data-structures/linked-list/singly-linked-list.ts +3 -1
  196. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -1
  197. package/src/types/data-structures/queue/deque.ts +3 -1
  198. package/src/types/data-structures/queue/queue.ts +3 -1
  199. package/src/types/data-structures/stack/stack.ts +3 -1
  200. package/src/types/data-structures/trie/trie.ts +3 -1
  201. package/src/utils/utils.ts +3 -3
  202. package/test/integration/avl-tree.test.ts +2 -2
  203. package/test/integration/bst.test.ts +3 -3
  204. package/test/integration/index.html +25 -11
  205. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +68 -0
  206. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +56 -0
  207. package/test/unit/data-structures/graph/directed-graph.test.ts +2 -2
  208. package/test/unit/data-structures/heap/heap.test.ts +80 -0
  209. package/test/unit/data-structures/heap/max-heap.test.ts +44 -1
  210. package/test/unit/data-structures/heap/min-heap.test.ts +18 -1
  211. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +42 -0
  212. package/test/unit/data-structures/queue/deque.test.ts +30 -0
  213. package/test/unit/data-structures/queue/queue.test.ts +56 -0
  214. package/test/utils/big-o.ts +12 -6
  215. package/tsconfig-base.json +1 -0
  216. package/dist/cjs/data-structures/base/iterable-base.js.map +0 -1
@@ -395,9 +395,8 @@ export class AbstractGraph extends IterableEntryBase {
395
395
  }
396
396
  /**
397
397
  * Dijkstra algorithm time: O(VE) space: O(VO + EO)
398
- * /
399
-
400
- /**
398
+ */
399
+ /**
401
400
  * Time Complexity: O(V^2 + E) - Quadratic time in the worst case (no heap optimization).
402
401
  * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
403
402
  */
@@ -523,9 +522,8 @@ export class AbstractGraph extends IterableEntryBase {
523
522
  * Dijkstra's algorithm is suitable for graphs with non-negative edge weights, whereas the Bellman-Ford algorithm and Floyd-Warshall algorithm can handle negative-weight edgeMap.
524
523
  * The time complexity of Dijkstra's algorithm and the Bellman-Ford algorithm depends on the size of the graph, while the time complexity of the Floyd-Warshall algorithm is O(VO^3), where VO is the number of nodes. For dense graphs, Floyd-Warshall might become slower.
525
524
  *
526
- * /
527
-
528
- /**
525
+ */
526
+ /**
529
527
  * Time Complexity: O((V + E) * log(V)) - Depends on the implementation (using a binary heap).
530
528
  * Space Complexity: O(V + E) - Depends on the implementation (using a binary heap).
531
529
  */
@@ -648,9 +646,8 @@ export class AbstractGraph extends IterableEntryBase {
648
646
  * Time Complexity: O(V * E) - Quadratic time in the worst case (Bellman-Ford algorithm).
649
647
  * Space Complexity: O(V + E) - Depends on the implementation (Bellman-Ford algorithm).
650
648
  * one to rest pairs
651
- * /
652
-
653
- /**
649
+ */
650
+ /**
654
651
  * Time Complexity: O(V * E) - Quadratic time in the worst case (Bellman-Ford algorithm).
655
652
  * Space Complexity: O(V + E) - Depends on the implementation (Bellman-Ford algorithm).
656
653
  *
@@ -755,9 +752,8 @@ export class AbstractGraph extends IterableEntryBase {
755
752
  }
756
753
  /**
757
754
  * Dijkstra algorithm time: O(logVE) space: O(VO + EO)
758
- * /
759
-
760
- /**
755
+ */
756
+ /**
761
757
  * Dijkstra algorithm time: O(logVE) space: O(VO + EO)
762
758
  * Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
763
759
  */
@@ -773,9 +769,8 @@ export class AbstractGraph extends IterableEntryBase {
773
769
  * Not support graph with negative weight cycle
774
770
  * all pairs
775
771
  * The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edgeMap, and it can simultaneously compute shortest paths between any two nodes.
776
- * /
777
-
778
- /**
772
+ */
773
+ /**
779
774
  * Time Complexity: O(V^3) - Cubic time (Floyd-Warshall algorithm).
780
775
  * Space Complexity: O(V^2) - Quadratic space (Floyd-Warshall algorithm).
781
776
  *
@@ -8,20 +8,21 @@
8
8
  import type { EntryCallback, HashMapLinkedNode, HashMapOptions, HashMapStoreItem, LinkedHashMapOptions } from '../../types';
9
9
  import { IterableEntryBase } from '../base';
10
10
  /**
11
- * 1. Key-Value Pair Storage: HashMap stores key-value pairs. Each key maps to a value.
11
+ * 1. Key-Value Pair Storage: HashMap stores key-value pairs. Each key map to a value.
12
12
  * 2. Fast Lookup: It's used when you need to quickly find, insert, or delete entries based on a key.
13
- * 3. Unique Keys: Keys are unique. If you try to insert another entry with the same key, the old entry will be replaced by the new one.
13
+ * 3. Unique Keys: Keys are unique.
14
+ * If you try to insert another entry with the same key, the new one will replace the old entry.
14
15
  * 4. Unordered Collection: HashMap does not guarantee the order of entries, and the order may change over time.
15
16
  */
16
17
  export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K, V> {
17
18
  /**
18
19
  * The constructor function initializes a HashMap object with an optional initial collection and
19
20
  * options.
20
- * @param rawCollection - The `rawCollection` parameter is an iterable collection of elements of type
21
+ * @param entryOrRawElements - The `entryOrRawElements` parameter is an iterable collection of elements of a type
21
22
  * `T`. It is an optional parameter and its default value is an empty array `[]`.
22
23
  * @param [options] - The `options` parameter is an optional object that can contain two properties:
23
24
  */
24
- constructor(rawCollection?: Iterable<R | [K, V]>, options?: HashMapOptions<K, V, R>);
25
+ constructor(entryOrRawElements?: Iterable<R | [K, V]>, options?: HashMapOptions<K, V, R>);
25
26
  protected _store: {
26
27
  [key: string]: HashMapStoreItem<K, V>;
27
28
  };
@@ -40,12 +41,12 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
40
41
  * `object` and values of type `V`.
41
42
  */
42
43
  get objMap(): Map<object, V>;
43
- protected _toEntryFn: (rawElement: R) => [K, V];
44
+ protected _toEntryFn?: (rawElement: R) => [K, V];
44
45
  /**
45
46
  * The function returns the value of the _toEntryFn property.
46
47
  * @returns The function being returned is `this._toEntryFn`.
47
48
  */
48
- get toEntryFn(): (rawElement: R) => [K, V];
49
+ get toEntryFn(): ((rawElement: R) => [K, V]) | undefined;
49
50
  protected _size: number;
50
51
  /**
51
52
  * The function returns the size of an object.
@@ -90,11 +91,11 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
90
91
  /**
91
92
  * The function `setMany` takes an iterable collection of objects, maps each object to a key-value
92
93
  * pair using a mapping function, and sets each key-value pair in the current object.
93
- * @param rawCollection - The `rawCollection` parameter is an iterable collection of elements of type
94
+ * @param entryOrRawElements - The `entryOrRawElements` parameter is an iterable collection of elements of a type
94
95
  * `T`.
95
96
  * @returns The `setMany` function is returning an array of booleans.
96
97
  */
97
- setMany(rawCollection: Iterable<R | [K, V]>): boolean[];
98
+ setMany(entryOrRawElements: Iterable<R | [K, V]>): boolean[];
98
99
  /**
99
100
  * The `get` function retrieves a value from a map based on a given key, either from an object map or
100
101
  * a string map.
@@ -149,7 +150,7 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
149
150
  * @returns The `map` method is returning a new `HashMap` object with the transformed values based on
150
151
  * the provided callback function.
151
152
  */
152
- map<U>(callbackfn: EntryCallback<K, V, U>, thisArg?: any): HashMap<K, U>;
153
+ map<VM>(callbackfn: EntryCallback<K, V, VM>, thisArg?: any): HashMap<K, VM>;
153
154
  /**
154
155
  * Time Complexity: O(n)
155
156
  * Space Complexity: O(n)
@@ -205,14 +206,14 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
205
206
  protected readonly _sentinel: HashMapLinkedNode<K, V | undefined>;
206
207
  /**
207
208
  * The constructor initializes a LinkedHashMap object with an optional raw collection and options.
208
- * @param rawCollection - The `rawCollection` parameter is an iterable collection of elements. It is
209
+ * @param entryOrRawElements - The `entryOrRawElements` parameter is an iterable collection of elements. It is
209
210
  * used to initialize the HashMapLinked instance with key-value pairs. Each element in the
210
- * `rawCollection` is converted to a key-value pair using the `toEntryFn` function (if provided) and
211
+ * `entryOrRawElements` is converted to a key-value pair using the `toEntryFn` function (if provided) and
211
212
  * then added to the HashMap
212
213
  * @param [options] - The `options` parameter is an optional object that can contain the following
213
214
  * properties:
214
215
  */
215
- constructor(rawCollection?: Iterable<R>, options?: LinkedHashMapOptions<K, V, R>);
216
+ constructor(entryOrRawElements?: Iterable<R>, options?: LinkedHashMapOptions<K, V, R>);
216
217
  protected _hashFn: (key: K) => string;
217
218
  /**
218
219
  * The function returns the hash function used for generating a hash value for a given key.
@@ -243,7 +244,7 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
243
244
  /**
244
245
  * The function returns the head node of a HashMapLinkedNode.
245
246
  * @returns The method `getHead()` is returning a `HashMapLinkedNode` object with key type `K` and
246
- * value type `V | undefined`.
247
+ * a value type `V | undefined`.
247
248
  */
248
249
  get head(): HashMapLinkedNode<K, V | undefined>;
249
250
  protected _tail: HashMapLinkedNode<K, V | undefined>;
@@ -320,11 +321,11 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
320
321
  * The function `setMany` takes an iterable collection, converts each element into a key-value pair
321
322
  * using a provided function, and sets each key-value pair in the current object, returning an array
322
323
  * of booleans indicating the success of each set operation.
323
- * @param rawCollection - The rawCollection parameter is an iterable collection of elements of type
324
+ * @param entryOrRawElements - The entryOrRawElements parameter is an iterable collection of elements of type
324
325
  * R.
325
326
  * @returns The `setMany` function returns an array of booleans.
326
327
  */
327
- setMany(rawCollection: Iterable<R>): boolean[];
328
+ setMany(entryOrRawElements: Iterable<R>): boolean[];
328
329
  /**
329
330
  * The function checks if a given key exists in a map, using different logic depending on whether the
330
331
  * key is a weak key or not.
@@ -353,9 +354,8 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
353
354
  /**
354
355
  * Time Complexity: O(n)
355
356
  * Space Complexity: O(1)
356
- * /
357
-
358
- /**
357
+ */
358
+ /**
359
359
  * Time Complexity: O(n)
360
360
  * Space Complexity: O(1)
361
361
  *
@@ -370,9 +370,8 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
370
370
  /**
371
371
  * Time Complexity: O(1)
372
372
  * Space Complexity: O(1)
373
- * /
374
-
375
- /**
373
+ */
374
+ /**
376
375
  * Time Complexity: O(1)
377
376
  * Space Complexity: O(1)
378
377
  *
@@ -386,9 +385,8 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
386
385
  /**
387
386
  * Time Complexity: O(n)
388
387
  * Space Complexity: O(1)
389
- * /
390
-
391
- /**
388
+ */
389
+ /**
392
390
  * Time Complexity: O(n)
393
391
  * Space Complexity: O(1)
394
392
  *
@@ -401,9 +399,8 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
401
399
  /**
402
400
  * Time Complexity: O(1)
403
401
  * Space Complexity: O(1)
404
- * /
405
-
406
- /**
402
+ */
403
+ /**
407
404
  * Time Complexity: O(1)
408
405
  * Space Complexity: O(1)
409
406
  *
@@ -422,9 +419,8 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
422
419
  /**
423
420
  * Time Complexity: O(1)
424
421
  * Space Complexity: O(1)
425
- * /
426
-
427
- /**
422
+ */
423
+ /**
428
424
  * Time Complexity: O(1)
429
425
  * Space Complexity: O(1)
430
426
  *
@@ -448,9 +444,8 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
448
444
  /**
449
445
  * Time Complexity: O(n)
450
446
  * Space Complexity: O(n)
451
- * /
452
-
453
- /**
447
+ */
448
+ /**
454
449
  * Time Complexity: O(n)
455
450
  * Space Complexity: O(n)
456
451
  *
@@ -469,9 +464,8 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
469
464
  /**
470
465
  * Time Complexity: O(n)
471
466
  * Space Complexity: O(n)
472
- * /
473
-
474
- /**
467
+ */
468
+ /**
475
469
  * Time Complexity: O(n)
476
470
  * Space Complexity: O(n)
477
471
  *
@@ -488,7 +482,7 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
488
482
  * @returns a new `LinkedHashMap` object with the values mapped according to the provided callback
489
483
  * function.
490
484
  */
491
- map<NV>(callback: EntryCallback<K, V, NV>, thisArg?: any): LinkedHashMap<K, NV>;
485
+ map<VM>(callback: EntryCallback<K, V, VM>, thisArg?: any): LinkedHashMap<K, VM>;
492
486
  /**
493
487
  * Time Complexity: O(1)
494
488
  * Space Complexity: O(1)
@@ -509,9 +503,8 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
509
503
  * Time Complexity: O(n)
510
504
  * Space Complexity: O(1)
511
505
  * where n is the number of entries in the LinkedHashMap.
512
- * /
513
-
514
- /**
506
+ */
507
+ /**
515
508
  * Time Complexity: O(n)
516
509
  * Space Complexity: O(1)
517
510
  * where n is the number of entries in the LinkedHashMap.
@@ -1,20 +1,21 @@
1
1
  import { IterableEntryBase } from '../base';
2
2
  import { isWeakKey, rangeCheck } from '../../utils';
3
3
  /**
4
- * 1. Key-Value Pair Storage: HashMap stores key-value pairs. Each key maps to a value.
4
+ * 1. Key-Value Pair Storage: HashMap stores key-value pairs. Each key map to a value.
5
5
  * 2. Fast Lookup: It's used when you need to quickly find, insert, or delete entries based on a key.
6
- * 3. Unique Keys: Keys are unique. If you try to insert another entry with the same key, the old entry will be replaced by the new one.
6
+ * 3. Unique Keys: Keys are unique.
7
+ * If you try to insert another entry with the same key, the new one will replace the old entry.
7
8
  * 4. Unordered Collection: HashMap does not guarantee the order of entries, and the order may change over time.
8
9
  */
9
10
  export class HashMap extends IterableEntryBase {
10
11
  /**
11
12
  * The constructor function initializes a HashMap object with an optional initial collection and
12
13
  * options.
13
- * @param rawCollection - The `rawCollection` parameter is an iterable collection of elements of type
14
+ * @param entryOrRawElements - The `entryOrRawElements` parameter is an iterable collection of elements of a type
14
15
  * `T`. It is an optional parameter and its default value is an empty array `[]`.
15
16
  * @param [options] - The `options` parameter is an optional object that can contain two properties:
16
17
  */
17
- constructor(rawCollection = [], options) {
18
+ constructor(entryOrRawElements = [], options) {
18
19
  super();
19
20
  if (options) {
20
21
  const { hashFn, toEntryFn } = options;
@@ -25,8 +26,8 @@ export class HashMap extends IterableEntryBase {
25
26
  this._toEntryFn = toEntryFn;
26
27
  }
27
28
  }
28
- if (rawCollection) {
29
- this.setMany(rawCollection);
29
+ if (entryOrRawElements) {
30
+ this.setMany(entryOrRawElements);
30
31
  }
31
32
  }
32
33
  _store = {};
@@ -47,15 +48,7 @@ export class HashMap extends IterableEntryBase {
47
48
  get objMap() {
48
49
  return this._objMap;
49
50
  }
50
- _toEntryFn = (rawElement) => {
51
- if (this.isEntry(rawElement)) {
52
- // TODO, For performance optimization, it may be necessary to only inspect the first element traversed.
53
- return rawElement;
54
- }
55
- else {
56
- throw new Error("If the provided rawCollection does not adhere to the [key, value] type format, the toEntryFn in the constructor's options parameter needs to specified.");
57
- }
58
- };
51
+ _toEntryFn;
59
52
  /**
60
53
  * The function returns the value of the _toEntryFn property.
61
54
  * @returns The function being returned is `this._toEntryFn`.
@@ -134,24 +127,25 @@ export class HashMap extends IterableEntryBase {
134
127
  /**
135
128
  * The function `setMany` takes an iterable collection of objects, maps each object to a key-value
136
129
  * pair using a mapping function, and sets each key-value pair in the current object.
137
- * @param rawCollection - The `rawCollection` parameter is an iterable collection of elements of type
130
+ * @param entryOrRawElements - The `entryOrRawElements` parameter is an iterable collection of elements of a type
138
131
  * `T`.
139
132
  * @returns The `setMany` function is returning an array of booleans.
140
133
  */
141
- setMany(rawCollection) {
134
+ setMany(entryOrRawElements) {
142
135
  const results = [];
143
- for (const rawEle of rawCollection) {
136
+ for (const rawEle of entryOrRawElements) {
144
137
  let key, value;
145
138
  if (this.isEntry(rawEle)) {
146
139
  key = rawEle[0];
147
140
  value = rawEle[1];
148
141
  }
149
- else {
142
+ else if (this.toEntryFn) {
150
143
  const item = this.toEntryFn(rawEle);
151
144
  key = item[0];
152
145
  value = item[1];
153
146
  }
154
- results.push(this.set(key, value));
147
+ if (key !== undefined && value !== undefined)
148
+ results.push(this.set(key, value));
155
149
  }
156
150
  return results;
157
151
  }
@@ -343,14 +337,14 @@ export class LinkedHashMap extends IterableEntryBase {
343
337
  _sentinel;
344
338
  /**
345
339
  * The constructor initializes a LinkedHashMap object with an optional raw collection and options.
346
- * @param rawCollection - The `rawCollection` parameter is an iterable collection of elements. It is
340
+ * @param entryOrRawElements - The `entryOrRawElements` parameter is an iterable collection of elements. It is
347
341
  * used to initialize the HashMapLinked instance with key-value pairs. Each element in the
348
- * `rawCollection` is converted to a key-value pair using the `toEntryFn` function (if provided) and
342
+ * `entryOrRawElements` is converted to a key-value pair using the `toEntryFn` function (if provided) and
349
343
  * then added to the HashMap
350
344
  * @param [options] - The `options` parameter is an optional object that can contain the following
351
345
  * properties:
352
346
  */
353
- constructor(rawCollection = [], options) {
347
+ constructor(entryOrRawElements = [], options) {
354
348
  super();
355
349
  this._sentinel = {};
356
350
  this._sentinel.prev = this._sentinel.next = this._head = this._tail = this._sentinel;
@@ -364,8 +358,8 @@ export class LinkedHashMap extends IterableEntryBase {
364
358
  this._toEntryFn = toEntryFn;
365
359
  }
366
360
  }
367
- if (rawCollection) {
368
- for (const el of rawCollection) {
361
+ if (entryOrRawElements) {
362
+ for (const el of entryOrRawElements) {
369
363
  const [key, value] = this.toEntryFn(el);
370
364
  this.set(key, value);
371
365
  }
@@ -409,7 +403,7 @@ export class LinkedHashMap extends IterableEntryBase {
409
403
  /**
410
404
  * The function returns the head node of a HashMapLinkedNode.
411
405
  * @returns The method `getHead()` is returning a `HashMapLinkedNode` object with key type `K` and
412
- * value type `V | undefined`.
406
+ * a value type `V | undefined`.
413
407
  */
414
408
  get head() {
415
409
  return this._head;
@@ -428,7 +422,7 @@ export class LinkedHashMap extends IterableEntryBase {
428
422
  return rawElement;
429
423
  }
430
424
  else {
431
- throw new Error("If the provided rawCollection does not adhere to the [key, value] type format, the toEntryFn in the constructor's options parameter needs to specified.");
425
+ throw new Error("If the provided entryOrRawElements does not adhere to the [key, value] type format, the toEntryFn in the constructor's options parameter needs to specified.");
432
426
  }
433
427
  };
434
428
  /**
@@ -524,7 +518,7 @@ export class LinkedHashMap extends IterableEntryBase {
524
518
  const hash = this.objHashFn(key);
525
519
  node = this.objMap.get(hash);
526
520
  if (!node && isNewKey) {
527
- // Create new node
521
+ // Create a new node
528
522
  node = { key: hash, value, prev: this.tail, next: this._sentinel };
529
523
  this.objMap.set(hash, node);
530
524
  }
@@ -564,13 +558,13 @@ export class LinkedHashMap extends IterableEntryBase {
564
558
  * The function `setMany` takes an iterable collection, converts each element into a key-value pair
565
559
  * using a provided function, and sets each key-value pair in the current object, returning an array
566
560
  * of booleans indicating the success of each set operation.
567
- * @param rawCollection - The rawCollection parameter is an iterable collection of elements of type
561
+ * @param entryOrRawElements - The entryOrRawElements parameter is an iterable collection of elements of type
568
562
  * R.
569
563
  * @returns The `setMany` function returns an array of booleans.
570
564
  */
571
- setMany(rawCollection) {
565
+ setMany(entryOrRawElements) {
572
566
  const results = [];
573
- for (const rawEle of rawCollection) {
567
+ for (const rawEle of entryOrRawElements) {
574
568
  const [key, value] = this.toEntryFn(rawEle);
575
569
  results.push(this.set(key, value));
576
570
  }
@@ -624,9 +618,8 @@ export class LinkedHashMap extends IterableEntryBase {
624
618
  /**
625
619
  * Time Complexity: O(n)
626
620
  * Space Complexity: O(1)
627
- * /
628
-
629
- /**
621
+ */
622
+ /**
630
623
  * Time Complexity: O(n)
631
624
  * Space Complexity: O(1)
632
625
  *
@@ -648,9 +641,8 @@ export class LinkedHashMap extends IterableEntryBase {
648
641
  /**
649
642
  * Time Complexity: O(1)
650
643
  * Space Complexity: O(1)
651
- * /
652
-
653
- /**
644
+ */
645
+ /**
654
646
  * Time Complexity: O(1)
655
647
  * Space Complexity: O(1)
656
648
  *
@@ -689,9 +681,8 @@ export class LinkedHashMap extends IterableEntryBase {
689
681
  /**
690
682
  * Time Complexity: O(n)
691
683
  * Space Complexity: O(1)
692
- * /
693
-
694
- /**
684
+ */
685
+ /**
695
686
  * Time Complexity: O(n)
696
687
  * Space Complexity: O(1)
697
688
  *
@@ -711,9 +702,8 @@ export class LinkedHashMap extends IterableEntryBase {
711
702
  /**
712
703
  * Time Complexity: O(1)
713
704
  * Space Complexity: O(1)
714
- * /
715
-
716
- /**
705
+ */
706
+ /**
717
707
  * Time Complexity: O(1)
718
708
  * Space Complexity: O(1)
719
709
  *
@@ -736,9 +726,8 @@ export class LinkedHashMap extends IterableEntryBase {
736
726
  /**
737
727
  * Time Complexity: O(1)
738
728
  * Space Complexity: O(1)
739
- * /
740
-
741
- /**
729
+ */
730
+ /**
742
731
  * Time Complexity: O(1)
743
732
  * Space Complexity: O(1)
744
733
  *
@@ -773,9 +762,8 @@ export class LinkedHashMap extends IterableEntryBase {
773
762
  /**
774
763
  * Time Complexity: O(n)
775
764
  * Space Complexity: O(n)
776
- * /
777
-
778
- /**
765
+ */
766
+ /**
779
767
  * Time Complexity: O(n)
780
768
  * Space Complexity: O(n)
781
769
  *
@@ -804,9 +792,8 @@ export class LinkedHashMap extends IterableEntryBase {
804
792
  /**
805
793
  * Time Complexity: O(n)
806
794
  * Space Complexity: O(n)
807
- * /
808
-
809
- /**
795
+ */
796
+ /**
810
797
  * Time Complexity: O(n)
811
798
  * Space Complexity: O(n)
812
799
  *
@@ -855,9 +842,8 @@ export class LinkedHashMap extends IterableEntryBase {
855
842
  * Time Complexity: O(n)
856
843
  * Space Complexity: O(1)
857
844
  * where n is the number of entries in the LinkedHashMap.
858
- * /
859
-
860
- /**
845
+ */
846
+ /**
861
847
  * Time Complexity: O(n)
862
848
  * Space Complexity: O(1)
863
849
  * where n is the number of entries in the LinkedHashMap.