min-heap-typed 1.50.2 → 1.50.4

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 (92) hide show
  1. package/dist/data-structures/base/iterable-base.d.ts +6 -0
  2. package/dist/data-structures/binary-tree/{tree-multimap.d.ts → avl-tree-multi-map.d.ts} +43 -10
  3. package/dist/data-structures/binary-tree/{tree-multimap.js → avl-tree-multi-map.js} +49 -11
  4. package/dist/data-structures/binary-tree/avl-tree.d.ts +29 -1
  5. package/dist/data-structures/binary-tree/avl-tree.js +33 -1
  6. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +22 -0
  7. package/dist/data-structures/binary-tree/binary-indexed-tree.js +22 -0
  8. package/dist/data-structures/binary-tree/binary-tree.d.ts +1 -1
  9. package/dist/data-structures/binary-tree/binary-tree.js +1 -1
  10. package/dist/data-structures/binary-tree/bst.d.ts +46 -13
  11. package/dist/data-structures/binary-tree/bst.js +51 -20
  12. package/dist/data-structures/binary-tree/index.d.ts +2 -1
  13. package/dist/data-structures/binary-tree/index.js +2 -1
  14. package/dist/data-structures/binary-tree/rb-tree.d.ts +54 -2
  15. package/dist/data-structures/binary-tree/rb-tree.js +90 -24
  16. package/dist/data-structures/binary-tree/segment-tree.d.ts +99 -6
  17. package/dist/data-structures/binary-tree/segment-tree.js +127 -10
  18. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +200 -0
  19. package/dist/data-structures/binary-tree/tree-multi-map.js +399 -0
  20. package/dist/data-structures/graph/abstract-graph.d.ts +0 -78
  21. package/dist/data-structures/graph/abstract-graph.js +0 -189
  22. package/dist/data-structures/graph/directed-graph.d.ts +59 -0
  23. package/dist/data-structures/graph/directed-graph.js +105 -0
  24. package/dist/data-structures/graph/undirected-graph.d.ts +60 -7
  25. package/dist/data-structures/graph/undirected-graph.js +126 -18
  26. package/dist/data-structures/hash/hash-map.d.ts +143 -23
  27. package/dist/data-structures/hash/hash-map.js +196 -62
  28. package/dist/data-structures/heap/heap.d.ts +29 -19
  29. package/dist/data-structures/heap/heap.js +29 -20
  30. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +71 -25
  31. package/dist/data-structures/linked-list/doubly-linked-list.js +83 -25
  32. package/dist/data-structures/linked-list/singly-linked-list.d.ts +26 -3
  33. package/dist/data-structures/linked-list/singly-linked-list.js +34 -3
  34. package/dist/data-structures/linked-list/skip-linked-list.d.ts +2 -2
  35. package/dist/data-structures/linked-list/skip-linked-list.js +2 -2
  36. package/dist/data-structures/matrix/matrix.d.ts +1 -1
  37. package/dist/data-structures/matrix/matrix.js +1 -1
  38. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +10 -0
  39. package/dist/data-structures/priority-queue/max-priority-queue.js +10 -0
  40. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -0
  41. package/dist/data-structures/priority-queue/min-priority-queue.js +11 -0
  42. package/dist/data-structures/priority-queue/priority-queue.d.ts +8 -0
  43. package/dist/data-structures/priority-queue/priority-queue.js +8 -0
  44. package/dist/data-structures/queue/deque.d.ts +95 -21
  45. package/dist/data-structures/queue/deque.js +100 -16
  46. package/dist/data-structures/queue/queue.d.ts +65 -45
  47. package/dist/data-structures/queue/queue.js +65 -45
  48. package/dist/data-structures/stack/stack.d.ts +36 -22
  49. package/dist/data-structures/stack/stack.js +36 -22
  50. package/dist/data-structures/tree/tree.d.ts +57 -3
  51. package/dist/data-structures/tree/tree.js +77 -11
  52. package/dist/data-structures/trie/trie.d.ts +100 -36
  53. package/dist/data-structures/trie/trie.js +115 -36
  54. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +5 -0
  55. package/dist/types/data-structures/binary-tree/index.d.ts +2 -1
  56. package/dist/types/data-structures/binary-tree/index.js +2 -1
  57. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +5 -0
  58. package/dist/types/data-structures/binary-tree/tree-multi-map.js +2 -0
  59. package/package.json +2 -2
  60. package/src/data-structures/base/iterable-base.ts +12 -0
  61. package/src/data-structures/binary-tree/{tree-multimap.ts → avl-tree-multi-map.ts} +59 -20
  62. package/src/data-structures/binary-tree/avl-tree.ts +37 -3
  63. package/src/data-structures/binary-tree/binary-indexed-tree.ts +22 -0
  64. package/src/data-structures/binary-tree/binary-tree.ts +1 -1
  65. package/src/data-structures/binary-tree/bst.ts +51 -19
  66. package/src/data-structures/binary-tree/index.ts +2 -1
  67. package/src/data-structures/binary-tree/rb-tree.ts +99 -28
  68. package/src/data-structures/binary-tree/segment-tree.ts +145 -11
  69. package/src/data-structures/binary-tree/tree-multi-map.ts +463 -0
  70. package/src/data-structures/graph/abstract-graph.ts +0 -211
  71. package/src/data-structures/graph/directed-graph.ts +122 -0
  72. package/src/data-structures/graph/undirected-graph.ts +143 -19
  73. package/src/data-structures/hash/hash-map.ts +228 -76
  74. package/src/data-structures/heap/heap.ts +31 -20
  75. package/src/data-structures/linked-list/doubly-linked-list.ts +96 -29
  76. package/src/data-structures/linked-list/singly-linked-list.ts +42 -6
  77. package/src/data-structures/linked-list/skip-linked-list.ts +2 -2
  78. package/src/data-structures/matrix/matrix.ts +1 -1
  79. package/src/data-structures/priority-queue/max-priority-queue.ts +10 -0
  80. package/src/data-structures/priority-queue/min-priority-queue.ts +11 -0
  81. package/src/data-structures/priority-queue/priority-queue.ts +8 -0
  82. package/src/data-structures/queue/deque.ts +118 -22
  83. package/src/data-structures/queue/queue.ts +68 -45
  84. package/src/data-structures/stack/stack.ts +39 -23
  85. package/src/data-structures/tree/tree.ts +89 -15
  86. package/src/data-structures/trie/trie.ts +131 -40
  87. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +8 -0
  88. package/src/types/data-structures/binary-tree/index.ts +2 -1
  89. package/src/types/data-structures/binary-tree/tree-multi-map.ts +8 -0
  90. package/dist/types/data-structures/binary-tree/tree-multimap.d.ts +0 -5
  91. package/src/types/data-structures/binary-tree/tree-multimap.ts +0 -8
  92. /package/dist/types/data-structures/binary-tree/{tree-multimap.js → avl-tree-multi-map.js} +0 -0
