data-structure-typed 1.50.0 → 1.50.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 (156) hide show
  1. package/CHANGELOG.md +2 -1
  2. package/README.md +204 -212
  3. package/benchmark/report.html +37 -1
  4. package/benchmark/report.json +370 -22
  5. package/dist/cjs/data-structures/base/iterable-base.d.ts +114 -9
  6. package/dist/cjs/data-structures/base/iterable-base.js +143 -7
  7. package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
  8. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +43 -46
  9. package/dist/cjs/data-structures/binary-tree/avl-tree.js +68 -71
  10. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  11. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +244 -199
  12. package/dist/cjs/data-structures/binary-tree/binary-tree.js +484 -376
  13. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  14. package/dist/cjs/data-structures/binary-tree/bst.d.ts +54 -74
  15. package/dist/cjs/data-structures/binary-tree/bst.js +30 -71
  16. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  17. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +78 -60
  18. package/dist/cjs/data-structures/binary-tree/rb-tree.js +84 -89
  19. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  20. package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +37 -56
  21. package/dist/cjs/data-structures/binary-tree/tree-multimap.js +64 -85
  22. package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
  23. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +1 -0
  24. package/dist/cjs/data-structures/graph/abstract-graph.js +3 -0
  25. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  26. package/dist/cjs/data-structures/graph/directed-graph.d.ts +14 -0
  27. package/dist/cjs/data-structures/graph/directed-graph.js +26 -0
  28. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  29. package/dist/cjs/data-structures/graph/map-graph.d.ts +8 -0
  30. package/dist/cjs/data-structures/graph/map-graph.js +14 -0
  31. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
  32. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +16 -0
  33. package/dist/cjs/data-structures/graph/undirected-graph.js +25 -0
  34. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  35. package/dist/cjs/data-structures/hash/hash-map.d.ts +121 -15
  36. package/dist/cjs/data-structures/hash/hash-map.js +160 -25
  37. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  38. package/dist/cjs/data-structures/heap/heap.d.ts +66 -6
  39. package/dist/cjs/data-structures/heap/heap.js +66 -6
  40. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  41. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +67 -50
  42. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +70 -64
  43. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  44. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +128 -103
  45. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +130 -112
  46. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  47. package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +63 -36
  48. package/dist/cjs/data-structures/linked-list/skip-linked-list.js +63 -36
  49. package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
  50. package/dist/cjs/data-structures/matrix/matrix.d.ts +35 -4
  51. package/dist/cjs/data-structures/matrix/matrix.js +50 -11
  52. package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
  53. package/dist/cjs/data-structures/queue/deque.d.ts +49 -19
  54. package/dist/cjs/data-structures/queue/deque.js +101 -47
  55. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  56. package/dist/cjs/data-structures/queue/queue.d.ts +39 -5
  57. package/dist/cjs/data-structures/queue/queue.js +47 -5
  58. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  59. package/dist/cjs/data-structures/stack/stack.d.ts +16 -0
  60. package/dist/cjs/data-structures/stack/stack.js +22 -0
  61. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  62. package/dist/cjs/data-structures/trie/trie.d.ts +38 -1
  63. package/dist/cjs/data-structures/trie/trie.js +41 -0
  64. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  65. package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
  66. package/dist/cjs/types/data-structures/hash/hash-map.d.ts +4 -3
  67. package/dist/cjs/types/utils/utils.d.ts +1 -0
  68. package/dist/mjs/data-structures/base/iterable-base.d.ts +114 -9
  69. package/dist/mjs/data-structures/base/iterable-base.js +143 -7
  70. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +43 -46
  71. package/dist/mjs/data-structures/binary-tree/avl-tree.js +68 -71
  72. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +244 -199
  73. package/dist/mjs/data-structures/binary-tree/binary-tree.js +483 -375
  74. package/dist/mjs/data-structures/binary-tree/bst.d.ts +54 -74
  75. package/dist/mjs/data-structures/binary-tree/bst.js +30 -71
  76. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +78 -60
  77. package/dist/mjs/data-structures/binary-tree/rb-tree.js +84 -89
  78. package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +37 -56
  79. package/dist/mjs/data-structures/binary-tree/tree-multimap.js +64 -85
  80. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +1 -0
  81. package/dist/mjs/data-structures/graph/abstract-graph.js +3 -0
  82. package/dist/mjs/data-structures/graph/directed-graph.d.ts +14 -0
  83. package/dist/mjs/data-structures/graph/directed-graph.js +26 -0
  84. package/dist/mjs/data-structures/graph/map-graph.d.ts +8 -0
  85. package/dist/mjs/data-structures/graph/map-graph.js +14 -0
  86. package/dist/mjs/data-structures/graph/undirected-graph.d.ts +16 -0
  87. package/dist/mjs/data-structures/graph/undirected-graph.js +25 -0
  88. package/dist/mjs/data-structures/hash/hash-map.d.ts +121 -15
  89. package/dist/mjs/data-structures/hash/hash-map.js +160 -25
  90. package/dist/mjs/data-structures/heap/heap.d.ts +66 -6
  91. package/dist/mjs/data-structures/heap/heap.js +66 -6
  92. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +67 -50
  93. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +70 -64
  94. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +128 -103
  95. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +130 -112
  96. package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +63 -36
  97. package/dist/mjs/data-structures/linked-list/skip-linked-list.js +63 -36
  98. package/dist/mjs/data-structures/matrix/matrix.d.ts +35 -4
  99. package/dist/mjs/data-structures/matrix/matrix.js +50 -11
  100. package/dist/mjs/data-structures/queue/deque.d.ts +49 -19
  101. package/dist/mjs/data-structures/queue/deque.js +101 -47
  102. package/dist/mjs/data-structures/queue/queue.d.ts +39 -5
  103. package/dist/mjs/data-structures/queue/queue.js +47 -5
  104. package/dist/mjs/data-structures/stack/stack.d.ts +16 -0
  105. package/dist/mjs/data-structures/stack/stack.js +22 -0
  106. package/dist/mjs/data-structures/trie/trie.d.ts +38 -1
  107. package/dist/mjs/data-structures/trie/trie.js +41 -0
  108. package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
  109. package/dist/mjs/types/data-structures/hash/hash-map.d.ts +4 -3
  110. package/dist/mjs/types/utils/utils.d.ts +1 -0
  111. package/dist/umd/data-structure-typed.js +1730 -1042
  112. package/dist/umd/data-structure-typed.min.js +3 -3
  113. package/dist/umd/data-structure-typed.min.js.map +1 -1
  114. package/package.json +16 -40
  115. package/src/data-structures/base/iterable-base.ts +172 -19
  116. package/src/data-structures/binary-tree/avl-tree.ts +97 -97
  117. package/src/data-structures/binary-tree/binary-tree.ts +674 -671
  118. package/src/data-structures/binary-tree/bst.ts +89 -131
  119. package/src/data-structures/binary-tree/rb-tree.ts +127 -155
  120. package/src/data-structures/binary-tree/tree-multimap.ts +96 -112
  121. package/src/data-structures/graph/abstract-graph.ts +4 -0
  122. package/src/data-structures/graph/directed-graph.ts +30 -0
  123. package/src/data-structures/graph/map-graph.ts +15 -0
  124. package/src/data-structures/graph/undirected-graph.ts +28 -0
  125. package/src/data-structures/hash/hash-map.ts +175 -34
  126. package/src/data-structures/heap/heap.ts +66 -6
  127. package/src/data-structures/linked-list/doubly-linked-list.ts +72 -66
  128. package/src/data-structures/linked-list/singly-linked-list.ts +132 -114
  129. package/src/data-structures/linked-list/skip-linked-list.ts +63 -37
  130. package/src/data-structures/matrix/matrix.ts +52 -12
  131. package/src/data-structures/queue/deque.ts +108 -49
  132. package/src/data-structures/queue/queue.ts +51 -5
  133. package/src/data-structures/stack/stack.ts +24 -0
  134. package/src/data-structures/trie/trie.ts +45 -1
  135. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
  136. package/src/types/data-structures/hash/hash-map.ts +4 -3
  137. package/src/types/utils/utils.ts +2 -0
  138. package/test/performance/data-structures/graph/directed-graph.test.ts +3 -3
  139. package/test/performance/data-structures/queue/deque.test.ts +26 -25
  140. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +37 -0
  141. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +46 -17
  142. package/test/unit/data-structures/binary-tree/bst.test.ts +65 -1
  143. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +38 -1
  144. package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +37 -32
  145. package/test/unit/data-structures/graph/abstract-graph.test.ts +8 -0
  146. package/test/unit/data-structures/graph/directed-graph.test.ts +249 -0
  147. package/test/unit/data-structures/hash/hash-map.test.ts +376 -353
  148. package/test/unit/data-structures/heap/heap.test.ts +18 -1
  149. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +24 -5
  150. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +20 -2
  151. package/test/unit/data-structures/linked-list/skip-list.test.ts +1 -1
  152. package/test/unit/data-structures/queue/deque.test.ts +71 -10
  153. package/test/unit/data-structures/queue/queue.test.ts +23 -6
  154. package/test/unit/data-structures/stack/stack.test.ts +17 -0
  155. package/test/unit/data-structures/trie/trie.test.ts +17 -0
  156. package/test/unit/unrestricted-interconversion.test.ts +143 -10
