binary-tree-typed 2.5.2 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/dist/cjs/index.cjs +320 -55
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +320 -55
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +320 -55
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +320 -55
  8. package/dist/esm-legacy/index.mjs.map +1 -1
  9. package/dist/types/data-structures/base/iterable-element-base.d.ts +17 -0
  10. package/dist/types/data-structures/base/linear-base.d.ts +6 -0
  11. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +86 -2
  12. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +98 -0
  13. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +191 -15
  14. package/dist/types/data-structures/binary-tree/bst.d.ts +171 -3
  15. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +136 -8
  16. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +42 -0
  17. package/dist/types/data-structures/binary-tree/tree-map.d.ts +1061 -167
  18. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1232 -355
  19. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +916 -194
  20. package/dist/types/data-structures/binary-tree/tree-set.d.ts +1078 -141
  21. package/dist/types/data-structures/graph/directed-graph.d.ts +70 -0
  22. package/dist/types/data-structures/graph/undirected-graph.d.ts +63 -0
  23. package/dist/types/data-structures/hash/hash-map.d.ts +84 -6
  24. package/dist/types/data-structures/heap/heap.d.ts +140 -12
  25. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +150 -2
  26. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +106 -1
  27. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +126 -0
  28. package/dist/types/data-structures/matrix/matrix.d.ts +56 -0
  29. package/dist/types/data-structures/queue/deque.d.ts +171 -0
  30. package/dist/types/data-structures/queue/queue.d.ts +97 -0
  31. package/dist/types/data-structures/stack/stack.d.ts +72 -2
  32. package/dist/types/data-structures/trie/trie.d.ts +84 -0
  33. package/dist/types/interfaces/binary-tree.d.ts +2 -3
  34. package/dist/umd/binary-tree-typed.js +320 -55
  35. package/dist/umd/binary-tree-typed.js.map +1 -1
  36. package/dist/umd/binary-tree-typed.min.js +5 -5
  37. package/dist/umd/binary-tree-typed.min.js.map +1 -1
  38. package/package.json +2 -2
  39. package/src/data-structures/base/iterable-element-base.ts +32 -0
  40. package/src/data-structures/base/linear-base.ts +11 -0
  41. package/src/data-structures/binary-tree/avl-tree.ts +88 -5
  42. package/src/data-structures/binary-tree/binary-indexed-tree.ts +98 -0
  43. package/src/data-structures/binary-tree/binary-tree.ts +242 -81
  44. package/src/data-structures/binary-tree/bst.ts +173 -7
  45. package/src/data-structures/binary-tree/red-black-tree.ts +139 -15
  46. package/src/data-structures/binary-tree/segment-tree.ts +42 -0
  47. package/src/data-structures/binary-tree/tree-map.ts +948 -36
  48. package/src/data-structures/binary-tree/tree-multi-map.ts +893 -13
  49. package/src/data-structures/binary-tree/tree-multi-set.ts +761 -33
  50. package/src/data-structures/binary-tree/tree-set.ts +1260 -251
  51. package/src/data-structures/graph/directed-graph.ts +71 -1
  52. package/src/data-structures/graph/undirected-graph.ts +64 -1
  53. package/src/data-structures/hash/hash-map.ts +100 -12
  54. package/src/data-structures/heap/heap.ts +149 -19
  55. package/src/data-structures/linked-list/doubly-linked-list.ts +178 -2
  56. package/src/data-structures/linked-list/singly-linked-list.ts +106 -1
  57. package/src/data-structures/linked-list/skip-linked-list.ts +126 -0
  58. package/src/data-structures/matrix/matrix.ts +56 -0
  59. package/src/data-structures/queue/deque.ts +187 -0
  60. package/src/data-structures/queue/queue.ts +109 -0
  61. package/src/data-structures/stack/stack.ts +75 -5
  62. package/src/data-structures/trie/trie.ts +84 -0
  63. package/src/interfaces/binary-tree.ts +1 -9
