binary-tree-typed 2.5.0 → 2.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/dist/cjs/index.cjs +771 -68
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +771 -68
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +771 -69
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +771 -69
  8. package/dist/esm-legacy/index.mjs.map +1 -1
  9. package/dist/types/common/error.d.ts +9 -0
  10. package/dist/types/common/index.d.ts +1 -1
  11. package/dist/types/data-structures/base/index.d.ts +1 -0
  12. package/dist/types/data-structures/base/iterable-entry-base.d.ts +8 -8
  13. package/dist/types/data-structures/base/linear-base.d.ts +3 -3
  14. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +288 -0
  15. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +336 -0
  16. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +618 -18
  17. package/dist/types/data-structures/binary-tree/bst.d.ts +676 -1
  18. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +456 -0
  19. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +144 -1
  20. package/dist/types/data-structures/binary-tree/tree-map.d.ts +3307 -399
  21. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3285 -360
  22. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2674 -325
  23. package/dist/types/data-structures/binary-tree/tree-set.d.ts +3072 -287
  24. package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
  25. package/dist/types/data-structures/graph/directed-graph.d.ts +240 -0
  26. package/dist/types/data-structures/graph/undirected-graph.d.ts +216 -0
  27. package/dist/types/data-structures/hash/hash-map.d.ts +274 -10
  28. package/dist/types/data-structures/heap/heap.d.ts +336 -0
  29. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +411 -3
  30. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +363 -3
  31. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +434 -2
  32. package/dist/types/data-structures/matrix/matrix.d.ts +192 -0
  33. package/dist/types/data-structures/queue/deque.d.ts +364 -4
  34. package/dist/types/data-structures/queue/queue.d.ts +288 -0
  35. package/dist/types/data-structures/stack/stack.d.ts +240 -0
  36. package/dist/types/data-structures/trie/trie.d.ts +292 -4
  37. package/dist/types/interfaces/graph.d.ts +1 -1
  38. package/dist/types/types/common.d.ts +2 -2
  39. package/dist/types/types/data-structures/binary-tree/bst.d.ts +1 -0
  40. package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +5 -0
  41. package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +4 -0
  42. package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +4 -0
  43. package/dist/types/types/data-structures/heap/heap.d.ts +1 -0
  44. package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
  45. package/dist/types/types/utils/validate-type.d.ts +4 -4
  46. package/dist/umd/binary-tree-typed.js +773 -71
  47. package/dist/umd/binary-tree-typed.js.map +1 -1
  48. package/dist/umd/binary-tree-typed.min.js +5 -5
  49. package/dist/umd/binary-tree-typed.min.js.map +1 -1
  50. package/package.json +2 -2
  51. package/src/common/error.ts +19 -1
  52. package/src/common/index.ts +1 -1
  53. package/src/data-structures/base/index.ts +1 -0
  54. package/src/data-structures/base/iterable-element-base.ts +3 -2
  55. package/src/data-structures/base/iterable-entry-base.ts +8 -8
  56. package/src/data-structures/base/linear-base.ts +3 -3
  57. package/src/data-structures/binary-tree/avl-tree.ts +299 -0
  58. package/src/data-structures/binary-tree/binary-indexed-tree.ts +341 -5
  59. package/src/data-structures/binary-tree/binary-tree.ts +606 -6
  60. package/src/data-structures/binary-tree/bst.ts +946 -7
  61. package/src/data-structures/binary-tree/red-black-tree.ts +472 -0
  62. package/src/data-structures/binary-tree/segment-tree.ts +145 -2
  63. package/src/data-structures/binary-tree/tree-map.ts +3423 -499
  64. package/src/data-structures/binary-tree/tree-multi-map.ts +3537 -596
  65. package/src/data-structures/binary-tree/tree-multi-set.ts +2855 -495
  66. package/src/data-structures/binary-tree/tree-set.ts +3209 -413
  67. package/src/data-structures/graph/abstract-graph.ts +6 -6
  68. package/src/data-structures/graph/directed-graph.ts +240 -0
  69. package/src/data-structures/graph/undirected-graph.ts +216 -0
  70. package/src/data-structures/hash/hash-map.ts +281 -19
  71. package/src/data-structures/heap/heap.ts +340 -4
  72. package/src/data-structures/heap/max-heap.ts +2 -2
  73. package/src/data-structures/linked-list/doubly-linked-list.ts +411 -3
  74. package/src/data-structures/linked-list/singly-linked-list.ts +363 -3
  75. package/src/data-structures/linked-list/skip-linked-list.ts +439 -7
  76. package/src/data-structures/matrix/matrix.ts +202 -10
  77. package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
  78. package/src/data-structures/queue/deque.ts +365 -5
  79. package/src/data-structures/queue/queue.ts +288 -0
  80. package/src/data-structures/stack/stack.ts +240 -0
  81. package/src/data-structures/trie/trie.ts +295 -7
  82. package/src/interfaces/graph.ts +1 -1
  83. package/src/types/common.ts +2 -2
  84. package/src/types/data-structures/binary-tree/bst.ts +1 -0
  85. package/src/types/data-structures/binary-tree/tree-map.ts +6 -0
  86. package/src/types/data-structures/binary-tree/tree-multi-set.ts +5 -0
  87. package/src/types/data-structures/binary-tree/tree-set.ts +5 -0
  88. package/src/types/data-structures/heap/heap.ts +1 -0
  89. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
  90. package/src/types/utils/validate-type.ts +4 -4