@@ -25,13 +25,42 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
25
25
  * `T`. It is an optional parameter and its default value is an empty array `[]`.
26
26
  * @param [options] - The `options` parameter is an optional object that can contain two properties:
27
27
  */
28
- constructor(rawCollection?: Iterable<R>, options?: HashMapOptions<K, V, R>);
28
+ constructor(rawCollection?: Iterable<R | [K, V]>, options?: HashMapOptions<K, V, R>);
29
29
  protected _toEntryFn: (rawElement: R) => [K, V];
30
+ /**
31
+ * The function returns the value of the _toEntryFn property.
32
+ * @returns The function being returned is `this._toEntryFn`.
33
+ */
30
34
  get toEntryFn(): (rawElement: R) => [K, V];
35
+ /**
36
+ * The hasFn function is a function that takes in an item and returns a boolean
37
+ * indicating whether the item is contained within the hash table.
38
+ *
39
+ * @return The hash function
40
+ */
41
+ get hasFn(): (key: K) => string;
31
42
  protected _size: number;
43
+ /**
44
+ * The function returns the size of an object.
45
+ * @returns The size of the object, which is a number.
46
+ */
32
47
  get size(): number;
48
+ /**
49
+ * The function checks if a given element is an array with exactly two elements.
50
+ * @param {any} rawElement - The `rawElement` parameter is of type `any`, which means it can be any
51
+ * data type.
52
+ * @returns a boolean value.
53
+ */
33
54
  isEntry(rawElement: any): rawElement is [K, V];
