deque-typed 1.52.4 → 1.52.5

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 (74) hide show
  1. package/dist/data-structures/base/iterable-element-base.d.ts +1 -37
  2. package/dist/data-structures/base/iterable-element-base.js +1 -37
  3. package/dist/data-structures/base/iterable-entry-base.d.ts +2 -54
  4. package/dist/data-structures/base/iterable-entry-base.js +1 -49
  5. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -32
  6. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +9 -41
  7. package/dist/data-structures/binary-tree/avl-tree.d.ts +0 -46
  8. package/dist/data-structures/binary-tree/avl-tree.js +0 -46
  9. package/dist/data-structures/binary-tree/binary-tree.d.ts +82 -147
  10. package/dist/data-structures/binary-tree/binary-tree.js +299 -331
  11. package/dist/data-structures/binary-tree/bst.d.ts +1 -40
  12. package/dist/data-structures/binary-tree/bst.js +12 -44
  13. package/dist/data-structures/binary-tree/rb-tree.d.ts +0 -48
  14. package/dist/data-structures/binary-tree/rb-tree.js +2 -50
  15. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +0 -32
  16. package/dist/data-structures/binary-tree/tree-multi-map.js +9 -41
  17. package/dist/data-structures/graph/abstract-graph.d.ts +0 -75
  18. package/dist/data-structures/graph/abstract-graph.js +0 -75
  19. package/dist/data-structures/graph/directed-graph.d.ts +0 -98
  20. package/dist/data-structures/graph/directed-graph.js +0 -98
  21. package/dist/data-structures/graph/undirected-graph.d.ts +0 -50
  22. package/dist/data-structures/graph/undirected-graph.js +0 -50
  23. package/dist/data-structures/hash/hash-map.d.ts +5 -92
  24. package/dist/data-structures/hash/hash-map.js +27 -111
  25. package/dist/data-structures/heap/heap.d.ts +0 -32
  26. package/dist/data-structures/heap/heap.js +0 -32
  27. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +5 -88
  28. package/dist/data-structures/linked-list/doubly-linked-list.js +5 -88
  29. package/dist/data-structures/linked-list/singly-linked-list.d.ts +1 -83
  30. package/dist/data-structures/linked-list/singly-linked-list.js +2 -84
  31. package/dist/data-structures/linked-list/skip-linked-list.d.ts +1 -35
  32. package/dist/data-structures/linked-list/skip-linked-list.js +1 -35
  33. package/dist/data-structures/queue/deque.d.ts +1 -98
  34. package/dist/data-structures/queue/deque.js +3 -99
  35. package/dist/data-structures/queue/queue.d.ts +1 -54
  36. package/dist/data-structures/queue/queue.js +0 -53
  37. package/dist/data-structures/stack/stack.d.ts +1 -34
  38. package/dist/data-structures/stack/stack.js +1 -34
  39. package/dist/data-structures/tree/tree.js +2 -1
  40. package/dist/data-structures/trie/trie.d.ts +0 -64
  41. package/dist/data-structures/trie/trie.js +0 -64
  42. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +8 -0
  43. package/dist/types/data-structures/binary-tree/binary-tree.js +6 -0
  44. package/dist/types/utils/utils.d.ts +13 -12
  45. package/dist/utils/number.d.ts +13 -0
  46. package/dist/utils/number.js +13 -0
  47. package/dist/utils/utils.d.ts +125 -3
  48. package/dist/utils/utils.js +177 -21
  49. package/package.json +2 -2
  50. package/src/data-structures/base/iterable-element-base.ts +2 -42
  51. package/src/data-structures/base/iterable-entry-base.ts +3 -62
  52. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +8 -48
  53. package/src/data-structures/binary-tree/avl-tree.ts +0 -57
  54. package/src/data-structures/binary-tree/binary-tree.ts +329 -358
  55. package/src/data-structures/binary-tree/bst.ts +11 -54
  56. package/src/data-structures/binary-tree/rb-tree.ts +2 -62
  57. package/src/data-structures/binary-tree/tree-multi-map.ts +8 -48
  58. package/src/data-structures/graph/abstract-graph.ts +0 -92
  59. package/src/data-structures/graph/directed-graph.ts +0 -122
  60. package/src/data-structures/graph/undirected-graph.ts +0 -62
  61. package/src/data-structures/hash/hash-map.ts +29 -133
  62. package/src/data-structures/heap/heap.ts +0 -40
  63. package/src/data-structures/linked-list/doubly-linked-list.ts +5 -112
  64. package/src/data-structures/linked-list/singly-linked-list.ts +2 -104
  65. package/src/data-structures/linked-list/skip-linked-list.ts +1 -44
  66. package/src/data-structures/queue/deque.ts +2 -125
  67. package/src/data-structures/queue/queue.ts +1 -68
  68. package/src/data-structures/stack/stack.ts +1 -43
  69. package/src/data-structures/tree/tree.ts +1 -1
  70. package/src/data-structures/trie/trie.ts +0 -80
  71. package/src/types/data-structures/binary-tree/binary-tree.ts +8 -1
  72. package/src/types/utils/utils.ts +17 -15
  73. package/src/utils/number.ts +13 -0
  74. package/src/utils/utils.ts +174 -18