@@ -241,6 +241,13 @@ export class DirectedGraph<
241
241
 
242
242
 
243
243
 
244
+
245
+
246
+
247
+
248
+
249
+
250
+
244
251
 
245
252
 
246
253
 
@@ -336,6 +343,13 @@ export class DirectedGraph<
336
343
 
337
344
 
338
345
 
346
+
347
+
348
+
349
+
350
+
351
+
352
+
339
353
 
340
354
 
341
355
 
@@ -426,6 +440,13 @@ export class DirectedGraph<
426
440
 
427
441
 
428
442
 
443
+
444
+
445
+
446
+
447
+
448
+
449
+
429
450
 
430
451
 
431
452
 
@@ -516,6 +537,13 @@ export class DirectedGraph<
516
537
 
517
538
 
518
539
 
540
+
541
+
542
+
543
+
544
+
545
+
546
+
519
547
 
520
548
 
521
549
 
@@ -571,6 +599,13 @@ export class DirectedGraph<
571
599
 
572
600
 
573
601
 
602
+
603
+
604
+
605
+
606
+
607
+
608
+
574
609
 
575
610
 
576
611
 
@@ -698,6 +733,13 @@ export class DirectedGraph<
698
733
 
699
734
 
700
735
 
736
+
737
+
738
+
739
+
740
+
741
+
742
+
701
743
 
702
744
 
703
745
 
@@ -792,6 +834,13 @@ export class DirectedGraph<
792
834
 
793
835
 
794
836
 
837
+
838
+
839
+
840
+
841
+
842
+
843
+
795
844
 
796
845
 
797
846
 
@@ -843,6 +892,13 @@ export class DirectedGraph<
843
892
 
844
893
 
845
894
 
895
+
896
+
897
+
898
+
899
+
900
+
901
+
846
902
 
847
903
 
848
904
 
@@ -909,7 +965,7 @@ export class DirectedGraph<
909
965
  * Remove all vertices and edges.
910
966
  * @remarks Time O(V + E), Space O(1)
911
967
  */