55
+ /**
56
+ * The function checks if the size of an object is equal to zero and returns a boolean value.
57
+ * @returns A boolean value indicating whether the size of the object is 0 or not.
58
+ */
34
59
  isEmpty(): boolean;
60
+ /**
61
+ * The clear() function resets the state of an object by clearing its internal store, object map, and
62
+ * size.
63
+ */
35
64
  clear(): void;
36
65
  /**
37
66
  * The `set` function adds a key-value pair to a map-like data structure, incrementing the size if
@@ -50,7 +79,7 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
50
79
  * `T`.
51
80
  * @returns The `setMany` function is returning an array of booleans.
52
81
  */
53
- setMany(rawCollection: Iterable<R>): boolean[];
82
+ setMany(rawCollection: Iterable<R | [K, V]>): boolean[];
54
83
  /**
55
84
  * The `get` function retrieves a value from a map based on a given key, either from an object map or
56
85
  * a string map.
@@ -75,6 +104,14 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
75
104
  * successfully deleted from the map, and `false` if the key was not found in the map.
76
105
  */
77
106
  delete(key: K): boolean;
107
+ /**
108
+ * The clone function creates a new HashMap with the same key-value pairs as
109
+ * this one. The clone function is useful for creating a copy of an existing
110
+ * HashMap, and then modifying that copy without affecting the original.
111
+ *
112
+ * @return A new hashmap with the same values as this one
113
+ */
114
+ clone(): HashMap<K, V, R>;
78
115
  /**
79
116
  * Time Complexity: O(n)
80
117
  * Space Complexity: O(n)
@@ -115,6 +152,14 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
115
152
  * from the original `HashMap` that pass the provided `predicate` function.
116
153
  */
117
154
  filter(predicate: EntryCallback<K, V, boolean>, thisArg?: any): HashMap<K, V>;
155
+ /**
156
+ * The put function sets a value in a data structure using a specified key.
157
+ * @param {K} key - The key parameter is of type K, which represents the type of the key being passed
158
+ * to the function.
159
+ * @param {V} value - The value parameter represents the value that you want to associate with the
160
+ * specified key in the data structure.
161
+ * @returns The method is returning a boolean value.
162
+ */
118
163
  put(key: K, value: V): boolean;
119
164
  /**
120
165
  * The function returns an iterator that yields key-value pairs from both an object store and an
@@ -130,14 +175,33 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
130
175
  * 2. Based on Hash Table and Linked List: It combines the structures of a hash table and a linked list, using the hash table to ensure fast access, while maintaining the order of entries through the linked list.
131
176
  * 3. Time Complexity: Similar to HashMap, LinkedHashMap offers constant-time performance for get and put operations in most cases.
132
177
  */