@@ -163,8 +163,8 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
163
163
  if (this.isEntry(rawEle)) {
164
164
  key = rawEle[0];
165
165
  value = rawEle[1];
166
- } else if (this.toEntryFn) {
167
- const item = this.toEntryFn(rawEle);
166
+ } else if (this._toEntryFn) {
167
+ const item = this._toEntryFn(rawEle);
168
168
  key = item[0];
169
169
  value = item[1];
170
170
  }
@@ -234,9 +234,7 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
234
234
  /**
235
235
  * Time Complexity: O(n)
236
236
  * Space Complexity: O(n)
237
- */
238
-
239
- /**
237
+ *
240
238
  * The clone function creates a new HashMap with the same key-value pairs as
241
239
  * this one. The clone function is useful for creating a copy of an existing
242
240
  * HashMap, and then modifying that copy without affecting the original.
@@ -244,14 +242,9 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
244
242
  * @return A new hashmap with the same values as this one
245
243
  */
246
244
  clone(): HashMap<K, V, R> {
247
- return new HashMap<K, V, R>(this, { hashFn: this.hashFn, toEntryFn: this.toEntryFn });
245
+ return new HashMap<K, V, R>(this, { hashFn: this._hashFn, toEntryFn: this._toEntryFn });
248
246
  }
249
247
 
250
- /**
251
- * Time Complexity: O(n)
252
- * Space Complexity: O(n)
253
- */
254
-
255
248
  /**
256
249
  * Time Complexity: O(n)
257
250
  * Space Complexity: O(n)
@@ -302,18 +295,6 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
302
295
  return filteredMap;
303
296
  }
304
297
 
305
- /**
306
- * The put function sets a value in a data structure using a specified key.
307
- * @param {K} key - The key parameter is of type K, which represents the type of the key being passed
308
- * to the function.
309
- * @param {V} value - The value parameter represents the value that you want to associate with the
310
- * specified key in the data structure.
311
- * @returns The method is returning a boolean value.
312
- */
313
- put(key: K, value: V): boolean {
314
- return this.set(key, value);
315
- }
316
-
317
298
  /**
318
299
  * The function returns an iterator that yields key-value pairs from both an object store and an
319
300
  * object map.
@@ -349,7 +330,7 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
349
330
 
350
331
  let strKey: string;
351
332
  if (keyType !== 'string' && keyType !== 'number' && keyType !== 'symbol') {
352
- strKey = this.hashFn(key);
333
+ strKey = this._hashFn(key);
353
334
  } else {
354
335
  if (keyType === 'number') {
355
336
  // TODO numeric key should has its own hash
@@ -379,7 +360,7 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
379
360
  * @param [options] - The `options` parameter is an optional object that can contain the following
380
361
  * properties:
381
362
  */
382
- constructor(entryOrRawElements: Iterable<R> = [], options?: LinkedHashMapOptions<K, V, R>) {
363
+ constructor(entryOrRawElements: Iterable<R | [K, V]> = [], options?: LinkedHashMapOptions<K, V, R>) {
383
364
  super();
384
365
  this._sentinel = <HashMapLinkedNode<K, V>>{};
385
366
  this._sentinel.prev = this._sentinel.next = this._head = this._tail = this._sentinel;
@@ -395,10 +376,7 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
395
376
  }
396
377
 
397
378
  if (entryOrRawElements) {
398
- for (const el of entryOrRawElements) {
399
- const [key, value] = this.toEntryFn(el);
400
- this.set(key, value);
401
- }
379
+ this.setMany(entryOrRawElements);
402
380
  }
403
381
  }