@@ -45,6 +45,22 @@ class HashMap extends base_1.IterableEntryBase {
45
45
  this.setMany(rawCollection);
46
46
  }
47
47
  }
48
+ /**
49
+ * The function returns the store object, which is a dictionary of HashMapStoreItem objects.
50
+ * @returns The store property is being returned. It is a dictionary-like object with string keys and
51
+ * values of type HashMapStoreItem<K, V>.
52
+ */
53
+ get store() {
54
+ return this._store;
55
+ }
56
+ /**
57
+ * The function returns the object map.
58
+ * @returns The `objMap` property is being returned, which is a `Map` object with keys of type
59
+ * `object` and values of type `V`.
60
+ */
61
+ get objMap() {
62
+ return this._objMap;
63
+ }
48
64
  /**
49
65
  * The function returns the value of the _toEntryFn property.
50
66
  * @returns The function being returned is `this._toEntryFn`.
@@ -52,22 +68,22 @@ class HashMap extends base_1.IterableEntryBase {
52
68
  get toEntryFn() {
53
69
  return this._toEntryFn;
54
70
  }
71
+ /**
72
+ * The function returns the size of an object.
73
+ * @returns The size of the object, which is a number.
74
+ */
75
+ get size() {
76
+ return this._size;
77
+ }
55
78
  /**
56
79
  * The hasFn function is a function that takes in an item and returns a boolean
57
80
  * indicating whether the item is contained within the hash table.
58
81
  *
59
82
  * @return The hash function
60
83
  */
