data-structure-typed 1.49.6 → 1.49.8

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 (198) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +16 -13
  3. package/README_zh-CN.md +2 -0
  4. package/benchmark/report.html +13 -13
  5. package/benchmark/report.json +148 -148
  6. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +3 -3
  7. package/dist/cjs/data-structures/binary-tree/avl-tree.js +5 -5
  8. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  9. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +3 -3
  10. package/dist/cjs/data-structures/binary-tree/binary-tree.js +11 -13
  11. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  12. package/dist/cjs/data-structures/binary-tree/bst.d.ts +3 -3
  13. package/dist/cjs/data-structures/binary-tree/bst.js +6 -7
  14. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  15. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +2 -2
  16. package/dist/cjs/data-structures/binary-tree/rb-tree.js +6 -6
  17. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  18. package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +1 -1
  19. package/dist/cjs/data-structures/binary-tree/tree-multimap.js +3 -3
  20. package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
  21. package/dist/cjs/data-structures/hash/hash-map.d.ts +24 -27
  22. package/dist/cjs/data-structures/hash/hash-map.js +35 -35
  23. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  24. package/dist/cjs/data-structures/hash/index.d.ts +0 -1
  25. package/dist/cjs/data-structures/hash/index.js +0 -1
  26. package/dist/cjs/data-structures/hash/index.js.map +1 -1
  27. package/dist/cjs/data-structures/heap/heap.d.ts +2 -1
  28. package/dist/cjs/data-structures/heap/heap.js +13 -13
  29. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  30. package/dist/cjs/data-structures/heap/max-heap.js +1 -1
  31. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  32. package/dist/cjs/data-structures/heap/min-heap.js +1 -1
  33. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  34. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +1 -1
  35. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  36. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +1 -3
  37. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  38. package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +2 -8
  39. package/dist/cjs/data-structures/linked-list/skip-linked-list.js +15 -18
  40. package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
  41. package/dist/cjs/data-structures/matrix/matrix.d.ts +2 -7
  42. package/dist/cjs/data-structures/matrix/matrix.js +0 -7
  43. package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
  44. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +1 -1
  45. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  46. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +1 -1
  47. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  48. package/dist/cjs/data-structures/priority-queue/priority-queue.js +1 -1
  49. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
  50. package/dist/cjs/data-structures/queue/deque.d.ts +2 -11
  51. package/dist/cjs/data-structures/queue/deque.js +9 -13
  52. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  53. package/dist/cjs/data-structures/queue/queue.d.ts +13 -13
  54. package/dist/cjs/data-structures/queue/queue.js +29 -25
  55. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  56. package/dist/cjs/data-structures/stack/stack.js +2 -3
  57. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  58. package/dist/cjs/data-structures/trie/trie.d.ts +2 -2
  59. package/dist/cjs/data-structures/trie/trie.js +9 -5
  60. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  61. package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +2 -2
  62. package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +1 -1
  63. package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +1 -1
  64. package/dist/cjs/types/data-structures/binary-tree/tree-multimap.d.ts +1 -1
  65. package/dist/cjs/types/data-structures/hash/hash-map.d.ts +5 -2
  66. package/dist/cjs/types/data-structures/hash/index.d.ts +0 -1
  67. package/dist/cjs/types/data-structures/hash/index.js +0 -1
  68. package/dist/cjs/types/data-structures/hash/index.js.map +1 -1
  69. package/dist/cjs/types/data-structures/heap/heap.d.ts +1 -1
  70. package/dist/cjs/types/data-structures/linked-list/index.d.ts +1 -0
  71. package/dist/cjs/types/data-structures/linked-list/index.js +1 -0
  72. package/dist/cjs/types/data-structures/linked-list/index.js.map +1 -1
  73. package/dist/cjs/types/data-structures/linked-list/skip-linked-list.d.ts +4 -1
  74. package/dist/cjs/types/data-structures/matrix/index.d.ts +1 -0
  75. package/dist/cjs/types/data-structures/matrix/index.js +1 -0
  76. package/dist/cjs/types/data-structures/matrix/index.js.map +1 -1
  77. package/dist/cjs/types/data-structures/matrix/matrix.d.ts +7 -1
  78. package/dist/cjs/types/data-structures/queue/deque.d.ts +3 -1
  79. package/dist/cjs/types/data-structures/trie/trie.d.ts +3 -1
  80. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +3 -3
  81. package/dist/mjs/data-structures/binary-tree/avl-tree.js +5 -5
  82. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +3 -3
  83. package/dist/mjs/data-structures/binary-tree/binary-tree.js +11 -13
  84. package/dist/mjs/data-structures/binary-tree/bst.d.ts +3 -3
  85. package/dist/mjs/data-structures/binary-tree/bst.js +6 -7
  86. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +2 -2
  87. package/dist/mjs/data-structures/binary-tree/rb-tree.js +5 -6
  88. package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +1 -1
  89. package/dist/mjs/data-structures/binary-tree/tree-multimap.js +3 -3
  90. package/dist/mjs/data-structures/hash/hash-map.d.ts +24 -27
  91. package/dist/mjs/data-structures/hash/hash-map.js +35 -37
  92. package/dist/mjs/data-structures/hash/index.d.ts +0 -1
  93. package/dist/mjs/data-structures/hash/index.js +0 -1
  94. package/dist/mjs/data-structures/heap/heap.d.ts +2 -1
  95. package/dist/mjs/data-structures/heap/heap.js +19 -20
  96. package/dist/mjs/data-structures/heap/max-heap.js +1 -1
  97. package/dist/mjs/data-structures/heap/min-heap.js +1 -1
  98. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +1 -1
  99. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +2 -5
  100. package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +2 -8
  101. package/dist/mjs/data-structures/linked-list/skip-linked-list.js +16 -23
  102. package/dist/mjs/data-structures/matrix/matrix.d.ts +2 -7
  103. package/dist/mjs/data-structures/matrix/matrix.js +0 -7
  104. package/dist/mjs/data-structures/priority-queue/max-priority-queue.js +1 -1
  105. package/dist/mjs/data-structures/priority-queue/min-priority-queue.js +1 -1
  106. package/dist/mjs/data-structures/priority-queue/priority-queue.js +1 -1
  107. package/dist/mjs/data-structures/queue/deque.d.ts +2 -11
  108. package/dist/mjs/data-structures/queue/deque.js +9 -14
  109. package/dist/mjs/data-structures/queue/queue.d.ts +13 -13
  110. package/dist/mjs/data-structures/queue/queue.js +30 -28
  111. package/dist/mjs/data-structures/stack/stack.js +3 -5
  112. package/dist/mjs/data-structures/trie/trie.d.ts +2 -2
  113. package/dist/mjs/data-structures/trie/trie.js +10 -9
  114. package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +2 -2
  115. package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +1 -1
  116. package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +1 -1
  117. package/dist/mjs/types/data-structures/binary-tree/tree-multimap.d.ts +1 -1
  118. package/dist/mjs/types/data-structures/hash/hash-map.d.ts +5 -2
  119. package/dist/mjs/types/data-structures/hash/index.d.ts +0 -1
  120. package/dist/mjs/types/data-structures/hash/index.js +0 -1
  121. package/dist/mjs/types/data-structures/heap/heap.d.ts +1 -1
  122. package/dist/mjs/types/data-structures/linked-list/index.d.ts +1 -0
  123. package/dist/mjs/types/data-structures/linked-list/index.js +1 -0
  124. package/dist/mjs/types/data-structures/linked-list/skip-linked-list.d.ts +4 -1
  125. package/dist/mjs/types/data-structures/matrix/index.d.ts +1 -0
  126. package/dist/mjs/types/data-structures/matrix/index.js +1 -0
  127. package/dist/mjs/types/data-structures/matrix/matrix.d.ts +7 -1
  128. package/dist/mjs/types/data-structures/queue/deque.d.ts +3 -1
  129. package/dist/mjs/types/data-structures/trie/trie.d.ts +3 -1
  130. package/dist/umd/data-structure-typed.js +151 -432
  131. package/dist/umd/data-structure-typed.min.js +2 -2
  132. package/dist/umd/data-structure-typed.min.js.map +1 -1
  133. package/package.json +1 -1
  134. package/src/data-structures/binary-tree/avl-tree.ts +4 -4
  135. package/src/data-structures/binary-tree/binary-tree.ts +10 -14
  136. package/src/data-structures/binary-tree/bst.ts +5 -7
  137. package/src/data-structures/binary-tree/rb-tree.ts +4 -5
  138. package/src/data-structures/binary-tree/tree-multimap.ts +2 -2
  139. package/src/data-structures/hash/hash-map.ts +46 -50
  140. package/src/data-structures/hash/index.ts +0 -1
  141. package/src/data-structures/heap/heap.ts +20 -19
  142. package/src/data-structures/heap/max-heap.ts +1 -1
  143. package/src/data-structures/heap/min-heap.ts +1 -1
  144. package/src/data-structures/linked-list/doubly-linked-list.ts +1 -1
  145. package/src/data-structures/linked-list/singly-linked-list.ts +2 -5
  146. package/src/data-structures/linked-list/skip-linked-list.ts +15 -16
  147. package/src/data-structures/matrix/matrix.ts +2 -10
  148. package/src/data-structures/priority-queue/max-priority-queue.ts +1 -1
  149. package/src/data-structures/priority-queue/min-priority-queue.ts +1 -1
  150. package/src/data-structures/priority-queue/priority-queue.ts +1 -1
  151. package/src/data-structures/queue/deque.ts +11 -15
  152. package/src/data-structures/queue/queue.ts +29 -28
  153. package/src/data-structures/stack/stack.ts +3 -6
  154. package/src/data-structures/trie/trie.ts +10 -11
  155. package/src/types/data-structures/binary-tree/binary-tree.ts +2 -2
  156. package/src/types/data-structures/binary-tree/bst.ts +1 -1
  157. package/src/types/data-structures/binary-tree/rb-tree.ts +1 -1
  158. package/src/types/data-structures/binary-tree/tree-multimap.ts +1 -1
  159. package/src/types/data-structures/hash/hash-map.ts +6 -2
  160. package/src/types/data-structures/hash/index.ts +0 -1
  161. package/src/types/data-structures/heap/heap.ts +1 -1
  162. package/src/types/data-structures/linked-list/index.ts +1 -0
  163. package/src/types/data-structures/linked-list/skip-linked-list.ts +1 -1
  164. package/src/types/data-structures/matrix/index.ts +1 -0
  165. package/src/types/data-structures/matrix/matrix.ts +7 -1
  166. package/src/types/data-structures/queue/deque.ts +1 -1
  167. package/src/types/data-structures/trie/trie.ts +1 -1
  168. package/test/integration/index.html +4 -4
  169. package/test/unit/data-structures/binary-tree/overall.test.ts +180 -1
  170. package/test/unit/data-structures/hash/hash-map.test.ts +19 -6
  171. package/test/unit/data-structures/linked-list/skip-list.test.ts +1 -1
  172. package/test/unit/data-structures/queue/deque.test.ts +5 -5
  173. package/test/unit/data-structures/trie/trie.test.ts +1 -1
  174. package/dist/cjs/data-structures/hash/hash-table.d.ts +0 -108
  175. package/dist/cjs/data-structures/hash/hash-table.js +0 -282
  176. package/dist/cjs/data-structures/hash/hash-table.js.map +0 -1
  177. package/dist/cjs/types/data-structures/hash/hash-table.d.ts +0 -1
  178. package/dist/cjs/types/data-structures/hash/hash-table.js +0 -3
  179. package/dist/cjs/types/data-structures/hash/hash-table.js.map +0 -1
  180. package/dist/cjs/types/data-structures/matrix/matrix2d.d.ts +0 -1
  181. package/dist/cjs/types/data-structures/matrix/matrix2d.js +0 -3
  182. package/dist/cjs/types/data-structures/matrix/matrix2d.js.map +0 -1
  183. package/dist/cjs/types/data-structures/matrix/vector2d.d.ts +0 -1
  184. package/dist/cjs/types/data-structures/matrix/vector2d.js +0 -3
  185. package/dist/cjs/types/data-structures/matrix/vector2d.js.map +0 -1
  186. package/dist/mjs/data-structures/hash/hash-table.d.ts +0 -108
  187. package/dist/mjs/data-structures/hash/hash-table.js +0 -283
  188. package/dist/mjs/types/data-structures/hash/hash-table.d.ts +0 -1
  189. package/dist/mjs/types/data-structures/hash/hash-table.js +0 -1
  190. package/dist/mjs/types/data-structures/matrix/matrix2d.d.ts +0 -1
  191. package/dist/mjs/types/data-structures/matrix/matrix2d.js +0 -1
  192. package/dist/mjs/types/data-structures/matrix/vector2d.d.ts +0 -1
  193. package/dist/mjs/types/data-structures/matrix/vector2d.js +0 -1
  194. package/src/data-structures/hash/hash-table.ts +0 -318
  195. package/src/types/data-structures/hash/hash-table.ts +0 -1
  196. package/src/types/data-structures/matrix/matrix2d.ts +0 -1
  197. package/src/types/data-structures/matrix/vector2d.ts +0 -1
  198. package/test/unit/data-structures/hash/hash-table.test.ts +0 -238