404
382
 
@@ -465,7 +443,7 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
465
443
  return this._tail;
466
444
  }
467
445
 
468
- protected _toEntryFn: (rawElement: R) => [K, V] = (rawElement: R) => {
446
+ protected _toEntryFn?: (rawElement: R) => [K, V] = (rawElement: R) => {
469
447
  if (this.isEntry(rawElement)) {
470
448
  // TODO, For performance optimization, it may be necessary to only inspect the first element traversed.
471
449
  return rawElement;
@@ -494,11 +472,6 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
494
472
  return this._size;
495
473
  }
496
474
 
497
- /**
498
- * Time Complexity: O(1)
499
- * Space Complexity: O(1)
500
- */
501
-
502
475
  /**
503
476
  * Time Complexity: O(1)
504
477
  * Space Complexity: O(1)
@@ -512,11 +485,6 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
512
485
  return <[K, V]>[this.head.key, this.head.value];
513
486
  }
514
487
 
515
- /**
516
- * Time Complexity: O(1)
517
- * Space Complexity: O(1)
518
- */
519
-
520
488
  /**
521
489
  * Time Complexity: O(1)
522
490
  * Space Complexity: O(1)
@@ -553,11 +521,6 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
553
521
  }
554
522
  }
555
523
 
556
- /**
557
- * Time Complexity: O(1)
558
- * Space Complexity: O(1)
559
- */
560
-
561
524
  /**
562
525
  * Time Complexity: O(1)
563
526
  * Space Complexity: O(1)
@@ -575,7 +538,7 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
575
538
  const isNewKey = !this.has(key); // Check if the key is new
576
539
 
577
540
  if (isWeakKey(key)) {
578
- const hash = this.objHashFn(key);
541
+ const hash = this._objHashFn(key);
579
542
  node = this.objMap.get(hash);
580
543
 
581
544
  if (!node && isNewKey) {
@@ -587,7 +550,7 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
587
550
  node.value = value;
588
551
  }
589
552
  } else {
590
- const hash = this.hashFn(key);
553
+ const hash = this._hashFn(key);
591
554
  node = this.noObjMap[hash];
592
555
 
593
556
  if (!node && isNewKey) {
@@ -623,11 +586,20 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
623
586
  * R.
624
587
  * @returns The `setMany` function returns an array of booleans.
625
588
  */
626
- setMany(entryOrRawElements: Iterable<R>): boolean[] {
589
+ setMany(entryOrRawElements: Iterable<R | [K, V]>): boolean[] {
627
590
  const results: boolean[] = [];
628
591
  for (const rawEle of entryOrRawElements) {
629
- const [key, value] = this.toEntryFn(rawEle);
630
- results.push(this.set(key, value));
592
+ let key: K | undefined, value: V | undefined;
593
+ if (this.isEntry(rawEle)) {
594
+ key = rawEle[0];
595
+ value = rawEle[1];
596
+ } else if (this._toEntryFn) {
597
+ const item = this._toEntryFn(rawEle);
598
+ key = item[0];
599
+ value = item[1];
600
+ }
601
+
602
+ if (key !== undefined && value !== undefined) results.push(this.set(key, value));
631
603
  }
632
604
  return results;
633
605
  }
@@ -640,19 +612,14 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
640
612
  */
641
613
  override has(key: K): boolean {
642
614
  if (isWeakKey(key)) {
643
- const hash = this.objHashFn(key);
615
+ const hash = this._objHashFn(key);
644
616
  return this.objMap.has(hash);
645
617
  } else {
646
- const hash = this.hashFn(key);
618
+ const hash = this._hashFn(key);
647
619
  return hash in this.noObjMap;
648
620
  }
649
621
  }
650
622
 
651
- /**
652
- * Time Complexity: O(1)
653
- * Space Complexity: O(1)
654
- */
655
-
656
623
  /**
657
624
  * Time Complexity: O(1)
658
625
  * Space Complexity: O(1)
@@ -668,21 +635,16 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
668
635
  */
669
636
  override get(key: K): V | undefined {
670
637
  if (isWeakKey(key)) {
671
- const hash = this.objHashFn(key);
638
+ const hash = this._objHashFn(key);
672
639
  const node = this.objMap.get(hash);
673
640
  return node ? node.value : undefined;
674
641
  } else {
675
- const hash = this.hashFn(key);
642
+ const hash = this._hashFn(key);
676
643
  const node = this.noObjMap[hash];
677
644
  return node ? node.value : undefined;
678
645
  }
679
646
  }
680
647
 
681
- /**
682
- * Time Complexity: O(n)
683
- * Space Complexity: O(1)
684
- */
685
-
686
648
  /**
687
649
  * Time Complexity: O(n)
688
650
  * Space Complexity: O(1)
@@ -703,11 +665,6 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
703
665
  return node.value;
704
666
  }
705
667
 
706
- /**
707
- * Time Complexity: O(1)
708
- * Space Complexity: O(1)
709
- */
710
-
711
668
  /**
712
669
  * Time Complexity: O(1)
713
670
  * Space Complexity: O(1)
@@ -722,7 +679,7 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
722
679
  let node;
723
680
 
724
681
  if (isWeakKey(key)) {
725
- const hash = this.objHashFn(key);
682
+ const hash = this._objHashFn(key);
726
683
  // Get nodes from WeakMap
727
684
  node = this.objMap.get(hash);
728
685
 
@@ -733,7 +690,7 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
733
690
  // Remove nodes from WeakMap
734
691
  this.objMap.delete(hash);
735
692
  } else {
736
- const hash = this.hashFn(key);
693
+ const hash = this._hashFn(key);
737
694
  // Get nodes from noObjMap
738
695
  node = this.noObjMap[hash];
739
696
 
@@ -750,11 +707,6 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
750
707
  return true;
751
708
  }
752
709
 
753
- /**
754
- * Time Complexity: O(n)
755
- * Space Complexity: O(1)
756
- */
757
-
758
710
  /**
759
711
  * Time Complexity: O(n)
760
712
  * Space Complexity: O(1)
@@ -773,11 +725,6 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
773
725
  return this._deleteNode(node);
774
726
  }
775
727
 
776
- /**
777
- * Time Complexity: O(1)
778
- * Space Complexity: O(1)
779
- */
780
-
781
728
  /**
782
729
  * Time Complexity: O(1)
783
730
  * Space Complexity: O(1)
@@ -800,11 +747,6 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
800
747
  return Array.isArray(rawElement) && rawElement.length === 2;
801
748
  }
802
749
 
803
- /**
804
- * Time Complexity: O(1)
805
- * Space Complexity: O(1)
806
- */
807
-
808
750
  /**
809
751
  * Time Complexity: O(1)
810
752
  * Space Complexity: O(1)
@@ -817,11 +759,6 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
817
759
  this._head = this._tail = this._sentinel.prev = this._sentinel.next = this._sentinel;
818
760
  }
819
761
 
820
- /**
821
- * Time Complexity: O(n)
822
- * Space Complexity: O(n)
823
- */
824
-
825
762
  /**
826
763
  * Time Complexity: O(n)
827
764
  * Space Complexity: O(n)
@@ -832,7 +769,7 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
832
769
  * of the original `LinkedHashMap` object.
833
770
  */
834
771
  clone(): LinkedHashMap<K, V> {
835
- const cloned = new LinkedHashMap<K, V>([], { hashFn: this.hashFn, objHashFn: this.objHashFn });
772
+ const cloned = new LinkedHashMap<K, V>([], { hashFn: this._hashFn, objHashFn: this._objHashFn });
836
773
  for (const entry of this) {
837
774
  const [key, value] = entry;
838
775
  cloned.set(key, value);
@@ -840,11 +777,6 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
840
777
  return cloned;
841
778
  }
842
779
 
843
- /**
844
- * Time Complexity: O(n)
845
- * Space Complexity: O(n)
846
- */
847
-
848
780
  /**
849
781
  * Time Complexity: O(n)
850
782
  * Space Complexity: O(n)
@@ -872,11 +804,6 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
872
804
  return filteredMap;
873
805
  }
874
806
 
875
- /**
876
- * Time Complexity: O(n)
877
- * Space Complexity: O(n)
878
- */
879
-
880
807
  /**
881
808
  * Time Complexity: O(n)
882
809
  * Space Complexity: O(n)
@@ -905,32 +832,6 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
905
832
  return mappedMap;
906
833
  }
907
834
 
908
- /**
909
- * Time Complexity: O(1)
910
- * Space Complexity: O(1)
911
- */
912
-
913
- /**
914
- * Time Complexity: O(1)
915
- * Space Complexity: O(1)
916
- *
917
- * The put function sets a value in a data structure using a specified key.
918
- * @param {K} key - The key parameter is of type K, which represents the type of the key being passed
919
- * to the function.
920
- * @param {V} value - The value parameter represents the value that you want to associate with the
921
- * specified key in the data structure.
922
- * @returns The method is returning a boolean value.
923
- */
924
- put(key: K, value: V): boolean {
925
- return this.set(key, value);
926
- }
927
-
928
- /**
929
- * Time Complexity: O(n)
930
- * Space Complexity: O(1)
931
- * where n is the number of entries in the LinkedHashMap.
932
- */
933
-
934
835
  /**
935
836
  * Time Complexity: O(n)
936
837
  * Space Complexity: O(1)
@@ -946,11 +847,6 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
946
847
  }
947
848
  }
948
849
 
949
- /**
950
- * Time Complexity: O(1)
951
- * Space Complexity: O(1)
952
- */
953
-
954
850
  /**
955
851
  * Time Complexity: O(1)
956
852
  * Space Complexity: O(1)
@@ -560,11 +560,6 @@ export class FibonacciHeap<E> {
560
560
  return this.min ? this.min.element : undefined;
561
561
  }
562
562
 
563
- /**
564
- * Time Complexity: O(n), where n is the number of elements in the linked list.
565
- * Space Complexity: O(1)
566
- */
567
-
568
563
  /**
569
564
  * Time Complexity: O(n), where n is the number of elements in the linked list.
570
565
  * Space Complexity: O(1)
@@ -612,11 +607,6 @@ export class FibonacciHeap<E> {
612
607
  }
613
608
  }
614
609
 
615
- /**
616
- * Time Complexity: O(log n)
617
- * Space Complexity: O(1)
618
- */
619
-
620
610
  /**
621
611
  * Time Complexity: O(log n)
622
612
  * Space Complexity: O(1)
@@ -628,11 +618,6 @@ export class FibonacciHeap<E> {
628
618
  return this.pop();
629
619
  }
630
620
 
631
- /**
632
- * Time Complexity: O(log n)
633
- * Space Complexity: O(1)
634
- */
635
-
636
621
  /**
637
622
  * Time Complexity: O(log n)
638
623
  * Space Complexity: O(1)
@@ -667,11 +652,6 @@ export class FibonacciHeap<E> {
667
652
  return z.element;
668
653
  }
669
654
 
670
- /**
671
- * Time Complexity: O(1)
672
- * Space Complexity: O(1)
673
- */
674
-
675
655
  /**
676
656
  * Time Complexity: O(1)
677
657
  * Space Complexity: O(1)
@@ -732,11 +712,6 @@ export class FibonacciHeap<E> {
732
712
  return 0;
733
713
  }
734
714
 
735
- /**
736
- * Time Complexity: O(1)
737
- * Space Complexity: O(1)
738
- */
739
-
740
715
  /**
741
716
  * Time Complexity: O(1)
742
717
  * Space Complexity: O(1)
@@ -755,11 +730,6 @@ export class FibonacciHeap<E> {
755
730
  }
756
731
  }
757
732
 
758
- /**
759
- * Time Complexity: O(1)
760
- * Space Complexity: O(1)
761
- */
762
-
763
733
  /**
764
734
  * Time Complexity: O(1)
765
735
  * Space Complexity: O(1)
@@ -774,11 +744,6 @@ export class FibonacciHeap<E> {
774
744
  if (node.right) node.right.left = node.left;
775
745
  }
776
746
 
777
- /**
778
- * Time Complexity: O(1)
779
- * Space Complexity: O(1)
780
- */
781
-
782
747
  /**
783
748
  * Time Complexity: O(1)
784
749
  * Space Complexity: O(1)
@@ -797,11 +762,6 @@ export class FibonacciHeap<E> {
797
762
  y.parent = x;
798
763
  }
799
764
 
800
- /**
801
- * Time Complexity: O(n log n)
802
- * Space Complexity: O(n)
803
- */
804
-
805
765
  /**
806
766
  * Time Complexity: O(n log n)
807
767
  * Space Complexity: O(n)