max-priority-queue-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 +174 -16
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +174 -16
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +174 -16
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +174 -16
  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/max-priority-queue-typed.js +174 -16
  35. package/dist/umd/max-priority-queue-typed.js.map +1 -1
  36. package/dist/umd/max-priority-queue-typed.min.js +1 -1
  37. package/dist/umd/max-priority-queue-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
@@ -76,6 +76,20 @@ export declare class BinaryIndexedTree implements Iterable<number> {
76
76
 
77
77
 
78
78
 
79
+
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
79
93
 
80
94
 
81
95
 
@@ -149,6 +163,20 @@ export declare class BinaryIndexedTree implements Iterable<number> {
149
163
 
150
164
 
151
165
 
166
+
167
+
168
+
169
+
170
+
171
+
172
+
173
+
174
+
175
+
176
+
177
+
178
+
179
+
152
180
 
153
181
 
154
182
 
@@ -221,6 +249,20 @@ export declare class BinaryIndexedTree implements Iterable<number> {
221
249
 
222
250
 
223
251
 
252
+
253
+
254
+
255
+
256
+
257
+
258
+
259
+
260
+
261
+
262
+
263
+
264
+
265
+
224
266
 
225
267
 
226
268
 
@@ -294,6 +336,20 @@ export declare class BinaryIndexedTree implements Iterable<number> {
294
336
 
295
337
 
296
338
 
339
+
340
+
341
+
342
+
343
+
344
+
345
+
346
+
347
+
348
+
349
+
350
+
351
+
352
+
297
353
 
298
354
 
299
355
 
@@ -365,6 +421,20 @@ export declare class BinaryIndexedTree implements Iterable<number> {
365
421
 
366
422
 
367
423
 
424
+
425
+
426
+
427
+
428
+
429
+
430
+
431
+
432
+
433
+
434
+
435
+
436
+
437
+
368
438
 
369
439
 
370
440
 
@@ -439,6 +509,20 @@ export declare class BinaryIndexedTree implements Iterable<number> {
439
509
 
440
510
 
441
511
 
512
+
513
+
514
+
515
+
516
+
517
+
518
+
519
+
520
+
521
+
522
+
523
+
524
+
525
+
442
526
 
443
527
 
444
528
 
@@ -484,6 +568,13 @@ export declare class BinaryIndexedTree implements Iterable<number> {
484
568
 
485
569
 
486
570
 
571
+
572
+
573
+
574
+
575
+
576
+
577
+
487
578
 
488
579
 
489
580
 
@@ -524,6 +615,13 @@ export declare class BinaryIndexedTree implements Iterable<number> {
524
615
 
525
616
 
526
617
 
618
+
619
+
620
+
621
+
622
+
623
+
624
+
527
625
 
528
626
 
529
627
 
@@ -136,7 +136,7 @@ export declare class BinaryTreeNode<K = any, V = any> {
136
136
  * node?: BinaryTreeNode<string> | null,
137
137
  * conditions?: { [key: string]: boolean }
138
138
  * ): string {
139
- * if (!node) raise(Error, 'Invalid node');
139
+ * if (!node) throw new Error('Invalid node');
140
140
  *
141
141
  * // If it's a leaf node, return the decision result
142
142
  * if (!node.left && !node.right) return node.key;
@@ -181,7 +181,7 @@ export declare class BinaryTreeNode<K = any, V = any> {
181
181
  * case '/':
182
182
  * return rightValue !== 0 ? leftValue / rightValue : 0; // Handle division by zero
183
183
  * default:
184
- * raise(Error, `Unsupported operator: ${node.key}`);
184
+ * throw new Error(`Unsupported operator: ${node.key}`);
185
185
  * }
186
186
  * }
187
187
  *
@@ -353,7 +353,7 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
353
353
  isValidKey(key: unknown): key is K;
354
354
  /**
355
355
  * Adds a new node to the tree.
356
- * @remarks Time O(log N), For BST, Red-Black Tree, and AVL Tree subclasses, the worst-case time is O(log N). This implementation adds the node at the first available position in a level-order (BFS) traversal. This is NOT a Binary Search Tree insertion. Time O(N), where N is the number of nodes. It must traverse level-by-level to find an empty slot. Space O(N) in the worst case for the BFS queue (e.g., a full last level).
356
+ * @remarks Time O(N) level-order traversal to find an empty slot. Space O(N) for the BFS queue. BST/Red-Black Tree/AVL Tree subclasses override to O(log N).
357
357
  *
358
358
  * @param keyNodeOrEntry - The key, node, or entry to add.
359
359
  * @returns True if the addition was successful, false otherwise.
@@ -379,6 +379,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
379
379
 
380
380
 
381
381
 
382
+
383
+
384
+
385
+
386
+
387
+
388
+
382
389
 
383
390
 
384
391
 
@@ -399,7 +406,7 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
399
406
  add(keyNodeOrEntry: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): boolean;
400
407
  /**
401
408
  * Adds or updates a new node to the tree.
402
- * @remarks Time O(log N), For BST, Red-Black Tree, and AVL Tree subclasses, the worst-case time is O(log N). This implementation sets the node at the first available position in a level-order (BFS) traversal. This is NOT a Binary Search Tree insertion. Time O(N), where N is the number of nodes. It must traverse level-by-level to find an empty slot. Space O(N) in the worst case for the BFS queue (e.g., a full last level).
409
+ * @remarks Time O(N) level-order traversal to find an empty slot. Space O(N) for the BFS queue. BST/Red-Black Tree/AVL Tree subclasses override to O(log N).
403
410
  *
404
411
  * @param keyNodeOrEntry - The key, node, or entry to set or update.
405
412
  * @param [value] - The value, if providing just a key.
@@ -431,6 +438,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
431
438
 
432
439
 
433
440
 
441
+
442
+
443
+
444
+
445
+
446
+
447
+
434
448
 
435
449
 
436
450
 
@@ -495,6 +509,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
495
509
 
496
510
 
497
511
 
512
+
513
+
514
+
515
+
516
+
517
+
518
+
498
519
 
499
520
 
500
521
 
@@ -535,6 +556,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
535
556
 
536
557
 
537
558
 
559
+
560
+
561
+
562
+
563
+
564
+
565
+
538
566
 
539
567
 
540
568
 
@@ -580,6 +608,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
580
608
 
581
609
 
582
610
 
611
+
612
+
613
+
614
+
615
+
616
+
617
+
583
618
 
584
619
 
585
620
 
@@ -597,19 +632,27 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
597
632
  */
598
633
  merge(anotherTree: BinaryTree<K, V, R>): void;
599
634
  /**
600
- * Clears the tree and refills it with new items.
601
- * @remarks Time O(N) (for `clear`) + O(N * M) (for `setMany`) = O(N * M). Space O(M) (from `setMany`).
635
+ * Deletes a node from the tree (internal, returns balancing metadata).
636
+ * @remarks Time O(N) O(N) to find the node + O(H) for predecessor swap. Space O(1). BST/Red-Black Tree/AVL Tree subclasses override to O(log N).
637
+ * @internal Used by AVL/BST subclasses that need balancing metadata after deletion.
602
638
  *
603
- * @param keysNodesEntriesOrRaws - An iterable of items to set.
604
- * @param [values] - An optional parallel iterable of values.
639
+ * @param keyNodeEntryRawOrPredicate - The node to delete.
640
+ * @returns An array containing deletion results with balancing metadata.
605
641
  */
606
- refill(keysNodesEntriesOrRaws: Iterable<K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>, values?: Iterable<V | undefined>): void;
642
+ protected _deleteInternal(keyNodeEntryRawOrPredicate: BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V> | null>): BinaryTreeDeleteResult<BinaryTreeNode<K, V>>[];
607
643
  /**
608
644
  * Deletes a node from the tree.
609
- * @remarks Time O(log N), For BST, Red-Black Tree, and AVL Tree subclasses, the worst-case time is O(log N). This implementation finds the node, and if it has two children, swaps it with the rightmost node of its left subtree (in-order predecessor) before deleting. Time O(N) in the worst case. O(N) to find the node (`getNode`) and O(H) (which is O(N) worst-case) to find the rightmost node. Space O(1) (if `getNode` is iterative, which it is).
645
+ * @remarks Time O(N) O(N) to find the node + O(H) for predecessor swap. Space O(1). BST/Red-Black Tree/AVL Tree subclasses override to O(log N).
610
646
  *
611
647
  * @param keyNodeEntryRawOrPredicate - The node to delete.
612
- * @returns An array containing deletion results (for compatibility with self-balancing trees).
648
+ * @returns True if the node was found and deleted, false otherwise.
649
+
650
+
651
+
652
+
653
+
654
+
655
+
613
656
 
614
657
 
615
658
 
@@ -652,7 +695,7 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
652
695
  * console.log(tree.has(3)); // false;
653
696
  * console.log(tree.size); // 4;
654
697
  */
655
- delete(keyNodeEntryRawOrPredicate: BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V> | null>): BinaryTreeDeleteResult<BinaryTreeNode<K, V>>[];
698
+ delete(keyNodeEntryRawOrPredicate: BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V> | null>): boolean;
656
699
  /**
657
700
  * Search by predicate
658
701
 
@@ -673,6 +716,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
673
716
 
674
717
 
675
718
 
719
+
720
+
721
+
722
+
723
+
724
+
725
+
676
726
 
677
727
 
678
728
 
@@ -722,6 +772,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
722
772
 
723
773
 
724
774
 
775
+
776
+
777
+
778
+
779
+
780
+
781
+
725
782
 
726
783
 
727
784
 
@@ -739,7 +796,7 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
739
796
  getNodes(keyNodeEntryOrPredicate: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BinaryTreeNode<K, V>>, onlyOne?: boolean, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): BinaryTreeNode<K, V>[];
740
797
  /**
741
798
  * Gets the first node matching a predicate.
742
- * @remarks Time O(log N), For BST, Red-Black Tree, and AVL Tree subclasses, the worst-case time is O(log N). Time O(N) in the worst case (via `search`). Space O(H) or O(N) (via `search`).
799
+ * @remarks Time O(N) via `search`. Space O(H) or O(N). BST/Red-Black Tree/AVL Tree subclasses override to O(log N) for key lookups.
743
800
  *
744
801
  * @param keyNodeEntryOrPredicate - The key, node, entry, or predicate function to search for.
745
802
  * @param [startNode=this._root] - The node to start the search from.
@@ -770,6 +827,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
770
827
 
771
828
 
772
829
 
830
+
831
+
832
+
833
+
834
+
835
+
836
+
773
837
 
774
838
 
775
839
 
@@ -786,7 +850,7 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
786
850
  getNode(keyNodeEntryOrPredicate: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BinaryTreeNode<K, V> | null>, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): BinaryTreeNode<K, V> | null | undefined;
787
851
  /**
788
852
  * Gets the value associated with a key.
789
- * @remarks Time O(log N), For BST, Red-Black Tree, and AVL Tree subclasses, the worst-case time is O(log N). Time O(1) if in Map mode. O(N) if not in Map mode (uses `getNode`). Space O(1) if in Map mode. O(H) or O(N) otherwise.
853
+ * @remarks Time O(1) in Map mode, O(N) otherwise (via `getNode`). Space O(1) in Map mode, O(H) or O(N) otherwise. BST subclasses override non-Map-mode to O(log N).
790
854
  *
791
855
  * @param keyNodeEntryOrPredicate - The key, node, or entry to get the value for.
792
856
  * @param [startNode=this._root] - The node to start searching from (if not in Map mode).
@@ -819,6 +883,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
819
883
 
820
884
 
821
885
 
886
+
887
+
888
+
889
+
890
+
891
+
892
+
822
893
 
823
894
 
824
895
 
@@ -836,7 +907,7 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
836
907
  get(keyNodeEntryOrPredicate: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): V | undefined;
837
908
  /**
838
909
  * Checks if a node matching the predicate exists in the tree.
839
- * @remarks Time O(log N), For BST, Red-Black Tree, and AVL Tree subclasses, the worst-case time is O(log N). Time O(N) in the worst case (via `search`). Space O(H) or O(N) (via `search`).
910
+ * @remarks Time O(N) via `search`. Space O(H) or O(N). BST/Red-Black Tree/AVL Tree subclasses override to O(log N) for key lookups.
840
911
  *
841
912
  * @param [keyNodeEntryOrPredicate] - The key, node, entry, or predicate to check for.
842
913
  * @param [startNode] - The node to start the search from.
@@ -869,6 +940,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
869
940
 
870
941
 
871
942
 
943
+
944
+
945
+
946
+
947
+
948
+
949
+
872
950
 
873
951
 
874
952
 
@@ -935,6 +1013,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
935
1013
 
936
1014
 
937
1015
 
1016
+
1017
+
1018
+
1019
+
1020
+
1021
+
1022
+
938
1023
 
939
1024
 
940
1025
 
@@ -980,6 +1065,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
980
1065
 
981
1066
 
982
1067
 
1068
+
1069
+
1070
+
1071
+
1072
+
1073
+
1074
+
983
1075
 
984
1076
 
985
1077
 
@@ -1033,6 +1125,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
1033
1125
 
1034
1126
 
1035
1127
 
1128
+
1129
+
1130
+
1131
+
1132
+
1133
+
1134
+
1036
1135
 
1037
1136
 
1038
1137
 
@@ -1082,6 +1181,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
1082
1181
 
1083
1182
 
1084
1183
 
1184
+
1185
+
1186
+
1187
+
1188
+
1189
+
1190
+
1085
1191
 
1086
1192
 
1087
1193
 
@@ -1131,6 +1237,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
1131
1237
 
1132
1238
 
1133
1239
 
1240
+
1241
+
1242
+
1243
+
1244
+
1245
+
1246
+
1134
1247
 
1135
1248
 
1136
1249
 
@@ -1205,6 +1318,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
1205
1318
 
1206
1319
 
1207
1320
 
1321
+
1322
+
1323
+
1324
+
1325
+
1326
+
1327
+
1208
1328
 
1209
1329
 
1210
1330
 
@@ -1251,6 +1371,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
1251
1371
 
1252
1372
 
1253
1373
 
1374
+
1375
+
1376
+
1377
+
1378
+
1379
+
1380
+
1254
1381
 
1255
1382
 
1256
1383
 
@@ -1317,6 +1444,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
1317
1444
 
1318
1445
 
1319
1446
 
1447
+
1448
+
1449
+
1450
+
1451
+
1452
+
1453
+
1320
1454
 
1321
1455
 
1322
1456
 
@@ -1359,6 +1493,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
1359
1493
 
1360
1494
 
1361
1495
 
1496
+
1497
+
1498
+
1499
+
1500
+
1501
+
1502
+
1362
1503
 
1363
1504
 
1364
1505
 
@@ -1403,6 +1544,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
1403
1544
 
1404
1545
 
1405
1546
 
1547
+
1548
+
1549
+
1550
+
1551
+
1552
+
1553
+
1406
1554
 
1407
1555
 
1408
1556
 
@@ -1449,6 +1597,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
1449
1597
 
1450
1598
 
1451
1599
 
1600
+
1601
+
1602
+
1603
+
1604
+
1605
+
1606
+
1452
1607
 
1453
1608
 
1454
1609
 
@@ -1497,6 +1652,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
1497
1652
 
1498
1653
 
1499
1654
 
1655
+
1656
+
1657
+
1658
+
1659
+
1660
+
1661
+
1500
1662
 
1501
1663
 
1502
1664
 
@@ -1548,6 +1710,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
1548
1710
 
1549
1711
 
1550
1712
 
1713
+
1714
+
1715
+
1716
+
1717
+
1718
+
1719
+
1551
1720
 
1552
1721
 
1553
1722
 
@@ -1603,6 +1772,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
1603
1772
 
1604
1773
 
1605
1774
 
1775
+
1776
+
1777
+
1778
+
1779
+
1780
+
1781
+
1606
1782
 
1607
1783
 
1608
1784