@@ -260,6 +260,30 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
260
260
 
261
261
 
262
262
 
263
+
264
+
265
+
266
+
267
+
268
+
269
+
270
+
271
+
272
+
273
+
274
+
275
+
276
+
277
+
278
+
279
+
280
+
281
+
282
+
283
+
284
+
285
+
286
+
263
287
  * @example
264
288
  * // Deque peek at both ends
265
289
  * const deque = new Deque<number>([10, 20, 30, 40, 50]);
@@ -296,6 +320,30 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
296
320
 
297
321
 
298
322
 
323
+
324
+
325
+
326
+
327
+
328
+
329
+
330
+
331
+
332
+
333
+
334
+
335
+
336
+
337
+
338
+
339
+
340
+
341
+
342
+
343
+
344
+
345
+
346
+
299
347
  * @example
300
348
  * // Peek at the back element
301
349
  * const dq = new Deque<string>(['a', 'b', 'c']);
@@ -346,6 +394,30 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
346
394
 
347
395
 
348
396
 
397
+
398
+
399
+
400
+
401
+
402
+
403
+
404
+
405
+
406
+
407
+
408
+
409
+
410
+
411
+
412
+
413
+
414
+
415
+
416
+
417
+
418
+
419
+
420
+
349
421
  * @example
350
422
  * // basic Deque creation and push/pop operations
351
423
  * // Create a simple Deque with initial values
@@ -400,6 +472,30 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
400
472
 
401
473
 
402
474
 
475
+
476
+
477
+
478
+
479
+
480
+
481
+
482
+
483
+
484
+
485
+
486
+
487
+
488
+
489
+
490
+
491
+
492
+
493
+
494
+
495
+
496
+
497
+
498
+
403
499
  * @example
404
500
  * // Remove from the back
405
501
  * const dq = new Deque<number>([1, 2, 3]);
@@ -441,6 +537,30 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
441
537
 
442
538
 
443
539
 
540
+
541
+
542
+
543
+
544
+
545
+
546
+
547
+
548
+
549
+
550
+
551
+
552
+
553
+
554
+
555
+
556
+
557
+
558
+
559
+
560
+
561
+
562
+
563
+
444
564
  * @example
445
565
  * // Remove from the front
446
566
  * const dq = new Deque<number>([1, 2, 3]);
@@ -483,6 +603,30 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
483
603
 
484
604
 
485
605
 
606
+
607
+
608
+
609
+
610
+
611
+
612
+
613
+
614
+
615
+
616
+
617
+
618
+
619
+
620
+
621
+
622
+
623
+
624
+
625
+
626
+
627
+
628
+
629
+
486
630
  * @example
487
631
  * // Deque shift and unshift operations
488
632
  * const deque = new Deque<number>([20, 30, 40]);
@@ -570,6 +714,30 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
570
714
 
571
715
 
572
716
 
717
+
718
+
719
+
720
+
721
+
722
+
723
+
724
+
725
+
726
+
727
+
728
+
729
+
730
+
731
+
732
+
733
+
734
+
735
+
736
+
737
+
738
+
739
+
740
+
573
741
  * @example
574
742
  * // Check if empty
575
743
  * const dq = new Deque();
@@ -593,6 +761,30 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
593
761
 
594
762
 
595
763
 
764
+
765
+
766
+
767
+
768
+
769
+
770
+
771
+
772
+
773
+
774
+
775
+
776
+
777
+
778
+
779
+
780
+
781
+
782
+
783
+
784
+
785
+
786
+
787
+
596
788
  * @example
597
789
  * // Remove all elements
598
790
  * const dq = new Deque<number>([1, 2, 3]);
@@ -620,6 +812,30 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
620
812
 
621
813
 
622
814
 
815
+
816
+
817
+
818
+
819
+
820
+
821
+
822
+
823
+
824
+
825
+
826
+
827
+
828
+
829
+
830
+
831
+
832
+
833
+
834
+
835
+
836
+
837
+
838
+
623
839
  * @example
624
840
  * // Access by index
625
841
  * const dq = new Deque<string>(['a', 'b', 'c']);
@@ -820,6 +1036,30 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
820
1036
 
821
1037
 
822
1038
 
1039
+
1040
+
1041
+
1042
+
1043
+
1044
+
1045
+
1046
+
1047
+
1048
+
1049
+
1050
+
1051
+
1052
+
1053
+
1054
+
1055
+
1056
+
1057
+
1058
+
1059
+
1060
+
1061
+
1062
+
823
1063
  * @example
824
1064
  * // Remove element
825
1065
  * const dq = new Deque<number>([1, 2, 3]);