912
- clear() {
968
+ clear(): void {
913
969
  this._vertexMap = new Map<VertexKey, VO>();
914
970
  this._inEdgeMap = new Map<VO, EO[]>();
915
971
  this._outEdgeMap = new Map<VO, EO[]>();
@@ -952,6 +1008,13 @@ export class DirectedGraph<
952
1008
 
953
1009
 
954
1010
 
1011
+
1012
+
1013
+
1014
+
1015
+
1016
+
1017
+
955
1018
 
956
1019
 
957
1020
 
@@ -1071,6 +1134,13 @@ export class DirectedGraph<
1071
1134
 
1072
1135
 
1073
1136
 
1137
+
1138
+
1139
+
1140
+
1141
+
1142
+
1143
+
1074
1144
 
1075
1145
 
1076
1146
 
@@ -250,6 +250,13 @@ export class UndirectedGraph<
250
250
 
251
251
 
252
252
 
253
+
254
+
255
+
256
+
257
+
258
+
259
+
253
260
 
254
261
 
255
262
 
@@ -341,6 +348,13 @@ export class UndirectedGraph<
341
348
 
342
349
 
343
350
 
351
+
352
+
353
+
354
+
355
+
356
+
357
+
344
358
 
345
359
 
346
360
 
@@ -427,6 +441,13 @@ export class UndirectedGraph<
427
441
 
428
442
 
429
443
 
444
+
445
+
446
+
447
+
448
+
449
+
450
+
430
451
 
431
452
 
432
453
 
@@ -537,6 +558,13 @@ export class UndirectedGraph<
537
558
 
538
559
 
539
560
 
561
+
562
+
563
+
564
+
565
+
566
+
567
+
540
568
 
541
569
 
542
570
 
@@ -592,6 +620,13 @@ export class UndirectedGraph<
592
620
 
593
621
 
594
622
 
623
+
624
+
625
+
626
+
627
+
628
+
629
+
595
630
 
596
631
 
597
632
 
@@ -679,7 +714,7 @@ export class UndirectedGraph<
679
714
  * Remove all vertices and edges.
680
715
  * @remarks Time O(V + E), Space O(1)
681
716
  */
682
- clear() {
717
+ clear(): void {
683
718
  this._vertexMap = new Map<VertexKey, VO>();
684
719
  this._edgeMap = new Map<VO, EO[]>();
685
720
  }
@@ -721,6 +756,13 @@ export class UndirectedGraph<
721
756
 
722
757
 
723
758
 
759
+
760
+
761
+
762
+
763
+
764
+
765
+
724
766
 
725
767
 
726
768
 
@@ -894,6 +936,13 @@ export class UndirectedGraph<
894
936
 
895
937
 
896
938
 
939
+
940
+
941
+
942
+
943
+
944
+
945
+
897
946
 
898
947
 
899
948
 
@@ -965,6 +1014,13 @@ export class UndirectedGraph<
965
1014
 
966
1015
 
967
1016
 
1017
+
1018
+
1019
+
1020
+
1021
+
1022
+
1023
+
968
1024
 
969
1025
 
970
1026
 
@@ -1016,6 +1072,13 @@ export class UndirectedGraph<
1016
1072
 
1017
1073
 
1018
1074
 
1075
+
1076
+
1077
+
1078
+
1079
+
1080
+
1081
+
1019
1082
 
1020
1083
 
1021
1084
 
@@ -196,6 +196,13 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
196
196
 
197
197
 
198
198
 
199
+
200
+
201
+
202
+
203
+
204
+
205
+
199
206
 
200
207
 
201
208
 
@@ -242,6 +249,13 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
242
249
 
243
250
 
244
251
 
252
+
253
+
254
+
255
+
256
+
257
+
258
+
245
259
 
246
260
 
247
261
 
@@ -332,6 +346,20 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
332
346
 
333
347
 
334
348
 
349
+
350
+
351
+
352
+
353
+
354
+
355
+
356
+
357
+
358
+
359
+
360
+
361
+
362
+
335
363
 
336
364
 
337
365
 
@@ -366,7 +394,7 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
366
394
  * // Verify entries
367
395
  * console.log([...map.entries()]); // length: 4;
368
396
  */
369
- set(key: K, value: V): boolean {
397
+ set(key: K, value: V): this {
370
398
  if (this._isObjKey(key)) {
371
399
  if (!this.objMap.has(key)) this._size++;
372
400
  this.objMap.set(key, value);
@@ -375,7 +403,7 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
375
403
  if (this.store[strKey] === undefined) this._size++;
376
404
  this._store[strKey] = { key, value };
377
405
  }
378
- return true;
406
+ return this;
379
407
  }
380
408
 
381
409
  /**
@@ -408,6 +436,13 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
408
436
 
409
437
 
410
438
 
439
+
440
+
441
+
442
+
443
+
444
+
445
+
411
446
 
412
447
 
413
448
 
@@ -428,7 +463,11 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
428
463
  let key: K | undefined, value: V | undefined;
429
464
  if (this.isEntry(rawEle)) [key, value] = rawEle;
430
465
  else if (this._toEntryFn) [key, value] = this._toEntryFn(rawEle);
431
- if (key !== undefined && value !== undefined) results.push(this.set(key, value));
466
+ if (key !== undefined && value !== undefined) {
467
+ const sizeBefore = this._size;
468
+ this.set(key, value);
469
+ results.push(sizeBefore < this._size);
470
+ }
432
471
  }
433
472
  return results;
434
473
  }
@@ -465,6 +504,13 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
465
504
 
466
505
 
467
506
 
507
+
508
+
509
+
510
+
511
+
512
+
513
+
468
514
 
469
515
 
470
516
 
@@ -533,6 +579,13 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
533
579
 
534
580
 
535
581
 
582
+
583
+
584
+
585
+
586
+
587
+
588
+
536
589
 
537
590
 
538
591
 
@@ -586,6 +639,13 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
586
639
 
587
640
 
588
641
 
642
+
643
+
644
+
645
+
646
+
647
+
648
+
589
649
 
590
650
 
591
651
 
@@ -658,6 +718,13 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
658
718
 
659
719
 
660
720
 
721
+
722
+
723
+
724
+
725
+
726
+
727
+
661
728
 
662
729
 
663
730
 
@@ -712,6 +779,13 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
712
779
 
713
780
 
714
781
 
782
+
783
+
784
+
785
+
786
+
787
+
788
+
715
789
 
716
790
 
717
791
 
@@ -768,6 +842,13 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
768
842
 
769
843
 
770
844
 
845
+
846
+
847
+
848
+
849
+
850
+
851
+
771
852
 
772
853
 
773
854
 
@@ -803,11 +884,11 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
803
884
  * console.log(values); // contains 7;
804
885
  */
805
886
 
806
- filter(predicate: EntryCallback<K, V, boolean>, thisArg?: unknown): any {
887
+ filter(predicate: EntryCallback<K, V, boolean>, thisArg?: unknown): this {
807
888
  const out = this._createLike<K, V, [K, V]>();
808
889
  let index = 0;
809
890
  for (const [key, value] of this) if (predicate.call(thisArg, value, key, index++, this)) out.set(key, value);
810
- return out;
891
+ return out as this;
811
892
  }
812
893
 
813
894
  /**
@@ -1015,9 +1096,9 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
1015
1096
  * @remarks Time O(1), Space O(1)
1016
1097
  * @param key - Key.
1017
1098
  * @param [value] - Value.
1018
- * @returns True when the operation succeeds.
1099
+ * @returns This map (for chaining).
1019
1100
  */
1020
- set(key: K, value?: V): boolean {
1101
+ set(key: K, value?: V): this {
1021
1102
  let node: HashMapLinkedNode<K, V | undefined> | undefined;
1022
1103
  const isNewKey = !this.has(key);
1023
1104
 
@@ -1053,7 +1134,7 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
1053
1134
  this._size++;
1054
1135
  }
1055
1136
 
1056
- return true;
1137
+ return this;
1057
1138
  }
1058
1139
 
1059
1140
  setMany(entryOrRawElements: Iterable<R | [K, V]>): boolean[] {
@@ -1062,7 +1143,11 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
1062
1143
  let key: K | undefined, value: V | undefined;
1063
1144
  if (this.isEntry(rawEle)) [key, value] = rawEle;
1064
1145
  else if (this._toEntryFn) [key, value] = this._toEntryFn(rawEle);
1065
- if (key !== undefined && value !== undefined) results.push(this.set(key, value));
1146
+ if (key !== undefined && value !== undefined) {
1147
+ const sizeBefore = this._size;
1148
+ this.set(key, value);
1149
+ results.push(sizeBefore < this._size);
1150
+ }
1066
1151
  }
1067
1152
  return results;
1068
1153
  }
@@ -1146,13 +1231,16 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
1146
1231
  * Delete the entry at a given index.
1147
1232
  * @remarks Time O(N), Space O(1)
1148
1233
  * @param index - Zero-based index.
1149
- * @returns True if removed.
1234
+ * @returns The removed entry [key, value].
1235
+ * @throws {RangeError} If index is out of bounds.
1150
1236
  */
1151
- deleteAt(index: number): boolean {
1237
+ deleteAt(index: number): [K, V | undefined] {
1152
1238
  rangeCheck(index, 0, this._size - 1);
1153
1239
  let node = this.head;
1154
1240
  while (index--) node = node.next;
1155
- return this._deleteNode(node);
1241
+ const entry: [K, V | undefined] = [node.key as K, node.value];
1242
+ this._deleteNode(node);
1243
+ return entry;
1156
1244
  }
1157
1245
 
1158
1246
  isEmpty(): boolean {