133
- export declare class LinkedHashMap<K = any, V = any> extends IterableEntryBase<K, V> {
178
+ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K, V> {
134
179
  protected _noObjMap: Record<string, HashMapLinkedNode<K, V | undefined>>;
135
180
  protected _objMap: WeakMap<object, HashMapLinkedNode<K, V | undefined>>;
136
181
  protected _head: HashMapLinkedNode<K, V | undefined>;
137
182
  protected _tail: HashMapLinkedNode<K, V | undefined>;
138
183
  protected readonly _sentinel: HashMapLinkedNode<K, V | undefined>;
139
- constructor(entries?: Iterable<[K, V]>, options?: LinkedHashMapOptions<K>);
184
+ /**
185
+ * The constructor initializes a LinkedHashMap object with an optional raw collection and options.
186
+ * @param rawCollection - The `rawCollection` parameter is an iterable collection of elements. It is
187
+ * used to initialize the HashMapLinked instance with key-value pairs. Each element in the
188
+ * `rawCollection` is converted to a key-value pair using the `toEntryFn` function (if provided) and
189
+ * then added to the HashMap
190
+ * @param [options] - The `options` parameter is an optional object that can contain the following
191
+ * properties:
192
+ */
193
+ constructor(rawCollection?: Iterable<R>, options?: LinkedHashMapOptions<K, V, R>);
194
+ protected _toEntryFn: (rawElement: R) => [K, V];
195
+ /**
196
+ * The function returns the value of the _toEntryFn property.
197
+ * @returns The function being returned is `this._toEntryFn`.
198
+ */
199
+ get toEntryFn(): (rawElement: R) => [K, V];
140
200
  protected _size: number;
201
+ /**
202
+ * The function returns the size of an object.
203
+ * @returns The size of the object.
204
+ */
141
205
  get size(): number;
142
206
  /**
143
207
  * Time Complexity: O(1)
@@ -179,8 +243,22 @@ export declare class LinkedHashMap<K = any, V = any> extends IterableEntryBase<K
179
243
  * @returns the size of the data structure after the key-value pair has been set.
180
244
  */
181
245
  set(key: K, value?: V): boolean;
246
+ /**
247
+ * The function `setMany` takes an iterable collection, converts each element into a key-value pair
248
+ * using a provided function, and sets each key-value pair in the current object, returning an array
249
+ * of booleans indicating the success of each set operation.
250
+ * @param rawCollection - The rawCollection parameter is an iterable collection of elements of type
251
+ * R.
252
+ * @returns The `setMany` function returns an array of booleans.
253
+ */
254
+ setMany(rawCollection: Iterable<R>): boolean[];
255
+ /**
256
+ * The function checks if a given key exists in a map, using different logic depending on whether the
257
+ * key is a weak key or not.
258
+ * @param {K} key - The `key` parameter is the key that is being checked for existence in the map.
259
+ * @returns The method `has` is returning a boolean value.
260
+ */
182
261
  has(key: K): boolean;
183
- setMany(entries: Iterable<[K, V]>): boolean[];
184
262
  /**
185
263
  * Time Complexity: O(1)
186
264
  * Space Complexity: O(1)
@@ -199,14 +277,14 @@ export declare class LinkedHashMap<K = any, V = any> extends IterableEntryBase<K
199
277
  * Time Complexity: O(n), where n is the index.
200
278
  * Space Complexity: O(1)
201
279
  *
202
- * The function `getAt` retrieves the key-value pair at a specified index in a linked list.
280
+ * The function `at` retrieves the key-value pair at a specified index in a linked list.
203
281
  * @param {number} index - The index parameter is a number that represents the position of the
204
282
  * element we want to retrieve from the data structure.
205
- * @returns The method `getAt(index: number)` is returning an array containing the key-value pair at
283
+ * @returns The method `at(index: number)` is returning an array containing the key-value pair at
206
284
  * the specified index in the data structure. The key-value pair is represented as a tuple `[K, V]`,
207
285
  * where `K` is the key and `V` is the value.
208
286
  */
209
- getAt(index: number): V | undefined;
287
+ at(index: number): V | undefined;
210
288
  /**
211
289
  * Time Complexity: O(1)
212
290
  * Space Complexity: O(1)
@@ -219,7 +297,7 @@ export declare class LinkedHashMap<K = any, V = any> extends IterableEntryBase<K
219
297
  */
220
298
  delete(key: K): boolean;
221
299
  /**
222
- * Time Complexity: O(n), where n is the index.
300
+ * Time Complexity: O(n)
223
301
  * Space Complexity: O(1)
224
302
  *
225
303
  * The `deleteAt` function deletes a node at a specified index in a linked list.
@@ -237,6 +315,13 @@ export declare class LinkedHashMap<K = any, V = any> extends IterableEntryBase<K
237
315
  * not.
238
316
  */
239
317
  isEmpty(): boolean;
318
+ /**
319
+ * The function checks if a given element is an array with exactly two elements.
320
+ * @param {any} rawElement - The `rawElement` parameter is of type `any`, which means it can be any
321
+ * data type.
322
+ * @returns a boolean value.
323
+ */
324
+ isEntry(rawElement: any): rawElement is [K, V];
240
325
  /**
241
326
  * Time Complexity: O(1)
242
327
  * Space Complexity: O(1)
@@ -244,6 +329,19 @@ export declare class LinkedHashMap<K = any, V = any> extends IterableEntryBase<K
244
329
  * The `clear` function clears all the entries in a data structure and resets its properties.
245
330
  */
246
331
  clear(): void;
332
+ /**
333
+ * Time Complexity: O(n)
334
+ * Space Complexity: O(n)
335
+ */
336
+ /**
337
+ * Time Complexity: O(n)
338
+ * Space Complexity: O(n)
339
+ *
340
+ * The `clone` function creates a new instance of a `LinkedHashMap` with the same key-value pairs as
341
+ * the original.
342
+ * @returns The `clone()` method is returning a new instance of `LinkedHashMap<K, V>` that is a clone
343
+ * of the original `LinkedHashMap` object.
344
+ */
247
345
  clone(): LinkedHashMap<K, V>;
248
346
  /**
249
347
  * Time Complexity: O(n)
@@ -280,19 +378,27 @@ export declare class LinkedHashMap<K = any, V = any> extends IterableEntryBase<K
280
378
  */
281
379
  map<NV>(callback: EntryCallback<K, V, NV>, thisArg?: any): LinkedHashMap<K, NV>;
282
380
  /**
283
- * Time Complexity: O(n)
284
- * Space Complexity: O(n)
381
+ * Time Complexity: O(1)
382
+ * Space Complexity: O(1)
285
383
  */
286
- put(key: K, value: V): boolean;
287
384
  /**
288
- * Time Complexity: O(n)
289
- * Space Complexity: O(n)
385
+ * Time Complexity: O(1)
386
+ * Space Complexity: O(1)
387
+ *
388
+ * The put function sets a value in a data structure using a specified key.
389
+ * @param {K} key - The key parameter is of type K, which represents the type of the key being passed
390
+ * to the function.
391
+ * @param {V} value - The value parameter represents the value that you want to associate with the
392
+ * specified key in the data structure.
393
+ * @returns The method is returning a boolean value.
290
394
  */
395
+ put(key: K, value: V): boolean;
291
396
  protected _hashFn: (key: K) => string;
292
397
  protected _objHashFn: (key: K) => object;
293
398
  /**
294
- * Time Complexity: O(n), where n is the number of entries in the LinkedHashMap.
399
+ * Time Complexity: O(n)
295
400
  * Space Complexity: O(1)
401
+ * where n is the number of entries in the LinkedHashMap.
296
402
  *
297
403
  * The above function is an iterator that yields key-value pairs from a linked list.
298
404
  */
@@ -40,19 +40,50 @@ export class HashMap extends IterableEntryBase {
40
40
  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.");
41
41
  }
42
42
  };
43
+ /**
44
+ * The function returns the value of the _toEntryFn property.
45
+ * @returns The function being returned is `this._toEntryFn`.
46
+ */
43
47
  get toEntryFn() {
44
48
  return this._toEntryFn;
45
49
  }
50
+ /**
51
+ * The hasFn function is a function that takes in an item and returns a boolean
52
+ * indicating whether the item is contained within the hash table.
53
+ *
54
+ * @return The hash function
55
+ */
56
+ get hasFn() {
57
+ return this._hashFn;
58
+ }
46
59
  _size = 0;
60
+ /**
61
+ * The function returns the size of an object.
62
+ * @returns The size of the object, which is a number.
63
+ */
47
64
  get size() {
48
65
  return this._size;
49
66
  }
67
+ /**
68
+ * The function checks if a given element is an array with exactly two elements.
69
+ * @param {any} rawElement - The `rawElement` parameter is of type `any`, which means it can be any
70
+ * data type.
71
+ * @returns a boolean value.
72
+ */
50
73
  isEntry(rawElement) {
51
74
  return Array.isArray(rawElement) && rawElement.length === 2;
52
75
  }
76
+ /**
77
+ * The function checks if the size of an object is equal to zero and returns a boolean value.
78
+ * @returns A boolean value indicating whether the size of the object is 0 or not.
79
+ */
53
80
  isEmpty() {
54
81
  return this.size === 0;
55
82
  }
83
+ /**
84
+ * The clear() function resets the state of an object by clearing its internal store, object map, and
85
+ * size.
86
+ */
56
87
  clear() {
57
88
  this._store = {};
58
89
  this._objMap.clear();
@@ -93,7 +124,16 @@ export class HashMap extends IterableEntryBase {
93
124
  setMany(rawCollection) {
94
125
  const results = [];
95
126
  for (const rawEle of rawCollection) {
96
- const [key, value] = this.toEntryFn(rawEle);
127
+ let key, value;
128
+ if (this.isEntry(rawEle)) {
129
+ key = rawEle[0];
130
+ value = rawEle[1];
131
+ }
132
+ else {
133
+ const item = this.toEntryFn(rawEle);
134
+ key = item[0];
135
+ value = item[1];
136
+ }
97
137
  results.push(this.set(key, value));
98
138
  }
99
139
  return results;
@@ -154,6 +194,16 @@ export class HashMap extends IterableEntryBase {
154
194
  return false;
155
195
  }
156
196
  }
197
+ /**
198
+ * The clone function creates a new HashMap with the same key-value pairs as
199
+ * this one. The clone function is useful for creating a copy of an existing
200
+ * HashMap, and then modifying that copy without affecting the original.
201
+ *
202
+ * @return A new hashmap with the same values as this one
203
+ */
204
+ clone() {
205
+ return new HashMap(this, { hashFn: this._hashFn, toEntryFn: this.toEntryFn });
206
+ }
157
207
  /**
158
208
  * Time Complexity: O(n)
159
209
  * Space Complexity: O(n)
@@ -210,6 +260,14 @@ export class HashMap extends IterableEntryBase {
210
260
  }
211
261
  return filteredMap;
212
262
  }
263
+ /**
264
+ * The put function sets a value in a data structure using a specified key.
265
+ * @param {K} key - The key parameter is of type K, which represents the type of the key being passed
266
+ * to the function.
267
+ * @param {V} value - The value parameter represents the value that you want to associate with the
268
+ * specified key in the data structure.
269
+ * @returns The method is returning a boolean value.
270
+ */
213
271
  put(key, value) {
214
272
  return this.set(key, value);
215
273
  }
@@ -259,24 +317,57 @@ export class LinkedHashMap extends IterableEntryBase {
259
317
  _head;
260
318
  _tail;
261
319
  _sentinel;
262
- constructor(entries, options) {
320
+ /**
321
+ * The constructor initializes a LinkedHashMap object with an optional raw collection and options.
322
+ * @param rawCollection - The `rawCollection` parameter is an iterable collection of elements. It is
323
+ * used to initialize the HashMapLinked instance with key-value pairs. Each element in the
324
+ * `rawCollection` is converted to a key-value pair using the `toEntryFn` function (if provided) and
325
+ * then added to the HashMap
326
+ * @param [options] - The `options` parameter is an optional object that can contain the following
327
+ * properties:
328
+ */
329
+ constructor(rawCollection = [], options) {
263
330
  super();
264
331
  this._sentinel = {};
265
332
  this._sentinel.prev = this._sentinel.next = this._head = this._tail = this._sentinel;
266
333
  if (options) {
267
- const { hashFn, objHashFn } = options;
334
+ const { hashFn, objHashFn, toEntryFn } = options;
268
335
  if (hashFn)
269
336
  this._hashFn = hashFn;
270
337
  if (objHashFn)
271
338
  this._objHashFn = objHashFn;
339
+ if (toEntryFn) {
340
+ this._toEntryFn = toEntryFn;
341
+ }
272
342
  }
273
- if (entries) {
274
- for (const el of entries) {
275
- this.set(el[0], el[1]);
343
+ if (rawCollection) {
344
+ for (const el of rawCollection) {
345
+ const [key, value] = this.toEntryFn(el);
346
+ this.set(key, value);
276
347
  }
277
348
  }
278
349
  }
350
+ _toEntryFn = (rawElement) => {
351
+ if (this.isEntry(rawElement)) {
352
+ // TODO, For performance optimization, it may be necessary to only inspect the first element traversed.
353
+ return rawElement;
354
+ }
355
+ else {
356
+ 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.");
357
+ }
358
+ };
359
+ /**
360
+ * The function returns the value of the _toEntryFn property.
361
+ * @returns The function being returned is `this._toEntryFn`.
362
+ */
363
+ get toEntryFn() {
364
+ return this._toEntryFn;
365
+ }
279
366
  _size = 0;
367
+ /**
368
+ * The function returns the size of an object.
369
+ * @returns The size of the object.
370
+ */
280
371
  get size() {
281
372
  return this._size;
282
373
  }
@@ -382,6 +473,28 @@ export class LinkedHashMap extends IterableEntryBase {
382
473
  }
383
474
  return true;
384
475
  }
476
+ /**
477
+ * The function `setMany` takes an iterable collection, converts each element into a key-value pair
478
+ * using a provided function, and sets each key-value pair in the current object, returning an array
479
+ * of booleans indicating the success of each set operation.
480
+ * @param rawCollection - The rawCollection parameter is an iterable collection of elements of type
481
+ * R.
482
+ * @returns The `setMany` function returns an array of booleans.
483
+ */
484
+ setMany(rawCollection) {
485
+ const results = [];
486
+ for (const rawEle of rawCollection) {
487
+ const [key, value] = this.toEntryFn(rawEle);
488
+ results.push(this.set(key, value));
489
+ }
490
+ return results;
491
+ }
492
+ /**
493
+ * The function checks if a given key exists in a map, using different logic depending on whether the
494
+ * key is a weak key or not.
495
+ * @param {K} key - The `key` parameter is the key that is being checked for existence in the map.
496
+ * @returns The method `has` is returning a boolean value.
497
+ */
385
498
  has(key) {
386
499
  if (isWeakKey(key)) {
387
500
  const hash = this._objHashFn(key);
@@ -392,14 +505,6 @@ export class LinkedHashMap extends IterableEntryBase {
392
505
  return hash in this._noObjMap;
393
506
  }
394
507
  }
395
- setMany(entries) {
396
- const results = [];
397
- for (const entry of entries) {
398
- const [key, value] = entry;
399
- results.push(this.set(key, value));
400
- }
401
- return results;
402
- }
403
508
  /**
404
509
  * Time Complexity: O(1)
405
510
  * Space Complexity: O(1)
@@ -429,14 +534,14 @@ export class LinkedHashMap extends IterableEntryBase {
429
534
  * Time Complexity: O(n), where n is the index.
430
535
  * Space Complexity: O(1)
431
536
  *
432
- * The function `getAt` retrieves the key-value pair at a specified index in a linked list.
537
+ * The function `at` retrieves the key-value pair at a specified index in a linked list.
433
538
  * @param {number} index - The index parameter is a number that represents the position of the
434
539
  * element we want to retrieve from the data structure.
435
- * @returns The method `getAt(index: number)` is returning an array containing the key-value pair at
540
+ * @returns The method `at(index: number)` is returning an array containing the key-value pair at
436
541
  * the specified index in the data structure. The key-value pair is represented as a tuple `[K, V]`,
437
542
  * where `K` is the key and `V` is the value.
438
543
  */
439
- getAt(index) {
544
+ at(index) {
440
545
  rangeCheck(index, 0, this._size - 1);
441
546
  let node = this._head;
442
547
  while (index--) {
@@ -481,7 +586,7 @@ export class LinkedHashMap extends IterableEntryBase {
481
586
  return true;
482
587
  }
483
588
  /**
484
- * Time Complexity: O(n), where n is the index.
589
+ * Time Complexity: O(n)
485
590
  * Space Complexity: O(1)
486
591
  *
487
592
  * The `deleteAt` function deletes a node at a specified index in a linked list.
@@ -508,6 +613,15 @@ export class LinkedHashMap extends IterableEntryBase {
508
613
  isEmpty() {
509
614
  return this._size === 0;
510
615
  }
616
+ /**
617
+ * The function checks if a given element is an array with exactly two elements.
618
+ * @param {any} rawElement - The `rawElement` parameter is of type `any`, which means it can be any
619
+ * data type.
620
+ * @returns a boolean value.
621
+ */
622
+ isEntry(rawElement) {
623
+ return Array.isArray(rawElement) && rawElement.length === 2;
624
+ }
511
625
  /**
512
626
  * Time Complexity: O(1)
513
627
  * Space Complexity: O(1)
@@ -519,6 +633,19 @@ export class LinkedHashMap extends IterableEntryBase {
519
633
  this._size = 0;
520
634
  this._head = this._tail = this._sentinel.prev = this._sentinel.next = this._sentinel;
521
635
  }
636
+ /**
637
+ * Time Complexity: O(n)
638
+ * Space Complexity: O(n)
639
+ */
640
+ /**
641
+ * Time Complexity: O(n)
642
+ * Space Complexity: O(n)
643
+ *
644
+ * The `clone` function creates a new instance of a `LinkedHashMap` with the same key-value pairs as
645
+ * the original.
646
+ * @returns The `clone()` method is returning a new instance of `LinkedHashMap<K, V>` that is a clone
647
+ * of the original `LinkedHashMap` object.
648
+ */
522
649
  clone() {
523
650
  const cloned = new LinkedHashMap([], { hashFn: this._hashFn, objHashFn: this._objHashFn });
524
651
  for (const entry of this) {
@@ -581,21 +708,29 @@ export class LinkedHashMap extends IterableEntryBase {
581
708
  return mappedMap;
582
709
  }
583
710
  /**
584
- * Time Complexity: O(n)
585
- * Space Complexity: O(n)
711
+ * Time Complexity: O(1)
712
+ * Space Complexity: O(1)
713
+ */
714
+ /**
715
+ * Time Complexity: O(1)
716
+ * Space Complexity: O(1)
717
+ *
718
+ * The put function sets a value in a data structure using a specified key.
719
+ * @param {K} key - The key parameter is of type K, which represents the type of the key being passed
720
+ * to the function.
721
+ * @param {V} value - The value parameter represents the value that you want to associate with the
722
+ * specified key in the data structure.
723
+ * @returns The method is returning a boolean value.
586
724
  */
587
725
  put(key, value) {
588
726
  return this.set(key, value);
589
727
  }
590
- /**
591
- * Time Complexity: O(n)
592
- * Space Complexity: O(n)
593
- */
594
728
  _hashFn = (key) => String(key);
595
729
  _objHashFn = (key) => key;
596
730
  /**
597
- * Time Complexity: O(n), where n is the number of entries in the LinkedHashMap.
731
+ * Time Complexity: O(n)
598
732
  * Space Complexity: O(1)
733
+ * where n is the number of entries in the LinkedHashMap.
599
734
  *
600
735
  * The above function is an iterator that yields key-value pairs from a linked list.
601
736
  */
@@ -19,10 +19,28 @@ import { IterableElementBase } from '../base';
19
19
  * 8. Graph Algorithms: Such as Dijkstra's shortest path algorithm and Prim's minimum spanning tree algorithm, which use heaps to improve performance.
20
20
  */
21
21
  export declare class Heap<E = any> extends IterableElementBase<E> {
22
+ /**
23
+ * The constructor initializes a heap data structure with optional elements and options.
24
+ * @param elements - The `elements` parameter is an iterable object that contains the initial
25
+ * elements to be added to the heap. It is an optional parameter and if not provided, the heap will
26
+ * be initialized as empty.
27
+ * @param [options] - The `options` parameter is an optional object that can contain additional
28
+ * configuration options for the heap. In this case, it is used to specify a custom comparator
29
+ * function for comparing elements in the heap. The comparator function is used to determine the
30
+ * order of elements in the heap.
31
+ */
22
32
  constructor(elements?: Iterable<E>, options?: HeapOptions<E>);
23
33
  protected _comparator: (a: E, b: E) => number;
34
+ /**
35
+ * The function returns the value of the _comparator property.
36
+ * @returns The `_comparator` property is being returned.
37
+ */
24
38
  get comparator(): (a: E, b: E) => number;
25
39
  protected _elements: E[];
40
+ /**
41
+ * The function returns an array of elements.
42
+ * @returns The elements array is being returned.
43
+ */
26
44
  get elements(): E[];
27
45
  /**
28
46
  * Get the size (number of elements) of the heap.
@@ -43,11 +61,12 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
43
61
  comparator: Comparator<E>;
44
62
  }): Heap<E>;
45
63
  /**
46
- * Time Complexity: O(log n), where n is the number of elements in the heap.
64
+ * Time Complexity: O(log n)
47
65
  * Space Complexity: O(1)
66
+ * where n is the number of elements in the heap.
48
67
  */
49
68
  /**
50
- * Time Complexity: O(log n), where n is the number of elements in the heap.
69
+ * Time Complexity: O(log n)
51
70
  * Space Complexity: O(1)
52
71
  *
53
72
  * Insert an element into the heap and maintain the heap properties.
@@ -55,11 +74,12 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
55
74
  */
56
75
  add(element: E): boolean;
57
76
  /**
58
- * Time Complexity: O(log n), where n is the number of elements in the heap.
77
+ * Time Complexity: O(log n)
59
78
  * Space Complexity: O(1)
79
+ * where n is the number of elements in the heap.
60
80
  */
61
81
  /**
62
- * Time Complexity: O(log n), where n is the number of elements in the heap.
82
+ * Time Complexity: O(log n)
63
83
  * Space Complexity: O(1)
64
84
  *
65
85
  * Remove and return the top element (smallest or largest element) from the heap.
@@ -67,6 +87,9 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
67
87
  */
68
88
  poll(): E | undefined;
69
89
  /**
90
+ * Time Complexity: O(1)
91
+ * Space Complexity: O(1)
92
+ *
70
93
  * Peek at the top element of the heap without removing it.
71
94
  * @returns The top element or undefined if the heap is empty.
72
95
  */
@@ -227,6 +250,9 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
227
250
  * original Heap.
228
251
  */
229
252
  map<T>(callback: ElementCallback<E, T>, comparator: Comparator<T>, thisArg?: any): Heap<T>;
253
+ /**
254
+ * The function `_getIterator` returns an iterable iterator for the elements in the class.
255
+ */
230
256
  protected _getIterator(): IterableIterator<E>;
231
257
  /**
232
258
  * Time Complexity: O(n)
@@ -258,17 +284,51 @@ export declare class FibonacciHeapNode<E> {
258
284
  child?: FibonacciHeapNode<E>;
259
285
  parent?: FibonacciHeapNode<E>;
260
286
  marked: boolean;
287
+ /**
288
+ * The constructor function initializes an object with an element and a degree, and sets the marked
289
+ * property to false.
290
+ * @param {E} element - The "element" parameter represents the value or data that will be stored in
291
+ * the node of a data structure. It can be any type of data, such as a number, string, object, or
292
+ * even another data structure.
293
+ * @param [degree=0] - The degree parameter represents the degree of the element in a data structure
294
+ * called a Fibonacci heap. The degree of a node is the number of children it has. By default, the
295
+ * degree is set to 0 when a new node is created.
296
+ */
261
297
  constructor(element: E, degree?: number);
262
298
  }
263
299
  export declare class FibonacciHeap<E> {
300
+ /**
301
+ * The constructor function initializes a FibonacciHeap object with an optional comparator function.
302
+ * @param [comparator] - The `comparator` parameter is an optional argument that represents a
303
+ * function used to compare elements in the FibonacciHeap. If a comparator function is provided, it
304
+ * will be used to determine the order of elements in the heap. If no comparator function is
305
+ * provided, a default comparator function will be used.
306
+ */
264
307
  constructor(comparator?: Comparator<E>);
265
308
  protected _root?: FibonacciHeapNode<E>;
309
+ /**
310
+ * The function returns the root node of a Fibonacci heap.
311
+ * @returns The method is returning either a FibonacciHeapNode object or undefined.
312
+ */
266
313
  get root(): FibonacciHeapNode<E> | undefined;
267
314
  protected _size: number;
315
+ /**
316
+ * The function returns the size of an object.
317
+ * @returns The size of the object, which is a number.
318
+ */
268
319
  get size(): number;
269
320
  protected _min?: FibonacciHeapNode<E>;
321
+ /**
322
+ * The function returns the minimum node in a Fibonacci heap.
323
+ * @returns The method is returning the minimum node of the Fibonacci heap, which is of type
324
+ * `FibonacciHeapNode<E>`. If there is no minimum node, it will return `undefined`.
325
+ */
270
326
  get min(): FibonacciHeapNode<E> | undefined;
271
327
  protected _comparator: Comparator<E>;
328
+ /**
329
+ * The function returns the comparator used for comparing elements.
330
+ * @returns The `_comparator` property of the object.
331
+ */
272
332
  get comparator(): Comparator<E>;
273
333
  /**
274
334
  * Get the size (number of elements) of the heap.
@@ -425,11 +485,11 @@ export declare class FibonacciHeap<E> {
425
485
  */
426
486
  protected _link(y: FibonacciHeapNode<E>, x: FibonacciHeapNode<E>): void;
427
487
  /**
428
- * Time Complexity: O(n log n), where n is the number of elements in the heap.
488
+ * Time Complexity: O(n log n)
429
489
  * Space Complexity: O(n)
430
490
  */
431
491
  /**
432
- * Time Complexity: O(n log n), where n is the number of elements in the heap.
492
+ * Time Complexity: O(n log n)
433
493
  * Space Complexity: O(n)
434
494
  *
435
495
  * Remove and return the top element (smallest or largest element) from the heap.