@@ -124,8 +124,6 @@ var dataStructureTyped = (() => {
124
124
  FibonacciHeap: () => FibonacciHeap,
125
125
  FibonacciHeapNode: () => FibonacciHeapNode,
126
126
  HashMap: () => HashMap,
127
- HashTable: () => HashTable,
128
- HashTableNode: () => HashTableNode,
129
127
  Heap: () => Heap,
130
128
  IterableElementBase: () => IterableElementBase,
131
129
  IterableEntryBase: () => IterableEntryBase,
@@ -176,273 +174,6 @@ var dataStructureTyped = (() => {
176
174
  uuidV4: () => uuidV4
177
175
  });
178
176
 
179
- // src/data-structures/hash/hash-table.ts
180
- var HashTableNode = class {
181
- constructor(key, value) {
182
- __publicField(this, "key");
183
- __publicField(this, "value");
184
- __publicField(this, "next");
185
- this.key = key;
186
- this.value = value;
187
- this.next = void 0;
188
- }
189
- };
190
- var _HashTable = class _HashTable {
191
- constructor(capacity = _HashTable.DEFAULT_CAPACITY, hashFn) {
192
- __publicField(this, "_capacity");
193
- __publicField(this, "_size");
194
- __publicField(this, "_buckets");
195
- __publicField(this, "_hashFn");
196
- this._hashFn = hashFn || this._defaultHashFn;
197
- this._capacity = Math.max(capacity, _HashTable.DEFAULT_CAPACITY);
198
- this._size = 0;
199
- this._buckets = new Array(this._capacity).fill(void 0);
200
- }
201
- get capacity() {
202
- return this._capacity;
203
- }
204
- get size() {
205
- return this._size;
206
- }
207
- get buckets() {
208
- return this._buckets;
209
- }
210
- get hashFn() {
211
- return this._hashFn;
212
- }
213
- /**
214
- * The set function adds a key-value pair to the hash table, handling collisions and resizing if necessary.
215
- * @param {K} key - The key parameter represents the key of the key-value pair that you want to insert into the hash
216
- * table. It is of type K, which is a generic type representing the key's data type.
217
- * @param {V} value - The parameter `value` represents the value that you want to associate with the given key in the hash
218
- * table.
219
- * @returns Nothing is being returned. The return type of the `put` method is `void`, which means it does not return any
220
- * value.
221
- */
222
- set(key, value) {
223
- const index = this._hash(key);
224
- const newNode = new HashTableNode(key, value);
225
- if (!this._buckets[index]) {
226
- this._buckets[index] = newNode;
227
- } else {
228
- let currentNode = this._buckets[index];
229
- while (currentNode) {
230
- if (currentNode.key === key) {
231
- currentNode.value = value;
232
- return;
233
- }
234
- if (!currentNode.next) {
235
- break;
236
- }
237
- currentNode = currentNode.next;
238
- }
239
- currentNode.next = newNode;
240
- }
241
- this._size++;
242
- if (this._size / this._capacity >= _HashTable.LOAD_FACTOR) {
243
- this._expand();
244
- }
245
- }
246
- /**
247
- * The `get` function retrieves the value associated with a given key from a hash table.
248
- * @param {K} key - The `key` parameter represents the key of the element that we want to retrieve from the data
249
- * structure.
250
- * @returns The method is returning the value associated with the given key if it exists in the hash table. If the key is
251
- * not found, it returns `undefined`.
252
- */
253
- get(key) {
254
- const index = this._hash(key);
255
- let currentNode = this._buckets[index];
256
- while (currentNode) {
257
- if (currentNode.key === key) {
258
- return currentNode.value;
259
- }
260
- currentNode = currentNode.next;
261
- }
262
- return void 0;
263
- }
264
- /**
265
- * The delete function removes a key-value pair from a hash table.
266
- * @param {K} key - The `key` parameter represents the key of the key-value pair that needs to be removed from the hash
267
- * table.
268
- * @returns Nothing is being returned. The `delete` method has a return type of `void`, which means it does not return
269
- * any value.
270
- */
271
- delete(key) {
272
- const index = this._hash(key);
273
- let currentNode = this._buckets[index];
274
- let prevNode = void 0;
275
- while (currentNode) {
276
- if (currentNode.key === key) {
277
- if (prevNode) {
278
- prevNode.next = currentNode.next;
279
- } else {
280
- this._buckets[index] = currentNode.next;
281
- }
282
- this._size--;
283
- currentNode.next = void 0;
284
- return;
285
- }
286
- prevNode = currentNode;
287
- currentNode = currentNode.next;
288
- }
289
- }
290
- *[Symbol.iterator]() {
291
- for (const bucket of this._buckets) {
292
- let currentNode = bucket;
293
- while (currentNode) {
294
- yield [currentNode.key, currentNode.value];
295
- currentNode = currentNode.next;
296
- }
297
- }
298
- }
299
- forEach(callback) {
300
- let index = 0;
301
- for (const entry of this) {
302
- callback(entry, index, this);
303
- index++;
304
- }
305
- }
306
- filter(predicate) {
307
- const newTable = new _HashTable();
308
- let index = 0;
309
- for (const [key, value] of this) {
310
- if (predicate([key, value], index, this)) {
311
- newTable.set(key, value);
312
- }
313
- index++;
314
- }
315
- return newTable;
316
- }
317
- map(callback) {
318
- const newTable = new _HashTable();
319
- let index = 0;
320
- for (const [key, value] of this) {
321
- newTable.set(key, callback([key, value], index, this));
322
- index++;
323
- }
324
- return newTable;
325
- }
326
- reduce(callback, initialValue) {
327
- let accumulator = initialValue;
328
- let index = 0;
329
- for (const entry of this) {
330
- accumulator = callback(accumulator, entry, index, this);
331
- index++;
332
- }
333
- return accumulator;
334
- }
335
- /**
336
- * The function `_defaultHashFn` calculates the hash value of a given key and returns the remainder when divided by the
337
- * capacity of the data structure.
338
- * @param {K} key - The `key` parameter is the input value that needs to be hashed. It can be of any type, but in this
339
- * code snippet, it is checked whether the key is a string or an object. If it is a string, the `_murmurStringHashFn`
340
- * function is used to
341
- * @returns the hash value of the key modulo the capacity of the data structure.
342
- */
343
- _defaultHashFn(key) {
344
- const hashValue = typeof key === "string" ? this._murmurStringHashFn(key) : this._objectHash(key);
345
- return hashValue % this._capacity;
346
- }
347
- /**
348
- * The `_multiplicativeStringHashFn` function calculates a hash value for a given string key using the multiplicative
349
- * string hash function.
350
- * @param {K} key - The `key` parameter is the input value for which we want to calculate the hash. It can be of any
351
- * type, as it is generic (`K`). The function converts the `key` to a string using the `String()` function.
352
- * @returns a number, which is the result of the multiplicative string hash function applied to the input key.
353
- */
354
- _multiplicativeStringHashFn(key) {
355
- const keyString = String(key);
356
- let hash = 0;
357
- for (let i = 0; i < keyString.length; i++) {
358
- const charCode = keyString.charCodeAt(i);
359
- const A = 0.618033988749895;
360
- const M = 1 << 30;
361
- hash = (hash * A + charCode) % M;
362
- }
363
- return Math.abs(hash);
364
- }
365
- /**
366
- * The function `_murmurStringHashFn` calculates a hash value for a given string key using the MurmurHash algorithm.
367
- * @param {K} key - The `key` parameter is the input value for which you want to calculate the hash. It can be of any
368
- * type, but it will be converted to a string using the `String()` function before calculating the hash.
369
- * @returns a number, which is the hash value calculated for the given key.
370
- */
371
- _murmurStringHashFn(key) {
372
- const keyString = String(key);
373
- const seed = 0;
374
- let hash = seed;
375
- for (let i = 0; i < keyString.length; i++) {
376
- const char = keyString.charCodeAt(i);
377
- hash = (hash ^ char) * 1540483477;
378
- hash = (hash ^ hash >>> 15) * 668265261;
379
- hash = hash ^ hash >>> 15;
380
- }
381
- return Math.abs(hash);
382
- }
383
- /**
384
- * The _hash function takes a key and returns a number.
385
- * @param {K} key - The parameter "key" is of type K, which represents the type of the key that will be hashed.
386
- * @returns The hash function is returning a number.
387
- */
388
- _hash(key) {
389
- return this.hashFn(key);
390
- }
391
- /**
392
- * The function calculates a hash value for a given string using the djb2 algorithm.
393
- * @param {string} key - The `key` parameter in the `stringHash` function is a string value that represents the input for
394
- * which we want to calculate the hash value.
395
- * @returns a number, which is the hash value of the input string.
396
- */
397
- _stringHash(key) {
398
- let hash = 0;
399
- for (let i = 0; i < key.length; i++) {
400
- hash = hash * 31 + key.charCodeAt(i) & 4294967295;
401
- }
402
- return hash;
403
- }
404
- /**
405
- * The function `_objectHash` takes a key and returns a hash value, using a custom hash function for objects.
406
- * @param {K} key - The parameter "key" is of type "K", which means it can be any type. It could be a string, number,
407
- * boolean, object, or any other type of value. The purpose of the objectHash function is to generate a hash value for
408
- * the key, which can be used for
409
- * @returns a number, which is the hash value of the key.
410
- */
411
- _objectHash(key) {
412
- return this._stringHash(JSON.stringify(key));
413
- }
414
- /**
415
- * The `expand` function increases the capacity of a hash table by creating a new array of buckets with double the
416
- * capacity and rehashing all the existing key-value pairs into the new buckets.
417
- */
418
- _expand() {
419
- const newCapacity = this._capacity * 2;
420
- const newBuckets = new Array(newCapacity).fill(void 0);
421
- for (const bucket of this._buckets) {
422
- let currentNode = bucket;
423
- while (currentNode) {
424
- const newIndex = this._hash(currentNode.key);
425
- const newNode = new HashTableNode(currentNode.key, currentNode.value);
426
- if (!newBuckets[newIndex]) {
427
- newBuckets[newIndex] = newNode;
428
- } else {
429
- let currentNewNode = newBuckets[newIndex];
430
- while (currentNewNode.next) {
431
- currentNewNode = currentNewNode.next;
432
- }
433
- currentNewNode.next = newNode;
434
- }
435
- currentNode = currentNode.next;
436
- }
437
- }
438
- this._buckets = newBuckets;
439
- this._capacity = newCapacity;
440
- }
441
- };
442
- __publicField(_HashTable, "DEFAULT_CAPACITY", 16);
443
- __publicField(_HashTable, "LOAD_FACTOR", 0.75);
444
- var HashTable = _HashTable;
445
-
446
177
  // src/data-structures/base/iterable-base.ts
447
178
  var IterableEntryBase = class {
448
179
  /**
@@ -854,14 +585,14 @@ var dataStructureTyped = (() => {
854
585
  // src/data-structures/hash/hash-map.ts
855
586
  var HashMap = class _HashMap extends IterableEntryBase {
856
587
  /**
857
- * The constructor function initializes a new instance of a class with optional elements and options.
858
- * @param elements - The `elements` parameter is an iterable containing key-value pairs `[K, V]`. It
588
+ * The constructor function initializes a new instance of a class with optional entries and options.
589
+ * @param entries - The `entries` parameter is an iterable containing key-value pairs `[K, V]`. It
859
590
  * is optional and defaults to an empty array `[]`. This parameter is used to initialize the map with
860
591
  * key-value pairs.
861
592
  * @param [options] - The `options` parameter is an optional object that can contain additional
862
593
  * configuration options for the constructor. In this case, it has one property:
863
594
  */
864
- constructor(elements = [], options) {
595
+ constructor(entries = [], options) {
865
596
  super();
866
597
  __publicField(this, "_store", {});
867
598
  __publicField(this, "_objMap", /* @__PURE__ */ new Map());
@@ -873,8 +604,8 @@ var dataStructureTyped = (() => {
873
604
  this._hashFn = hashFn;
874
605
  }
875
606
  }
876
- if (elements) {
877
- this.setMany(elements);
607
+ if (entries) {
608
+ this.setMany(entries);
878
609
  }
879
610
  }
880
611
  get size() {
@@ -914,12 +645,12 @@ var dataStructureTyped = (() => {
914
645
  }
915
646
  /**
916
647
  * The function "setMany" sets multiple key-value pairs in a map.
917
- * @param elements - The `elements` parameter is an iterable containing key-value pairs. Each
918
- * key-value pair is represented as an array with two elements: the key and the value.
648
+ * @param entries - The `entries` parameter is an iterable containing key-value pairs. Each
649
+ * key-value pair is represented as an array with two entries: the key and the value.
919
650
  */
920
- setMany(elements) {
651
+ setMany(entries) {
921
652
  const results = [];
922
- for (const [key, value] of elements)
653
+ for (const [key, value] of entries)
923
654
  results.push(this.set(key, value));
924
655
  return results;
925
656
  }
@@ -1033,9 +764,6 @@ var dataStructureTyped = (() => {
1033
764
  }
1034
765
  return filteredMap;
1035
766
  }
1036
- print() {
1037
- console.log([...this.entries()]);
1038
- }
1039
767
  put(key, value) {
1040
768
  return this.set(key, value);
1041
769
  }
@@ -1071,26 +799,31 @@ var dataStructureTyped = (() => {
1071
799
  }
1072
800
  };
1073
801
  var LinkedHashMap = class _LinkedHashMap extends IterableEntryBase {
1074
- constructor(elements, options = {
1075
- hashFn: (key) => String(key),
1076
- objHashFn: (key) => key
1077
- }) {
802
+ constructor(entries, options) {
1078
803
  super();
1079
804
  __publicField(this, "_noObjMap", {});
1080
805
  __publicField(this, "_objMap", /* @__PURE__ */ new WeakMap());
1081
806
  __publicField(this, "_head");
1082
807
  __publicField(this, "_tail");
1083
808
  __publicField(this, "_sentinel");
1084
- __publicField(this, "_hashFn");
1085
- __publicField(this, "_objHashFn");
1086
809
  __publicField(this, "_size", 0);
810
+ /**
811
+ * Time Complexity: O(n)
812
+ * Space Complexity: O(n)
813
+ */
814
+ __publicField(this, "_hashFn", (key) => String(key));
815
+ __publicField(this, "_objHashFn", (key) => key);
1087
816
  this._sentinel = {};
1088
817
  this._sentinel.prev = this._sentinel.next = this._head = this._tail = this._sentinel;
1089
- const { hashFn, objHashFn } = options;
1090
- this._hashFn = hashFn;
1091
- this._objHashFn = objHashFn;
1092
- if (elements) {
1093
- for (const el of elements) {
818
+ if (options) {
819
+ const { hashFn, objHashFn } = options;
820
+ if (hashFn)
821
+ this._hashFn = hashFn;
822
+ if (objHashFn)
823
+ this._objHashFn = objHashFn;
824
+ }
825
+ if (entries) {
826
+ for (const el of entries) {
1094
827
  this.set(el[0], el[1]);
1095
828
  }
1096
829
  }
@@ -1314,7 +1047,7 @@ var dataStructureTyped = (() => {
1314
1047
  * Time Complexity: O(1)
1315
1048
  * Space Complexity: O(1)
1316
1049
  *
1317
- * The `clear` function clears all the elements in a data structure and resets its properties.
1050
+ * The `clear` function clears all the entries in a data structure and resets its properties.
1318
1051
  */
1319
1052
  clear() {
1320
1053
  this._noObjMap = {};
@@ -1329,10 +1062,6 @@ var dataStructureTyped = (() => {
1329
1062
  }
1330
1063
  return cloned;
1331
1064
  }
1332
- /**
1333
- * Time Complexity: O(n)
1334
- * Space Complexity: O(n)
1335
- */
1336
1065
  /**
1337
1066
  * Time Complexity: O(n)
1338
1067
  * Space Complexity: O(n)
@@ -1359,10 +1088,6 @@ var dataStructureTyped = (() => {
1359
1088
  }
1360
1089
  return filteredMap;
1361
1090
  }
1362
- /**
1363
- * Time Complexity: O(n)
1364
- * Space Complexity: O(n)
1365
- */
1366
1091
  /**
1367
1092
  * Time Complexity: O(n)
1368
1093
  * Space Complexity: O(n)
@@ -1390,11 +1115,15 @@ var dataStructureTyped = (() => {
1390
1115
  }
1391
1116
  return mappedMap;
1392
1117
  }
1118
+ /**
1119
+ * Time Complexity: O(n)
1120
+ * Space Complexity: O(n)
1121
+ */
1393
1122
  put(key, value) {
1394
1123
  return this.set(key, value);
1395
1124
  }
1396
1125
  /**
1397
- * Time Complexity: O(n), where n is the number of elements in the LinkedHashMap.
1126
+ * Time Complexity: O(n), where n is the number of entries in the LinkedHashMap.
1398
1127
  * Space Complexity: O(1)
1399
1128
  *
1400
1129
  * The above function is an iterator that yields key-value pairs from a linked list.
@@ -1449,14 +1178,11 @@ var dataStructureTyped = (() => {
1449
1178
  /**
1450
1179
  * The constructor initializes the linked list with an empty head, tail, and length.
1451
1180
  */
1452
- constructor(elements) {
1181
+ constructor(elements = []) {
1453
1182
  super();
1454
1183
  __publicField(this, "_head");
1455
1184
  __publicField(this, "_tail");
1456
- __publicField(this, "_size");
1457
- this._head = void 0;
1458
- this._tail = void 0;
1459
- this._size = 0;
1185
+ __publicField(this, "_size", 0);
1460
1186
  if (elements) {
1461
1187
  for (const el of elements)
1462
1188
  this.push(el);
@@ -2126,7 +1852,7 @@ var dataStructureTyped = (() => {
2126
1852
  /**
2127
1853
  * The constructor initializes the linked list with an empty head, tail, and size.
2128
1854
  */
2129
- constructor(elements) {
1855
+ constructor(elements = []) {
2130
1856
  super();
2131
1857
  __publicField(this, "_head");
2132
1858
  __publicField(this, "_tail");
@@ -2852,22 +2578,22 @@ var dataStructureTyped = (() => {
2852
2578
  }
2853
2579
  };
2854
2580
  var SkipList = class {
2855
- /**
2856
- * The constructor initializes a SkipList with a specified maximum level and probability.
2857
- * @param [maxLevel=16] - The `maxLevel` parameter represents the maximum level that a skip list can have. It determines
2858
- * the maximum number of levels that can be created in the skip list.
2859
- * @param [probability=0.5] - The probability parameter represents the probability of a node being promoted to a higher
2860
- * level in the skip list. It is used to determine the height of each node in the skip list.
2861
- */
2862
- constructor(maxLevel = 16, probability = 0.5) {
2863
- __publicField(this, "_head");
2864
- __publicField(this, "_level");
2865
- __publicField(this, "_maxLevel");
2866
- __publicField(this, "_probability");
2867
- this._head = new SkipListNode(void 0, void 0, maxLevel);
2868
- this._level = 0;
2869
- this._maxLevel = maxLevel;
2870
- this._probability = probability;
2581
+ constructor(elements = [], options) {
2582
+ __publicField(this, "_head", new SkipListNode(void 0, void 0, this.maxLevel));
2583
+ __publicField(this, "_level", 0);
2584
+ __publicField(this, "_maxLevel", 16);
2585
+ __publicField(this, "_probability", 0.5);
2586
+ if (options) {
2587
+ const { maxLevel, probability } = options;
2588
+ if (typeof maxLevel === "number")
2589
+ this._maxLevel = maxLevel;
2590
+ if (typeof probability === "number")
2591
+ this._probability = probability;
2592
+ }
2593
+ if (elements) {
2594
+ for (const [key, value] of elements)
2595
+ this.add(key, value);
2596
+ }
2871
2597
  }
2872
2598
  get head() {
2873
2599
  return this._head;
@@ -3096,14 +2822,12 @@ var dataStructureTyped = (() => {
3096
2822
  * of elements of type `E`. It is used to initialize the `_elements` property of the class. If the `elements` parameter
3097
2823
  * is provided and is an array, it is assigned to the `_elements
3098
2824
  */
3099
- constructor(elements) {
2825
+ constructor(elements = []) {
3100
2826
  super();
3101
- __publicField(this, "_elements");
3102
- this._elements = [];
2827
+ __publicField(this, "_elements", []);
3103
2828
  if (elements) {
3104
- for (const el of elements) {
2829
+ for (const el of elements)
3105
2830
  this.push(el);
3106
- }
3107
2831
  }
3108
2832
  }
3109
2833
  get elements() {
@@ -3295,18 +3019,20 @@ var dataStructureTyped = (() => {
3295
3019
  /**
3296
3020
  * The constructor initializes an instance of a class with an optional array of elements and sets the offset to 0.
3297
3021
  * @param {E[]} [elements] - The `elements` parameter is an optional array of elements of type `E`. If provided, it
3298
- * will be used to initialize the `_nodes` property of the class. If not provided, the `_nodes` property will be
3022
+ * will be used to initialize the `_elements` property of the class. If not provided, the `_elements` property will be
3299
3023
  * initialized as an empty array.
3300
3024
  */
3301
- constructor(elements) {
3025
+ constructor(elements = []) {
3302
3026
  super();
3303
- __publicField(this, "_nodes");
3304
- __publicField(this, "_offset");
3305
- this._nodes = elements || [];
3306
- this._offset = 0;
3027
+ __publicField(this, "_elements", []);
3028
+ __publicField(this, "_offset", 0);
3029
+ if (elements) {
3030
+ for (const el of elements)
3031
+ this.push(el);
3032
+ }
3307
3033
  }
3308
- get nodes() {
3309
- return this._nodes;
3034
+ get elements() {
3035
+ return this._elements;
3310
3036
  }
3311
3037
  get offset() {
3312
3038
  return this._offset;
@@ -3316,18 +3042,18 @@ var dataStructureTyped = (() => {
3316
3042
  * @returns {number} The size of the array, which is the difference between the length of the array and the offset.
3317
3043
  */
3318
3044
  get size() {
3319
- return this.nodes.length - this.offset;
3045
+ return this.elements.length - this.offset;
3320
3046
  }
3321
3047
  /**
3322
3048
  * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
3323
3049
  * Space Complexity: O(1) - no additional space is used.
3324
3050
  *
3325
- * The `first` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
3326
- * @returns The `get first()` method returns the first element of the data structure, represented by the `_nodes` array at
3051
+ * The `first` function returns the first element of the array `_elements` if it exists, otherwise it returns `undefined`.
3052
+ * @returns The `get first()` method returns the first element of the data structure, represented by the `_elements` array at
3327
3053
  * the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
3328
3054
  */
3329
3055
  get first() {
3330
- return this.size > 0 ? this.nodes[this.offset] : void 0;
3056
+ return this.size > 0 ? this.elements[this.offset] : void 0;
3331
3057
  }
3332
3058
  /**
3333
3059
  * Time Complexity: O(1) - constant time as it adds an element to the end of the array.
@@ -3338,11 +3064,11 @@ var dataStructureTyped = (() => {
3338
3064
  * Space Complexity: O(1) - no additional space is used.
3339
3065
  *
3340
3066
  * The `last` function returns the last element in an array-like data structure, or undefined if the structure is empty.
3341
- * @returns The method `get last()` returns the last element of the `_nodes` array if the array is not empty. If the
3067
+ * @returns The method `get last()` returns the last element of the `_elements` array if the array is not empty. If the
3342
3068
  * array is empty, it returns `undefined`.
3343
3069
  */
3344
3070
  get last() {
3345
- return this.size > 0 ? this.nodes[this.nodes.length - 1] : void 0;
3071
+ return this.size > 0 ? this.elements[this.elements.length - 1] : void 0;
3346
3072
  }
3347
3073
  /**
3348
3074
  * Time Complexity: O(n) - where n is the number of elements in the queue. In the worst case, it may need to shift all elements to update the offset.
@@ -3372,7 +3098,7 @@ var dataStructureTyped = (() => {
3372
3098
  * @returns The `add` method is returning a `Queue<E>` object.
3373
3099
  */
3374
3100
  push(element) {
3375
- this.nodes.push(element);
3101
+ this.elements.push(element);
3376
3102
  return true;
3377
3103
  }
3378
3104
  /**
@@ -3392,9 +3118,9 @@ var dataStructureTyped = (() => {
3392
3118
  return void 0;
3393
3119
  const first = this.first;
3394
3120
  this._offset += 1;
3395
- if (this.offset * 2 < this.nodes.length)
3121
+ if (this.offset * 2 < this.elements.length)
3396
3122
  return first;
3397
- this._nodes = this.nodes.slice(this.offset);
3123
+ this._elements = this.elements.slice(this.offset);
3398
3124
  this._offset = 0;
3399
3125
  return first;
3400
3126
  }
@@ -3406,8 +3132,8 @@ var dataStructureTyped = (() => {
3406
3132
  * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
3407
3133
  * Space Complexity: O(1) - no additional space is used.
3408
3134
  *
3409
- * The `peek` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
3410
- * @returns The `peek()` method returns the first element of the data structure, represented by the `_nodes` array at
3135
+ * The `peek` function returns the first element of the array `_elements` if it exists, otherwise it returns `undefined`.
3136
+ * @returns The `peek()` method returns the first element of the data structure, represented by the `_elements` array at
3411
3137
  * the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
3412
3138
  */
3413
3139
  peek() {
@@ -3422,7 +3148,7 @@ var dataStructureTyped = (() => {
3422
3148
  * Space Complexity: O(1) - no additional space is used.
3423
3149
  *
3424
3150
  * The `peekLast` function returns the last element in an array-like data structure, or undefined if the structure is empty.
3425
- * @returns The method `peekLast()` returns the last element of the `_nodes` array if the array is not empty. If the
3151
+ * @returns The method `peekLast()` returns the last element of the `_elements` array if the array is not empty. If the
3426
3152
  * array is empty, it returns `undefined`.
3427
3153
  */
3428
3154
  peekLast() {
@@ -3467,7 +3193,7 @@ var dataStructureTyped = (() => {
3467
3193
  * @param index
3468
3194
  */
3469
3195
  getAt(index) {
3470
- return this.nodes[index];
3196
+ return this.elements[index];
3471
3197
  }
3472
3198
  /**
3473
3199
  * Time Complexity: O(1) - constant time as it retrieves the value at the specified index.
@@ -3491,17 +3217,17 @@ var dataStructureTyped = (() => {
3491
3217
  * Time Complexity: O(1) - constant time as it returns a shallow copy of the internal array.
3492
3218
  * Space Complexity: O(n) - where n is the number of elements in the queue.
3493
3219
  *
3494
- * The toArray() function returns an array of elements from the current offset to the end of the _nodes array.
3220
+ * The toArray() function returns an array of elements from the current offset to the end of the _elements array.
3495
3221
  * @returns An array of type E is being returned.
3496
3222
  */
3497
3223
  toArray() {
3498
- return this.nodes.slice(this.offset);
3224
+ return this.elements.slice(this.offset);
3499
3225
  }
3500
3226
  /**
3501
- * The clear function resets the nodes array and offset to their initial values.
3227
+ * The clear function resets the elements array and offset to their initial values.
3502
3228
  */
3503
3229
  clear() {
3504
- this._nodes = [];
3230
+ this._elements = [];
3505
3231
  this._offset = 0;
3506
3232
  }
3507
3233
  /**
@@ -3516,7 +3242,7 @@ var dataStructureTyped = (() => {
3516
3242
  * @returns The `clone()` method is returning a new instance of the `Queue` class.
3517
3243
  */
3518
3244
  clone() {
3519
- return new _Queue(this.nodes.slice(this.offset));
3245
+ return new _Queue(this.elements.slice(this.offset));
3520
3246
  }
3521
3247
  /**
3522
3248
  * Time Complexity: O(n)
@@ -3581,7 +3307,7 @@ var dataStructureTyped = (() => {
3581
3307
  * Space Complexity: O(n)
3582
3308
  */
3583
3309
  *_getIterator() {
3584
- for (const item of this.nodes) {
3310
+ for (const item of this.elements) {
3585
3311
  yield item;
3586
3312
  }
3587
3313
  }
@@ -3620,25 +3346,21 @@ var dataStructureTyped = (() => {
3620
3346
 
3621
3347
  // src/data-structures/queue/deque.ts
3622
3348
  var Deque = class _Deque extends IterableElementBase {
3623
- /**
3624
- * The constructor initializes a data structure with a specified bucket size and populates it with
3625
- * elements from an iterable.
3626
- * @param elements - The `elements` parameter is an iterable object (such as an array or a Set) that
3627
- * contains the initial elements to be stored in the data structure. It can also be an object with a
3628
- * `length` property or a `size` property, which represents the number of elements in the iterable.
3629
- * @param bucketSize - The `bucketSize` parameter is the maximum number of elements that can be
3630
- * stored in each bucket. It determines the size of each bucket in the data structure.
3631
- */
3632
- constructor(elements = [], bucketSize = 1 << 12) {
3349
+ constructor(elements = [], options) {
3633
3350
  super();
3634
3351
  __publicField(this, "_bucketFirst", 0);
3635
3352
  __publicField(this, "_firstInBucket", 0);
3636
3353
  __publicField(this, "_bucketLast", 0);
3637
3354
  __publicField(this, "_lastInBucket", 0);
3638
3355
  __publicField(this, "_bucketCount", 0);
3639
- __publicField(this, "_bucketSize");
3356
+ __publicField(this, "_bucketSize", 1 << 12);
3640
3357
  __publicField(this, "_buckets", []);
3641
3358
  __publicField(this, "_size", 0);
3359
+ if (options) {
3360
+ const { bucketSize } = options;
3361
+ if (typeof bucketSize === "number")
3362
+ this._bucketSize = bucketSize;
3363
+ }
3642
3364
  let _size;
3643
3365
  if ("length" in elements) {
3644
3366
  if (elements.length instanceof Function)
@@ -3651,7 +3373,6 @@ var dataStructureTyped = (() => {
3651
3373
  else
3652
3374
  _size = elements.size;
3653
3375
  }
3654
- this._bucketSize = bucketSize;
3655
3376
  this._bucketCount = calcMinUnitsRequired(_size, this._bucketSize) || 1;
3656
3377
  for (let i = 0; i < this._bucketCount; ++i) {
3657
3378
  this._buckets.push(new Array(this._bucketSize));
@@ -4210,7 +3931,7 @@ var dataStructureTyped = (() => {
4210
3931
  * satisfy the given predicate function.
4211
3932
  */
4212
3933
  filter(predicate, thisArg) {
4213
- const newDeque = new _Deque([], this._bucketSize);
3934
+ const newDeque = new _Deque([], { bucketSize: this._bucketSize });
4214
3935
  let index = 0;
4215
3936
  for (const el of this) {
4216
3937
  if (predicate.call(thisArg, el, index, this)) {
@@ -4238,7 +3959,7 @@ var dataStructureTyped = (() => {
4238
3959
  * @returns a new Deque object with the mapped values.
4239
3960
  */
4240
3961
  map(callback, thisArg) {
4241
- const newDeque = new _Deque([], this._bucketSize);
3962
+ const newDeque = new _Deque([], { bucketSize: this._bucketSize });
4242
3963
  let index = 0;
4243
3964
  for (const el of this) {
4244
3965
  newDeque.push(callback.call(thisArg, el, index, this));
@@ -4374,23 +4095,20 @@ var dataStructureTyped = (() => {
4374
4095
 
4375
4096
  // src/data-structures/heap/heap.ts
4376
4097
  var Heap = class _Heap extends IterableElementBase {
4377
- constructor(elements, options) {
4098
+ constructor(elements = [], options) {
4378
4099
  super();
4379
- __publicField(this, "options");
4380
- __publicField(this, "_elements", []);
4381
- const defaultComparator = (a, b) => {
4100
+ __publicField(this, "_comparator", (a, b) => {
4382
4101
  if (!(typeof a === "number" && typeof b === "number")) {
4383
4102
  throw new Error("The a, b params of compare function must be number");
4384
4103
  } else {
4385
4104
  return a - b;
4386
4105
  }
4387
- };
4106
+ });
4107
+ __publicField(this, "_elements", []);
4388
4108
  if (options) {
4389
- this.options = options;
4390
- } else {
4391
- this.options = {
4392
- comparator: defaultComparator
4393
- };
4109
+ const { comparator } = options;
4110
+ if (comparator)
4111
+ this._comparator = comparator;
4394
4112
  }
4395
4113
  if (elements) {
4396
4114
  for (const el of elements) {
@@ -4398,6 +4116,9 @@ var dataStructureTyped = (() => {
4398
4116
  }
4399
4117
  }
4400
4118
  }
4119
+ get comparator() {
4120
+ return this._comparator;
4121
+ }
4401
4122
  get elements() {
4402
4123
  return this._elements;
4403
4124
  }
@@ -4602,7 +4323,7 @@ var dataStructureTyped = (() => {
4602
4323
  * @returns A new Heap instance containing the same elements.
4603
4324
  */
4604
4325
  clone() {
4605
- const clonedHeap = new _Heap([], this.options);
4326
+ const clonedHeap = new _Heap([], { comparator: this.comparator });
4606
4327
  clonedHeap._elements = [...this.elements];
4607
4328
  return clonedHeap;
4608
4329
  }
@@ -4728,7 +4449,7 @@ var dataStructureTyped = (() => {
4728
4449
  while (index > 0) {
4729
4450
  const parent = index - 1 >> 1;
4730
4451
  const parentItem = this.elements[parent];
4731
- if (this.options.comparator(parentItem, element) <= 0)
4452
+ if (this.comparator(parentItem, element) <= 0)
4732
4453
  break;
4733
4454
  this.elements[index] = parentItem;
4734
4455
  index = parent;
@@ -4750,11 +4471,11 @@ var dataStructureTyped = (() => {
4750
4471
  let left = index << 1 | 1;
4751
4472
  const right = left + 1;
4752
4473
  let minItem = this.elements[left];
4753
- if (right < this.elements.length && this.options.comparator(minItem, this.elements[right]) > 0) {
4474
+ if (right < this.elements.length && this.comparator(minItem, this.elements[right]) > 0) {
4754
4475
  left = right;
4755
4476
  minItem = this.elements[right];
4756
4477
  }
4757
- if (this.options.comparator(minItem, element) >= 0)
4478
+ if (this.comparator(minItem, element) >= 0)
4758
4479
  break;
4759
4480
  this.elements[index] = minItem;
4760
4481
  index = left;
@@ -5113,7 +4834,7 @@ var dataStructureTyped = (() => {
5113
4834
 
5114
4835
  // src/data-structures/heap/max-heap.ts
5115
4836
  var MaxHeap = class extends Heap {
5116
- constructor(elements, options = {
4837
+ constructor(elements = [], options = {
5117
4838
  comparator: (a, b) => {
5118
4839
  if (!(typeof a === "number" && typeof b === "number")) {
5119
4840
  throw new Error("The a, b params of compare function must be number");
@@ -5128,7 +4849,7 @@ var dataStructureTyped = (() => {
5128
4849
 
5129
4850
  // src/data-structures/heap/min-heap.ts
5130
4851
  var MinHeap = class extends Heap {
5131
- constructor(elements, options = {
4852
+ constructor(elements = [], options = {
5132
4853
  comparator: (a, b) => {
5133
4854
  if (!(typeof a === "number" && typeof b === "number")) {
5134
4855
  throw new Error("The a, b params of compare function must be number");
@@ -7315,15 +7036,15 @@ var dataStructureTyped = (() => {
7315
7036
  };
7316
7037
  var BinaryTree = class _BinaryTree extends IterableEntryBase {
7317
7038
  /**
7318
- * The constructor function initializes a binary tree object with optional nodes and options.
7319
- * @param [nodes] - An optional iterable of KeyOrNodeOrEntry objects. These objects represent the
7039
+ * The constructor function initializes a binary tree object with optional keysOrNodesOrEntries and options.
7040
+ * @param [keysOrNodesOrEntries] - An optional iterable of KeyOrNodeOrEntry objects. These objects represent the
7320
7041
  * nodes to be added to the binary tree.
7321
7042
  * @param [options] - The `options` parameter is an optional object that can contain additional
7322
7043
  * configuration options for the binary tree. In this case, it is of type
7323
7044
  * `Partial<BinaryTreeOptions>`, which means that not all properties of `BinaryTreeOptions` are
7324
7045
  * required.
7325
7046
  */
7326
- constructor(nodes, options) {
7047
+ constructor(keysOrNodesOrEntries = [], options) {
7327
7048
  super();
7328
7049
  __publicField(this, "iterationType", "ITERATIVE" /* ITERATIVE */);
7329
7050
  __publicField(this, "_extractor", (key) => Number(key));
@@ -7332,16 +7053,14 @@ var dataStructureTyped = (() => {
7332
7053
  __publicField(this, "_defaultOneParamCallback", (node) => node ? node.key : void 0);
7333
7054
  if (options) {
7334
7055
  const { iterationType, extractor } = options;
7335
- if (iterationType) {
7056
+ if (iterationType)
7336
7057
  this.iterationType = iterationType;
7337
- }
7338
- if (extractor) {
7058
+ if (extractor)
7339
7059
  this._extractor = extractor;
7340
- }
7341
7060
  }
7342
7061
  this._size = 0;
7343
- if (nodes)
7344
- this.addMany(nodes);
7062
+ if (keysOrNodesOrEntries)
7063
+ this.addMany(keysOrNodesOrEntries);
7345
7064
  }
7346
7065
  get extractor() {
7347
7066
  return this._extractor;
@@ -8409,9 +8128,9 @@ var dataStructureTyped = (() => {
8409
8128
  if (current && this.isNodeOrNull(current.right))
8410
8129
  queue.push(current.right);
8411
8130
  } else {
8412
- if (current.left)
8131
+ if (this.isRealNode(current.left))
8413
8132
  queue.push(current.left);
8414
- if (current.right)
8133
+ if (this.isRealNode(current.right))
8415
8134
  queue.push(current.right);
8416
8135
  }
8417
8136
  traverse(level + 1);
@@ -8430,9 +8149,9 @@ var dataStructureTyped = (() => {
8430
8149
  if (current && this.isNodeOrNull(current.right))
8431
8150
  queue.push(current.right);
8432
8151
  } else {
8433
- if (current.left)
8152
+ if (this.isRealNode(current.left))
8434
8153
  queue.push(current.left);
8435
- if (current.right)
8154
+ if (this.isRealNode(current.right))
8436
8155
  queue.push(current.right);
8437
8156
  }
8438
8157
  }
@@ -8949,25 +8668,24 @@ var dataStructureTyped = (() => {
8949
8668
  var BST = class _BST extends BinaryTree {
8950
8669
  /**
8951
8670
  * This is the constructor function for a binary search tree class in TypeScript, which initializes
8952
- * the tree with optional nodes and options.
8953
- * @param [nodes] - An optional iterable of KeyOrNodeOrEntry objects that will be added to the
8671
+ * the tree with optional keysOrNodesOrEntries and options.
8672
+ * @param [keysOrNodesOrEntries] - An optional iterable of KeyOrNodeOrEntry objects that will be added to the
8954
8673
  * binary search tree.
8955
8674
  * @param [options] - The `options` parameter is an optional object that can contain additional
8956
8675
  * configuration options for the binary search tree. It can have the following properties:
8957
8676
  */
8958
- constructor(nodes, options) {
8677
+ constructor(keysOrNodesOrEntries = [], options) {
8959
8678
  super([], options);
8960
8679
  __publicField(this, "_root");
8961
8680
  __publicField(this, "_variant", "STANDARD" /* STANDARD */);
8962
8681
  if (options) {
8963
8682
  const { variant } = options;
8964
- if (variant) {
8683
+ if (variant)
8965
8684
  this._variant = variant;
8966
- }
8967
8685
  }
8968
8686
  this._root = void 0;
8969
- if (nodes)
8970
- this.addMany(nodes);
8687
+ if (keysOrNodesOrEntries)
8688
+ this.addMany(keysOrNodesOrEntries);
8971
8689
  }
8972
8690
  get root() {
8973
8691
  return this._root;
@@ -10022,18 +9740,18 @@ var dataStructureTyped = (() => {
10022
9740
  };
10023
9741
  var AVLTree = class _AVLTree extends BST {
10024
9742
  /**
10025
- * The constructor function initializes an AVLTree object with optional nodes and options.
10026
- * @param [nodes] - The `nodes` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, N>`
9743
+ * The constructor function initializes an AVLTree object with optional keysOrNodesOrEntries and options.
9744
+ * @param [keysOrNodesOrEntries] - The `keysOrNodesOrEntries` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, N>`
10027
9745
  * objects. It represents a collection of nodes that will be added to the AVL tree during
10028
9746
  * initialization.
10029
9747
  * @param [options] - The `options` parameter is an optional object that allows you to customize the
10030
9748
  * behavior of the AVL tree. It is of type `Partial<AVLTreeOptions>`, which means that you can
10031
9749
  * provide only a subset of the properties defined in the `AVLTreeOptions` interface.
10032
9750
  */
10033
- constructor(nodes, options) {
9751
+ constructor(keysOrNodesOrEntries = [], options) {
10034
9752
  super([], options);
10035
- if (nodes)
10036
- super.addMany(nodes);
9753
+ if (keysOrNodesOrEntries)
9754
+ super.addMany(keysOrNodesOrEntries);
10037
9755
  }
10038
9756
  /**
10039
9757
  * The function creates a new AVL tree node with the specified key and value.
@@ -10454,7 +10172,7 @@ var dataStructureTyped = (() => {
10454
10172
  /**
10455
10173
  * This is the constructor function for a Red-Black Tree data structure in TypeScript, which
10456
10174
  * initializes the tree with optional nodes and options.
10457
- * @param [nodes] - The `nodes` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, N>`
10175
+ * @param [keysOrNodesOrEntries] - The `keysOrNodesOrEntries` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, N>`
10458
10176
  * objects. It represents the initial nodes that will be added to the RBTree during its
10459
10177
  * construction. If this parameter is provided, the `addMany` method is called to add all the
10460
10178
  * nodes to the
@@ -10462,14 +10180,14 @@ var dataStructureTyped = (() => {
10462
10180
  * behavior of the RBTree. It is of type `Partial<RBTreeOptions>`, which means that you can provide
10463
10181
  * only a subset of the properties defined in the `RBTreeOptions` interface.
10464
10182
  */
10465
- constructor(nodes, options) {
10183
+ constructor(keysOrNodesOrEntries = [], options) {
10466
10184
  super([], options);
10467
10185
  __publicField(this, "Sentinel", new RedBlackTreeNode(NaN));
10468
10186
  __publicField(this, "_root");
10469
10187
  __publicField(this, "_size", 0);
10470
10188
  this._root = this.Sentinel;
10471
- if (nodes)
10472
- super.addMany(nodes);
10189
+ if (keysOrNodesOrEntries)
10190
+ super.addMany(keysOrNodesOrEntries);
10473
10191
  }
10474
10192
  get root() {
10475
10193
  return this._root;
@@ -10501,8 +10219,7 @@ var dataStructureTyped = (() => {
10501
10219
  */
10502
10220
  createTree(options) {
10503
10221
  return new _RedBlackTree([], __spreadValues({
10504
- iterationType: this.iterationType,
10505
- variant: this.variant
10222
+ iterationType: this.iterationType
10506
10223
  }, options));
10507
10224
  }
10508
10225
  /**
@@ -10690,6 +10407,7 @@ var dataStructureTyped = (() => {
10690
10407
  this._fixDelete(x);
10691
10408
  }
10692
10409
  this._size--;
10410
+ ans.push({ deleted: z, needBalanced: void 0 });
10693
10411
  };
10694
10412
  helper(this.root);
10695
10413
  return ans;
@@ -11009,11 +10727,11 @@ var dataStructureTyped = (() => {
11009
10727
  }
11010
10728
  };
11011
10729
  var TreeMultimap = class _TreeMultimap extends AVLTree {
11012
- constructor(nodes, options) {
10730
+ constructor(keysOrNodesOrEntries = [], options) {
11013
10731
  super([], options);
11014
10732
  __publicField(this, "_count", 0);
11015
- if (nodes)
11016
- this.addMany(nodes);
10733
+ if (keysOrNodesOrEntries)
10734
+ this.addMany(keysOrNodesOrEntries);
11017
10735
  }
11018
10736
  // TODO the _count is not accurate after nodes count modified
11019
10737
  get count() {
@@ -11373,14 +11091,14 @@ var dataStructureTyped = (() => {
11373
11091
 
11374
11092
  // src/data-structures/priority-queue/priority-queue.ts
11375
11093
  var PriorityQueue = class extends Heap {
11376
- constructor(elements, options) {
11094
+ constructor(elements = [], options) {
11377
11095
  super(elements, options);
11378
11096
  }
11379
11097
  };
11380
11098
 
11381
11099
  // src/data-structures/priority-queue/min-priority-queue.ts
11382
11100
  var MinPriorityQueue = class extends PriorityQueue {
11383
- constructor(elements, options = {
11101
+ constructor(elements = [], options = {
11384
11102
  comparator: (a, b) => {
11385
11103
  if (!(typeof a === "number" && typeof b === "number")) {
11386
11104
  throw new Error("The a, b params of compare function must be number");
@@ -11395,7 +11113,7 @@ var dataStructureTyped = (() => {
11395
11113
 
11396
11114
  // src/data-structures/priority-queue/max-priority-queue.ts
11397
11115
  var MaxPriorityQueue = class extends PriorityQueue {
11398
- constructor(elements, options = {
11116
+ constructor(elements = [], options = {
11399
11117
  comparator: (a, b) => {
11400
11118
  if (!(typeof a === "number" && typeof b === "number")) {
11401
11119
  throw new Error("The a, b params of compare function must be number");
@@ -11924,18 +11642,19 @@ var dataStructureTyped = (() => {
11924
11642
  }
11925
11643
  };
11926
11644
  var Trie = class _Trie extends IterableElementBase {
11927
- constructor(words, caseSensitive = true) {
11645
+ constructor(words = [], options) {
11928
11646
  super();
11929
- __publicField(this, "_size");
11930
- __publicField(this, "_caseSensitive");
11931
- __publicField(this, "_root");
11932
- this._root = new TrieNode("");
11933
- this._caseSensitive = caseSensitive;
11934
- this._size = 0;
11647
+ __publicField(this, "_size", 0);
11648
+ __publicField(this, "_caseSensitive", true);
11649
+ __publicField(this, "_root", new TrieNode(""));
11650
+ if (options) {
11651
+ const { caseSensitive } = options;
11652
+ if (caseSensitive !== void 0)
11653
+ this._caseSensitive = caseSensitive;
11654
+ }
11935
11655
  if (words) {
11936
- for (const word of words) {
11656
+ for (const word of words)
11937
11657
  this.add(word);
11938
- }
11939
11658
  }
11940
11659
  }
11941
11660
  get size() {