61
- get hasFn() {
84
+ get hashFn() {
62
85
  return this._hashFn;
63
86
  }
64
- /**
65
- * The function returns the size of an object.
66
- * @returns The size of the object, which is a number.
67
- */
68
- get size() {
69
- return this._size;
70
- }
71
87
  /**
72
88
  * The function checks if a given element is an array with exactly two elements.
73
89
  * @param {any} rawElement - The `rawElement` parameter is of type `any`, which means it can be any
@@ -104,14 +120,14 @@ class HashMap extends base_1.IterableEntryBase {
104
120
  */
105
121
  set(key, value) {
106
122
  if (this._isObjKey(key)) {
107
- if (!this._objMap.has(key)) {
123
+ if (!this.objMap.has(key)) {
108
124
  this._size++;
109
125
  }
110
- this._objMap.set(key, value);
126
+ this.objMap.set(key, value);
111
127
  }
112
128
  else {
113
129
  const strKey = this._getNoObjKey(key);
114
- if (this._store[strKey] === undefined) {
130
+ if (this.store[strKey] === undefined) {
115
131
  this._size++;
116
132
  }
117
133
  this._store[strKey] = { key, value };
@@ -153,7 +169,7 @@ class HashMap extends base_1.IterableEntryBase {
153
169
  get(key) {
154
170
  var _a;
155
171
  if (this._isObjKey(key)) {
156
- return this._objMap.get(key);
172
+ return this.objMap.get(key);
157
173
  }
158
174
  else {
159
175
  const strKey = this._getNoObjKey(key);
@@ -168,11 +184,11 @@ class HashMap extends base_1.IterableEntryBase {
168
184
  */
169
185
  has(key) {
170
186
  if (this._isObjKey(key)) {
171
- return this._objMap.has(key);
187
+ return this.objMap.has(key);
172
188
  }
173
189
  else {
174
190
  const strKey = this._getNoObjKey(key);
175
- return strKey in this._store;
191
+ return strKey in this.store;
176
192
  }
177
193
  }
178
194
  /**
@@ -184,21 +200,25 @@ class HashMap extends base_1.IterableEntryBase {
184
200
  */
185
201
  delete(key) {
186
202
  if (this._isObjKey(key)) {
187
- if (this._objMap.has(key)) {
203
+ if (this.objMap.has(key)) {
188
204
  this._size--;
189
205
  }
190
- return this._objMap.delete(key);
206
+ return this.objMap.delete(key);
191
207
  }
192
208
  else {
193
209
  const strKey = this._getNoObjKey(key);
194
- if (strKey in this._store) {
195
- delete this._store[strKey];
210
+ if (strKey in this.store) {
211
+ delete this.store[strKey];
196
212
  this._size--;
197
213
  return true;
198
214
  }
199
215
  return false;
200
216
  }
201
217
  }
218
+ /**
219
+ * Time Complexity: O(n)
220
+ * Space Complexity: O(n)
221
+ */
202
222
  /**
203
223
  * The clone function creates a new HashMap with the same key-value pairs as
204
224
  * this one. The clone function is useful for creating a copy of an existing
@@ -207,7 +227,7 @@ class HashMap extends base_1.IterableEntryBase {
207
227
  * @return A new hashmap with the same values as this one
208
228
  */
209
229
  clone() {
210
- return new HashMap(this, { hashFn: this._hashFn, toEntryFn: this.toEntryFn });
230
+ return new HashMap(this, { hashFn: this.hashFn, toEntryFn: this.toEntryFn });
211
231
  }
212
232
  /**
213
233
  * Time Complexity: O(n)
@@ -235,10 +255,6 @@ class HashMap extends base_1.IterableEntryBase {
235
255
  }
236
256
  return resultMap;
237
257
  }
238
- /**
239
- * Time Complexity: O(n)
240
- * Space Complexity: O(n)
241
- */
242
258
  /**
243
259
  * Time Complexity: O(n)
244
260
  * Space Complexity: O(n)
@@ -281,22 +297,34 @@ class HashMap extends base_1.IterableEntryBase {
281
297
  * object map.
282
298
  */
283
299
  *_getIterator() {
284
- for (const node of Object.values(this._store)) {
300
+ for (const node of Object.values(this.store)) {
285
301
  yield [node.key, node.value];
286
302
  }
287
- for (const node of this._objMap) {
303
+ for (const node of this.objMap) {
288
304
  yield node;
289
305
  }
290
306
  }
307
+ /**
308
+ * The function checks if a given key is an object or a function.
309
+ * @param {any} key - The parameter "key" can be of any type.
310
+ * @returns a boolean value.
311
+ */
291
312
  _isObjKey(key) {
292
313
  const keyType = typeof key;
293
314
  return (keyType === 'object' || keyType === 'function') && key !== null;
294
315
  }
316
+ /**
317
+ * The function `_getNoObjKey` takes a key and returns a string representation of the key, handling
318
+ * different types of keys.
319
+ * @param {K} key - The `key` parameter is of type `K`, which represents the type of the key being
320
+ * passed to the `_getNoObjKey` function.
321
+ * @returns a string value.
322
+ */
295
323
  _getNoObjKey(key) {
296
324
  const keyType = typeof key;
297
325
  let strKey;
298
326
  if (keyType !== 'string' && keyType !== 'number' && keyType !== 'symbol') {
299
- strKey = this._hashFn(key);
327
+ strKey = this.hashFn(key);
300
328
  }
301
329
  else {
302
330
  if (keyType === 'number') {
@@ -328,6 +356,8 @@ class LinkedHashMap extends base_1.IterableEntryBase {
328
356
  */
329
357
  constructor(rawCollection = [], options) {
330
358
  super();
359
+ this._hashFn = (key) => String(key);
360
+ this._objHashFn = (key) => key;
331
361
  this._noObjMap = {};
332
362
  this._objMap = new WeakMap();
333
363
  this._toEntryFn = (rawElement) => {
@@ -340,8 +370,6 @@ class LinkedHashMap extends base_1.IterableEntryBase {
340
370
  }
341
371
  };
342
372
  this._size = 0;
343
- this._hashFn = (key) => String(key);
344
- this._objHashFn = (key) => key;
345
373
  this._sentinel = {};
346
374
  this._sentinel.prev = this._sentinel.next = this._head = this._tail = this._sentinel;
347
375
  if (options) {
@@ -361,6 +389,51 @@ class LinkedHashMap extends base_1.IterableEntryBase {
361
389
  }
362
390
  }
363
391
  }
392
+ /**
393
+ * The function returns the hash function used for generating a hash value for a given key.
394
+ * @returns The hash function that takes a key of type K and returns a string.
395
+ */
396
+ get hashFn() {
397
+ return this._hashFn;
398
+ }
399
+ /**
400
+ * The function returns the object hash function.
401
+ * @returns The function `objHashFn` is being returned.
402
+ */
403
+ get objHashFn() {
404
+ return this._objHashFn;
405
+ }
406
+ /**
407
+ * The function returns a record of HashMapLinkedNode objects with string keys.
408
+ * @returns The method is returning a Record object, which is a TypeScript type that represents an
409
+ * object with string keys and values that are HashMapLinkedNode objects with keys of type K and
410
+ * values of type V or undefined.
411
+ */
412
+ get noObjMap() {
413
+ return this._noObjMap;
414
+ }
415
+ /**
416
+ * The function returns the WeakMap object used to map objects to HashMapLinkedNode instances.
417
+ * @returns The `objMap` property is being returned.
418
+ */
419
+ get objMap() {
420
+ return this._objMap;
421
+ }
422
+ /**
423
+ * The function returns the head node of a HashMapLinkedNode.
424
+ * @returns The method `getHead()` is returning a `HashMapLinkedNode` object with key type `K` and
425
+ * value type `V | undefined`.
426
+ */
427
+ get head() {
428
+ return this._head;
429
+ }
430
+ /**
431
+ * The function returns the tail node of a HashMapLinkedNode.
432
+ * @returns The `_tail` property of type `HashMapLinkedNode<K, V | undefined>` is being returned.
433
+ */
434
+ get tail() {
435
+ return this._tail;
436
+ }
364
437
  /**
365
438
  * The function returns the value of the _toEntryFn property.
366
439
  * @returns The function being returned is `this._toEntryFn`.
@@ -375,6 +448,10 @@ class LinkedHashMap extends base_1.IterableEntryBase {
375
448
  get size() {
376
449
  return this._size;
377
450
  }
451
+ /**
452
+ * Time Complexity: O(1)
453
+ * Space Complexity: O(1)
454
+ */
378
455
  /**
379
456
  * Time Complexity: O(1)
380
457
  * Space Complexity: O(1)
@@ -386,8 +463,12 @@ class LinkedHashMap extends base_1.IterableEntryBase {
386
463
  get first() {
387
464
  if (this._size === 0)
388
465
  return;
389
- return [this._head.key, this._head.value];
466
+ return [this.head.key, this.head.value];
390
467
  }
468
+ /**
469
+ * Time Complexity: O(1)
470
+ * Space Complexity: O(1)
471
+ */
391
472
  /**
392
473
  * Time Complexity: O(1)
393
474
  * Space Complexity: O(1)
@@ -399,13 +480,13 @@ class LinkedHashMap extends base_1.IterableEntryBase {
399
480
  get last() {
400
481
  if (this._size === 0)
401
482
  return;
402
- return [this._tail.key, this._tail.value];
483
+ return [this.tail.key, this.tail.value];
403
484
  }
404
485
  /**
405
486
  * The `begin()` function in TypeScript iterates over a linked list and yields key-value pairs.
406
487
  */
407
488
  *begin() {
408
- let node = this._head;
489
+ let node = this.head;
409
490
  while (node !== this._sentinel) {
410
491
  yield [node.key, node.value];
411
492
  node = node.next;
@@ -416,12 +497,16 @@ class LinkedHashMap extends base_1.IterableEntryBase {
416
497
  * key and value.
417
498
  */
418
499
  *reverseBegin() {
419
- let node = this._tail;
500
+ let node = this.tail;
420
501
  while (node !== this._sentinel) {
421
502
  yield [node.key, node.value];
422
503
  node = node.prev;
423
504
  }
424
505
  }
506
+ /**
507
+ * Time Complexity: O(1)
508
+ * Space Complexity: O(1)
509
+ */
425
510
  /**
426
511
  * Time Complexity: O(1)
427
512
  * Space Complexity: O(1)
@@ -438,12 +523,12 @@ class LinkedHashMap extends base_1.IterableEntryBase {
438
523
  let node;
439
524
  const isNewKey = !this.has(key); // Check if the key is new
440
525
  if ((0, utils_1.isWeakKey)(key)) {
441
- const hash = this._objHashFn(key);
442
- node = this._objMap.get(hash);
526
+ const hash = this.objHashFn(key);
527
+ node = this.objMap.get(hash);
443
528
  if (!node && isNewKey) {
444
529
  // Create new node
445
- node = { key: hash, value, prev: this._tail, next: this._sentinel };
446
- this._objMap.set(hash, node);
530
+ node = { key: hash, value, prev: this.tail, next: this._sentinel };
531
+ this.objMap.set(hash, node);
447
532
  }
448
533
  else if (node) {
449
534
  // Update the value of an existing node
@@ -451,10 +536,10 @@ class LinkedHashMap extends base_1.IterableEntryBase {
451
536
  }
452
537
  }
453
538
  else {
454
- const hash = this._hashFn(key);
455
- node = this._noObjMap[hash];
539
+ const hash = this.hashFn(key);
540
+ node = this.noObjMap[hash];
456
541
  if (!node && isNewKey) {
457
- this._noObjMap[hash] = node = { key, value, prev: this._tail, next: this._sentinel };
542
+ this.noObjMap[hash] = node = { key, value, prev: this.tail, next: this._sentinel };
458
543
  }
459
544
  else if (node) {
460
545
  // Update the value of an existing node
@@ -468,8 +553,8 @@ class LinkedHashMap extends base_1.IterableEntryBase {
468
553
  this._sentinel.next = node;
469
554
  }
470
555
  else {
471
- this._tail.next = node;
472
- node.prev = this._tail; // Make sure that the prev of the new node points to the current tail node
556
+ this.tail.next = node;
557
+ node.prev = this.tail; // Make sure that the prev of the new node points to the current tail node
473
558
  }
474
559
  this._tail = node;
475
560
  this._sentinel.prev = node;
@@ -501,14 +586,18 @@ class LinkedHashMap extends base_1.IterableEntryBase {
501
586
  */
502
587
  has(key) {
503
588
  if ((0, utils_1.isWeakKey)(key)) {
504
- const hash = this._objHashFn(key);
505
- return this._objMap.has(hash);
589
+ const hash = this.objHashFn(key);
590
+ return this.objMap.has(hash);
506
591
  }
507
592
  else {
508
- const hash = this._hashFn(key);
509
- return hash in this._noObjMap;
593
+ const hash = this.hashFn(key);
594
+ return hash in this.noObjMap;
510
595
  }
511
596
  }
597
+ /**
598
+ * Time Complexity: O(1)
599
+ * Space Complexity: O(1)
600
+ */
512
601
  /**
513
602
  * Time Complexity: O(1)
514
603
  * Space Complexity: O(1)
@@ -524,18 +613,23 @@ class LinkedHashMap extends base_1.IterableEntryBase {
524
613
  */
525
614
  get(key) {
526
615
  if ((0, utils_1.isWeakKey)(key)) {
527
- const hash = this._objHashFn(key);
528
- const node = this._objMap.get(hash);
616
+ const hash = this.objHashFn(key);
617
+ const node = this.objMap.get(hash);
529
618
  return node ? node.value : undefined;
530
619
  }
531
620
  else {
532
- const hash = this._hashFn(key);
533
- const node = this._noObjMap[hash];
621
+ const hash = this.hashFn(key);
622
+ const node = this.noObjMap[hash];
534
623
  return node ? node.value : undefined;
535
624
  }
536
625
  }
537
626
  /**
538
- * Time Complexity: O(n), where n is the index.
627
+ * Time Complexity: O(n)
628
+ * Space Complexity: O(1)
629
+ * /
630
+
631
+ /**
632
+ * Time Complexity: O(n)
539
633
  * Space Complexity: O(1)
540
634
  *
541
635
  * The function `at` retrieves the key-value pair at a specified index in a linked list.
@@ -547,13 +641,18 @@ class LinkedHashMap extends base_1.IterableEntryBase {
547
641
  */
548
642
  at(index) {
549
643
  (0, utils_1.rangeCheck)(index, 0, this._size - 1);
550
- let node = this._head;
644
+ let node = this.head;
551
645
  while (index--) {
552
646
  node = node.next;
553
647
  }
554
648
  return node.value;
555
649
  }
556
650
  /**
651
+ * Time Complexity: O(1)
652
+ * Space Complexity: O(1)
653
+ * /
654
+
655
+ /**
557
656
  * Time Complexity: O(1)
558
657
  * Space Complexity: O(1)
559
658
  *
@@ -566,30 +665,35 @@ class LinkedHashMap extends base_1.IterableEntryBase {
566
665
  delete(key) {
567
666
  let node;
568
667
  if ((0, utils_1.isWeakKey)(key)) {
569
- const hash = this._objHashFn(key);
668
+ const hash = this.objHashFn(key);
570
669
  // Get nodes from WeakMap
571
- node = this._objMap.get(hash);
670
+ node = this.objMap.get(hash);
572
671
  if (!node) {
573
672
  return false; // If the node does not exist, return false
574
673
  }
575
674
  // Remove nodes from WeakMap
576
- this._objMap.delete(hash);
675
+ this.objMap.delete(hash);
577
676
  }
578
677
  else {
579
- const hash = this._hashFn(key);
678
+ const hash = this.hashFn(key);
580
679
  // Get nodes from noObjMap
581
- node = this._noObjMap[hash];
680
+ node = this.noObjMap[hash];
582
681
  if (!node) {
583
682
  return false; // If the node does not exist, return false
584
683
  }
585
684
  // Remove nodes from orgMap
586
- delete this._noObjMap[hash];
685
+ delete this.noObjMap[hash];
587
686
  }
588
687
  // Remove node from doubly linked list
589
688
  this._deleteNode(node);
590
689
  return true;
591
690
  }
592
691
  /**
692
+ * Time Complexity: O(n)
693
+ * Space Complexity: O(1)
694
+ * /
695
+
696
+ /**
593
697
  * Time Complexity: O(n)
594
698
  * Space Complexity: O(1)
595
699
  *
@@ -600,13 +704,18 @@ class LinkedHashMap extends base_1.IterableEntryBase {
600
704
  */
601
705
  deleteAt(index) {
602
706
  (0, utils_1.rangeCheck)(index, 0, this._size - 1);
603
- let node = this._head;
707
+ let node = this.head;
604
708
  while (index--) {
605
709
  node = node.next;
606
710
  }
607
711
  return this._deleteNode(node);
608
712
  }
609
713
  /**
714
+ * Time Complexity: O(1)
715
+ * Space Complexity: O(1)
716
+ * /
717
+
718
+ /**
610
719
  * Time Complexity: O(1)
611
720
  * Space Complexity: O(1)
612
721
  *
@@ -627,6 +736,11 @@ class LinkedHashMap extends base_1.IterableEntryBase {
627
736
  return Array.isArray(rawElement) && rawElement.length === 2;
628
737
  }
629
738
  /**
739
+ * Time Complexity: O(1)
740
+ * Space Complexity: O(1)
741
+ * /
742
+
743
+ /**
630
744
  * Time Complexity: O(1)
631
745
  * Space Complexity: O(1)
632
746
  *
@@ -651,7 +765,7 @@ class LinkedHashMap extends base_1.IterableEntryBase {
651
765
  * of the original `LinkedHashMap` object.
652
766
  */
653
767
  clone() {
654
- const cloned = new LinkedHashMap([], { hashFn: this._hashFn, objHashFn: this._objHashFn });
768
+ const cloned = new LinkedHashMap([], { hashFn: this.hashFn, objHashFn: this.objHashFn });
655
769
  for (const entry of this) {
656
770
  const [key, value] = entry;
657
771
  cloned.set(key, value);
@@ -659,6 +773,11 @@ class LinkedHashMap extends base_1.IterableEntryBase {
659
773
  return cloned;
660
774
  }
661
775
  /**
776
+ * Time Complexity: O(n)
777
+ * Space Complexity: O(n)
778
+ * /
779
+
780
+ /**
662
781
  * Time Complexity: O(n)
663
782
  * Space Complexity: O(n)
664
783
  *
@@ -685,6 +804,11 @@ class LinkedHashMap extends base_1.IterableEntryBase {
685
804
  return filteredMap;
686
805
  }
687
806
  /**
807
+ * Time Complexity: O(n)
808
+ * Space Complexity: O(n)
809
+ * /
810
+
811
+ /**
688
812
  * Time Complexity: O(n)
689
813
  * Space Complexity: O(n)
690
814
  *
@@ -730,6 +854,12 @@ class LinkedHashMap extends base_1.IterableEntryBase {
730
854
  return this.set(key, value);
731
855
  }
732
856
  /**
857
+ * Time Complexity: O(n)
858
+ * Space Complexity: O(1)
859
+ * where n is the number of entries in the LinkedHashMap.
860
+ * /
861
+
862
+ /**
733
863
  * Time Complexity: O(n)
734
864
  * Space Complexity: O(1)
735
865
  * where n is the number of entries in the LinkedHashMap.
@@ -737,12 +867,16 @@ class LinkedHashMap extends base_1.IterableEntryBase {
737
867
  * The above function is an iterator that yields key-value pairs from a linked list.
738
868
  */
739
869
  *_getIterator() {
740
- let node = this._head;
870
+ let node = this.head;
741
871
  while (node !== this._sentinel) {
742
872
  yield [node.key, node.value];
743
873
  node = node.next;
744
874
  }
745
875
  }
876
+ /**
877
+ * Time Complexity: O(1)
878
+ * Space Complexity: O(1)
879
+ */
746
880
  /**
747
881
  * Time Complexity: O(1)
748
882
  * Space Complexity: O(1)
@@ -757,10 +891,10 @@ class LinkedHashMap extends base_1.IterableEntryBase {
757
891
  const { prev, next } = node;
758
892
  prev.next = next;
759
893
  next.prev = prev;
760
- if (node === this._head) {
894
+ if (node === this.head) {
761
895
  this._head = next;
762
896
  }
763
- if (node === this._tail) {
897
+ if (node === this.tail) {
764
898
  this._tail = prev;
765
899
  }
766
900
  this._size -= 1;
@@ -86,6 +86,10 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
86
86
  * @returns The top element or undefined if the heap is empty.
87
87
  */
88
88
  poll(): E | undefined;
89
+ /**
90
+ * Time Complexity: O(1)
91
+ * Space Complexity: O(1)
92
+ */
89
93
  /**
90
94
  * Time Complexity: O(1)
91
95
  * Space Complexity: O(1)
@@ -104,11 +108,11 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
104
108
  */
105
109
  clear(): void;
106
110
  /**
107
- * Time Complexity: O(n), where n is the number of elements in the elements array.
111
+ * Time Complexity: O(n)
108
112
  * Space Complexity: O(n)
109
113
  */
110
114
  /**
111
- * Time Complexity: O(n), where n is the number of elements in the elements array.
115
+ * Time Complexity: O(n)
112
116
  * Space Complexity: O(n)
113
117
  *
114
118
  * Clear and add elements of the heap
@@ -116,11 +120,11 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
116
120
  */
117
121
  refill(elements: E[]): boolean[];
118
122
  /**
119
- * Time Complexity: O(n), where n is the number of elements in the heap.
123
+ * Time Complexity: O(n)
120
124
  * Space Complexity: O(1)
121
125
  */
122
126
  /**
123
- * Time Complexity: O(n), where n is the number of elements in the heap.
127
+ * Time Complexity: O(n)
124
128
  * Space Complexity: O(1)
125
129
  *
126
130
  * Use a comparison function to check whether a binary heap contains a specific element.
@@ -129,11 +133,12 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
129
133
  */
130
134
  has(element: E): boolean;
131
135
  /**
132
- * Time Complexity: O(n). The worst-case O(n), where n is the number of elements in the heap. This is because, in the worst case, the element to be deleted is located at the end of the heap (not the root), and after deletion, we may need to reorganize the elements by performing a sinkDown operation.
136
+ * Time Complexity: O(n)
133
137
  * Space Complexity: O(1)
138
+ * The worst-case O(n) This is because, in the worst case, the element to be deleted is located at the end of the heap (not the root), and after deletion, we may need to reorganize the elements by performing a sinkDown operation.
134
139
  */
135
140
  /**
136
- * Time Complexity: O(n). The worst-case O(n), where n is the number of elements in the heap. This is because, in the worst case, the element to be deleted is located at the end of the heap (not the root), and after deletion, we may need to reorganize the elements by performing a sinkDown operation.
141
+ * Time Complexity: O(n)
137
142
  * Space Complexity: O(1)
138
143
  *
139
144
  * The `delete` function removes an element from an array-like data structure, maintaining the order
@@ -145,12 +150,13 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
145
150
  */
146
151
  delete(element: E): boolean;
147
152
  /**
148
- * Time Complexity: O(n), where n is the number of elements in the heap.
149
- * Space Complexity: O(h), where h is the height of the heap.
153
+ * Time Complexity: O(n)
154
+ * Space Complexity: O(log n)
155
+ * where log n is the height of the heap.
150
156
  */
151
157
  /**
152
- * Time Complexity: O(n), where n is the number of elements in the heap.
153
- * Space Complexity: O(h), where h is the height of the heap.
158
+ * Time Complexity: O(n)
159
+ * Space Complexity: O(log n)
154
160
  *
155
161
  * Depth-first search (DFS) method, different traversal orders can be selected。
156
162
  * @param order - Traverse order parameter: 'in' (in-order), 'pre' (pre-order) or 'post' (post-order).
@@ -194,12 +200,12 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
194
200
  */
195
201
  sort(): E[];
196
202
  /**
197
- * Time Complexity: O(log n)
198
- * Space Complexity: O(1)
203
+ * Time Complexity: O(n log n)
204
+ * Space Complexity: O(n)
199
205
  */
200
206
  /**
201
- * Time Complexity: O(n)
202
- * Space Complexity: O(1)
207
+ * Time Complexity: O(n log n)
208
+ * Space Complexity: O(n)
203
209
  *
204
210
  * Fix the entire heap to maintain heap properties.
205
211
  */
@@ -255,7 +261,7 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
255
261
  */
256
262
  protected _getIterator(): IterableIterator<E>;
257
263
  /**
258
- * Time Complexity: O(n)
264
+ * Time Complexity: O(log n)
259
265
  * Space Complexity: O(1)
260
266
  */
261
267
  /**
@@ -266,6 +272,10 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
266
272
  * @param index - The index of the newly added element.
267
273
  */
268
274
  protected _bubbleUp(index: number): boolean;
275
+ /**
276
+ * Time Complexity: O(log n)
277
+ * Space Complexity: O(1)
278
+ */
269
279
  /**
270
280
  * Time Complexity: O(log n)
271
281
  * Space Complexity: O(1)
@@ -397,11 +407,11 @@ export declare class FibonacciHeap<E> {
397
407
  */
398
408
  mergeWithChild(parent: FibonacciHeapNode<E>, node: FibonacciHeapNode<E>): void;
399
409
  /**
400
- * Time Complexity: O(log n), where n is the number of elements in the heap.
410
+ * Time Complexity: O(log n)
401
411
  * Space Complexity: O(1)
402
412
  */
403
413
  /**
404
- * Time Complexity: O(log n), where n is the number of elements in the heap.
414
+ * Time Complexity: O(log n)
405
415
  * Space Complexity: O(1)
406
416
  *
407
417
  * Remove and return the top element (smallest or largest element) from the heap.
@@ -409,11 +419,11 @@ export declare class FibonacciHeap<E> {
409
419
  */
410
420
  poll(): E | undefined;
411
421
  /**
412
- * Time Complexity: O(log n), where n is the number of elements in the heap.
422
+ * Time Complexity: O(log n)
413
423
  * Space Complexity: O(1)
414
424
  */
415
425
  /**
416
- * Time Complexity: O(log n), where n is the number of elements in the heap.
426
+ * Time Complexity: O(log n)
417
427
  * Space Complexity: O(1)
418
428
  *
419
429
  * Remove and return the top element (smallest or largest element) from the heap.