@@ -889,6 +1129,30 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
889
1129
 
890
1130
 
891
1131
 
1132
+
1133
+
1134
+
1135
+
1136
+
1137
+
1138
+
1139
+
1140
+
1141
+
1142
+
1143
+
1144
+
1145
+
1146
+
1147
+
1148
+
1149
+
1150
+
1151
+
1152
+
1153
+
1154
+
1155
+
892
1156
  * @example
893
1157
  * // Deque for...of iteration and reverse
894
1158
  * const deque = new Deque<string>(['A', 'B', 'C', 'D']);
@@ -985,6 +1249,30 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
985
1249
 
986
1250
 
987
1251
 
1252
+
1253
+
1254
+
1255
+
1256
+
1257
+
1258
+
1259
+
1260
+
1261
+
1262
+
1263
+
1264
+
1265
+
1266
+
1267
+
1268
+
1269
+
1270
+
1271
+
1272
+
1273
+
1274
+
1275
+
988
1276
  * @example
989
1277
  * // Reclaim memory
990
1278
  * const dq = new Deque<number>([1, 2, 3, 4, 5]);
@@ -1034,6 +1322,30 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
1034
1322
 
1035
1323
 
1036
1324
 
1325
+
1326
+
1327
+
1328
+
1329
+
1330
+
1331
+
1332
+
1333
+
1334
+
1335
+
1336
+
1337
+
1338
+
1339
+
1340
+
1341
+
1342
+
1343
+
1344
+
1345
+
1346
+
1347
+
1348
+
1037
1349
  * @example
1038
1350
  * // Create independent copy
1039
1351
  * const dq = new Deque<number>([1, 2, 3]);
@@ -1066,6 +1378,30 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
1066
1378
 
1067
1379
 
1068
1380
 
1381
+
1382
+
1383
+
1384
+
1385
+
1386
+
1387
+
1388
+
1389
+
1390
+
1391
+
1392
+
1393
+
1394
+
1395
+
1396
+
1397
+
1398
+
1399
+
1400
+
1401
+
1402
+
1403
+
1404
+
1069
1405
  * @example
1070
1406
  * // Filter elements
1071
1407
  * const dq = new Deque<number>([1, 2, 3, 4]);
@@ -1073,7 +1409,7 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
1073
1409
  * console.log(result.length); // 2;
1074
1410
  */
1075
1411
 
1076
- filter(predicate: ElementCallback<E, R, boolean>, thisArg?: any): this {
1412
+ filter(predicate: ElementCallback<E, R, boolean>, thisArg?: unknown): this {
1077
1413
  const out = this._createInstance({ toElementFn: this.toElementFn, maxLen: this._maxLen });
1078
1414
  out._setBucketSize(this._bucketSize);
1079
1415
  let index = 0;
@@ -1092,7 +1428,7 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
1092
1428
  * @returns A new deque with mapped values.
1093
1429
  */
1094
1430
 
1095
- mapSame(callback: ElementCallback<E, R, E>, thisArg?: any): this {
1431
+ mapSame(callback: ElementCallback<E, R, E>, thisArg?: unknown): this {
1096
1432
  const out = this._createInstance({ toElementFn: this._toElementFn, maxLen: this._maxLen });
1097
1433
  out._setBucketSize(this._bucketSize);
1098
1434
  let index = 0;
@@ -1120,6 +1456,30 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
1120
1456
 
1121
1457
 
1122
1458
 
1459
+
1460
+
1461
+
1462
+
1463
+
1464
+
1465
+
1466
+
1467
+
1468
+
1469
+
1470
+
1471
+
1472
+
1473
+
1474
+
1475
+
1476
+
1477
+
1478
+
1479
+
1480
+
1481
+
1482
+
1123
1483
  * @example
1124
1484
  * // Transform elements
1125
1485
  * const dq = new Deque<number>([1, 2, 3]);
@@ -1130,7 +1490,7 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
1130
1490
  map<EM, RM>(
1131
1491
  callback: ElementCallback<E, R, EM>,
1132
1492
  options?: IterableElementBaseOptions<EM, RM>,
1133
- thisArg?: any
1493
+ thisArg?: unknown
1134
1494
  ): Deque<EM, RM> {
1135
1495
  const out = this._createLike<EM, RM>([], {
1136
1496
  ...(options ?? {}),
@@ -1263,11 +1623,11 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
1263
1623
  protected _createLike<T = E, RR = R>(
1264
1624
  elements: IterableWithSizeOrLength<T> | IterableWithSizeOrLength<RR> = [],
1265
1625
  options?: DequeOptions<T, RR>
1266
- ): any {
1626
+ ): Deque<T, RR> {
1267
1627
  const Ctor = this.constructor as new (
1268
1628
  elements?: IterableWithSizeOrLength<T> | IterableWithSizeOrLength<RR>,
1269
1629
  options?: DequeOptions<T, RR>
1270
- ) => any;
1630
+ ) => Deque<T, RR>;
1271
1631
  return new Ctor(elements, options);
1272
1632
  }
1273
1633