max-priority-queue-typed 2.5.2 → 2.5.3
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.
- package/dist/cjs/index.cjs +103 -16
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +103 -16
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +103 -16
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +103 -16
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +50 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +56 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +116 -15
- package/dist/types/data-structures/binary-tree/bst.d.ts +99 -3
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +79 -8
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +24 -0
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +520 -1
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +489 -1
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +393 -1
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +500 -1
- package/dist/types/data-structures/graph/directed-graph.d.ts +40 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +36 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +51 -6
- package/dist/types/data-structures/heap/heap.d.ts +98 -12
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +75 -0
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +61 -1
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +72 -0
- package/dist/types/data-structures/matrix/matrix.d.ts +32 -0
- package/dist/types/data-structures/queue/deque.d.ts +82 -0
- package/dist/types/data-structures/queue/queue.d.ts +61 -0
- package/dist/types/data-structures/stack/stack.d.ts +42 -2
- package/dist/types/data-structures/trie/trie.d.ts +48 -0
- package/dist/types/interfaces/binary-tree.d.ts +2 -3
- package/dist/umd/max-priority-queue-typed.js +103 -16
- package/dist/umd/max-priority-queue-typed.js.map +1 -1
- package/dist/umd/max-priority-queue-typed.min.js +1 -1
- package/dist/umd/max-priority-queue-typed.min.js.map +1 -1
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree.ts +52 -5
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +56 -0
- package/src/data-structures/binary-tree/binary-tree.ts +167 -81
- package/src/data-structures/binary-tree/bst.ts +101 -7
- package/src/data-structures/binary-tree/red-black-tree.ts +82 -15
- package/src/data-structures/binary-tree/segment-tree.ts +24 -0
- package/src/data-structures/binary-tree/tree-map.ts +540 -3
- package/src/data-structures/binary-tree/tree-multi-map.ts +490 -2
- package/src/data-structures/binary-tree/tree-multi-set.ts +393 -1
- package/src/data-structures/binary-tree/tree-set.ts +520 -3
- package/src/data-structures/graph/directed-graph.ts +41 -1
- package/src/data-structures/graph/undirected-graph.ts +37 -1
- package/src/data-structures/hash/hash-map.ts +67 -12
- package/src/data-structures/heap/heap.ts +107 -19
- package/src/data-structures/linked-list/doubly-linked-list.ts +88 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +61 -1
- package/src/data-structures/linked-list/skip-linked-list.ts +72 -0
- package/src/data-structures/matrix/matrix.ts +32 -0
- package/src/data-structures/queue/deque.ts +85 -0
- package/src/data-structures/queue/queue.ts +73 -0
- package/src/data-structures/stack/stack.ts +45 -5
- package/src/data-structures/trie/trie.ts +48 -0
- package/src/interfaces/binary-tree.ts +1 -9
|
@@ -375,6 +375,10 @@ var maxPriorityQueueTyped = (() => {
|
|
|
375
375
|
|
|
376
376
|
|
|
377
377
|
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
|
|
378
382
|
|
|
379
383
|
|
|
380
384
|
|
|
@@ -429,7 +433,7 @@ var maxPriorityQueueTyped = (() => {
|
|
|
429
433
|
}
|
|
430
434
|
/**
|
|
431
435
|
* Insert an element.
|
|
432
|
-
* @remarks Time O(
|
|
436
|
+
* @remarks Time O(log N) amortized, Space O(1)
|
|
433
437
|
* @param element - Element to insert.
|
|
434
438
|
* @returns True.
|
|
435
439
|
|
|
@@ -462,6 +466,10 @@ var maxPriorityQueueTyped = (() => {
|
|
|
462
466
|
|
|
463
467
|
|
|
464
468
|
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
|
|
465
473
|
|
|
466
474
|
|
|
467
475
|
|
|
@@ -519,6 +527,10 @@ var maxPriorityQueueTyped = (() => {
|
|
|
519
527
|
|
|
520
528
|
|
|
521
529
|
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
|
|
533
|
+
|
|
522
534
|
|
|
523
535
|
|
|
524
536
|
|
|
@@ -579,10 +591,41 @@ var maxPriorityQueueTyped = (() => {
|
|
|
579
591
|
|
|
580
592
|
|
|
581
593
|
|
|
594
|
+
|
|
595
|
+
|
|
596
|
+
|
|
582
597
|
|
|
583
598
|
|
|
584
599
|
|
|
585
600
|
|
|
601
|
+
* @example
|
|
602
|
+
* // Heap with custom comparator (MaxHeap behavior)
|
|
603
|
+
* interface Task {
|
|
604
|
+
* id: number;
|
|
605
|
+
* priority: number;
|
|
606
|
+
* name: string;
|
|
607
|
+
* }
|
|
608
|
+
*
|
|
609
|
+
* // Custom comparator for max heap behavior (higher priority first)
|
|
610
|
+
* const tasks: Task[] = [
|
|
611
|
+
* { id: 1, priority: 5, name: 'Email' },
|
|
612
|
+
* { id: 2, priority: 3, name: 'Chat' },
|
|
613
|
+
* { id: 3, priority: 8, name: 'Alert' }
|
|
614
|
+
* ];
|
|
615
|
+
*
|
|
616
|
+
* const maxHeap = new Heap(tasks, {
|
|
617
|
+
* comparator: (a: Task, b: Task) => b.priority - a.priority
|
|
618
|
+
* });
|
|
619
|
+
*
|
|
620
|
+
* console.log(maxHeap.size); // 3;
|
|
621
|
+
*
|
|
622
|
+
* // Peek returns highest priority task
|
|
623
|
+
* const topTask = maxHeap.peek();
|
|
624
|
+
* console.log(topTask?.priority); // 8;
|
|
625
|
+
* console.log(topTask?.name); // 'Alert';
|
|
626
|
+
*/
|
|
627
|
+
/**
|
|
628
|
+
* @deprecated Use `pop` instead. Will be removed in a future major version.
|
|
586
629
|
* @example
|
|
587
630
|
* // Heap with custom comparator (MaxHeap behavior)
|
|
588
631
|
* interface Task {
|
|
@@ -610,6 +653,14 @@ var maxPriorityQueueTyped = (() => {
|
|
|
610
653
|
* console.log(topTask?.name); // 'Alert';
|
|
611
654
|
*/
|
|
612
655
|
poll() {
|
|
656
|
+
return this.pop();
|
|
657
|
+
}
|
|
658
|
+
/**
|
|
659
|
+
* Remove and return the top element (min or max depending on comparator).
|
|
660
|
+
* @remarks Time O(log N) amortized, Space O(1)
|
|
661
|
+
* @returns The removed top element, or undefined if empty.
|
|
662
|
+
*/
|
|
663
|
+
pop() {
|
|
613
664
|
if (this.elements.length === 0) return;
|
|
614
665
|
const value = this.elements[0];
|
|
615
666
|
const last = this.elements.pop();
|
|
@@ -653,6 +704,10 @@ var maxPriorityQueueTyped = (() => {
|
|
|
653
704
|
|
|
654
705
|
|
|
655
706
|
|
|
707
|
+
|
|
708
|
+
|
|
709
|
+
|
|
710
|
+
|
|
656
711
|
|
|
657
712
|
|
|
658
713
|
|
|
@@ -753,6 +808,10 @@ var maxPriorityQueueTyped = (() => {
|
|
|
753
808
|
|
|
754
809
|
|
|
755
810
|
|
|
811
|
+
|
|
812
|
+
|
|
813
|
+
|
|
814
|
+
|
|
756
815
|
|
|
757
816
|
|
|
758
817
|
|
|
@@ -800,6 +859,10 @@ var maxPriorityQueueTyped = (() => {
|
|
|
800
859
|
|
|
801
860
|
|
|
802
861
|
|
|
862
|
+
|
|
863
|
+
|
|
864
|
+
|
|
865
|
+
|
|
803
866
|
|
|
804
867
|
|
|
805
868
|
|
|
@@ -814,16 +877,6 @@ var maxPriorityQueueTyped = (() => {
|
|
|
814
877
|
clear() {
|
|
815
878
|
this._elements = [];
|
|
816
879
|
}
|
|
817
|
-
/**
|
|
818
|
-
* Replace the backing array and rebuild the heap.
|
|
819
|
-
* @remarks Time O(N), Space O(N)
|
|
820
|
-
* @param elements - Iterable used to refill the heap.
|
|
821
|
-
* @returns Array of per-node results from fixing steps.
|
|
822
|
-
*/
|
|
823
|
-
refill(elements) {
|
|
824
|
-
this._elements = Array.from(elements);
|
|
825
|
-
return this.fix();
|
|
826
|
-
}
|
|
827
880
|
/**
|
|
828
881
|
* Check if an equal element exists in the heap.
|
|
829
882
|
* @remarks Time O(N), Space O(1)
|
|
@@ -850,6 +903,10 @@ var maxPriorityQueueTyped = (() => {
|
|
|
850
903
|
|
|
851
904
|
|
|
852
905
|
|
|
906
|
+
|
|
907
|
+
|
|
908
|
+
|
|
909
|
+
|
|
853
910
|
|
|
854
911
|
|
|
855
912
|
|
|
@@ -897,6 +954,10 @@ var maxPriorityQueueTyped = (() => {
|
|
|
897
954
|
|
|
898
955
|
|
|
899
956
|
|
|
957
|
+
|
|
958
|
+
|
|
959
|
+
|
|
960
|
+
|
|
900
961
|
|
|
901
962
|
|
|
902
963
|
|
|
@@ -918,7 +979,7 @@ var maxPriorityQueueTyped = (() => {
|
|
|
918
979
|
}
|
|
919
980
|
if (index < 0) return false;
|
|
920
981
|
if (index === 0) {
|
|
921
|
-
this.
|
|
982
|
+
this.pop();
|
|
922
983
|
} else if (index === this.elements.length - 1) {
|
|
923
984
|
this.elements.pop();
|
|
924
985
|
} else {
|
|
@@ -928,13 +989,19 @@ var maxPriorityQueueTyped = (() => {
|
|
|
928
989
|
}
|
|
929
990
|
return true;
|
|
930
991
|
}
|
|
992
|
+
/**
|
|
993
|
+
* @deprecated Use `deleteWhere` instead. Will be removed in a future major version.
|
|
994
|
+
*/
|
|
995
|
+
deleteBy(predicate) {
|
|
996
|
+
return this.deleteWhere(predicate);
|
|
997
|
+
}
|
|
931
998
|
/**
|
|
932
999
|
* Delete the first element that matches a predicate.
|
|
933
1000
|
* @remarks Time O(N), Space O(1)
|
|
934
1001
|
* @param predicate - Function (element, index, heap) → boolean.
|
|
935
1002
|
* @returns True if an element was removed.
|
|
936
1003
|
*/
|
|
937
|
-
|
|
1004
|
+
deleteWhere(predicate) {
|
|
938
1005
|
let idx = -1;
|
|
939
1006
|
for (let i = 0; i < this.elements.length; i++) {
|
|
940
1007
|
if (predicate(this.elements[i], i, this)) {
|
|
@@ -944,7 +1011,7 @@ var maxPriorityQueueTyped = (() => {
|
|
|
944
1011
|
}
|
|
945
1012
|
if (idx < 0) return false;
|
|
946
1013
|
if (idx === 0) {
|
|
947
|
-
this.
|
|
1014
|
+
this.pop();
|
|
948
1015
|
} else if (idx === this.elements.length - 1) {
|
|
949
1016
|
this.elements.pop();
|
|
950
1017
|
} else {
|
|
@@ -990,6 +1057,10 @@ var maxPriorityQueueTyped = (() => {
|
|
|
990
1057
|
|
|
991
1058
|
|
|
992
1059
|
|
|
1060
|
+
|
|
1061
|
+
|
|
1062
|
+
|
|
1063
|
+
|
|
993
1064
|
|
|
994
1065
|
|
|
995
1066
|
|
|
@@ -1070,6 +1141,10 @@ var maxPriorityQueueTyped = (() => {
|
|
|
1070
1141
|
|
|
1071
1142
|
|
|
1072
1143
|
|
|
1144
|
+
|
|
1145
|
+
|
|
1146
|
+
|
|
1147
|
+
|
|
1073
1148
|
|
|
1074
1149
|
|
|
1075
1150
|
|
|
@@ -1123,6 +1198,10 @@ var maxPriorityQueueTyped = (() => {
|
|
|
1123
1198
|
|
|
1124
1199
|
|
|
1125
1200
|
|
|
1201
|
+
|
|
1202
|
+
|
|
1203
|
+
|
|
1204
|
+
|
|
1126
1205
|
|
|
1127
1206
|
|
|
1128
1207
|
|
|
@@ -1175,6 +1254,10 @@ var maxPriorityQueueTyped = (() => {
|
|
|
1175
1254
|
|
|
1176
1255
|
|
|
1177
1256
|
|
|
1257
|
+
|
|
1258
|
+
|
|
1259
|
+
|
|
1260
|
+
|
|
1178
1261
|
|
|
1179
1262
|
|
|
1180
1263
|
|
|
@@ -1234,6 +1317,10 @@ var maxPriorityQueueTyped = (() => {
|
|
|
1234
1317
|
|
|
1235
1318
|
|
|
1236
1319
|
|
|
1320
|
+
|
|
1321
|
+
|
|
1322
|
+
|
|
1323
|
+
|
|
1237
1324
|
|
|
1238
1325
|
|
|
1239
1326
|
|
|
@@ -1412,7 +1499,7 @@ var maxPriorityQueueTyped = (() => {
|
|
|
1412
1499
|
* Push an element into the root list.
|
|
1413
1500
|
* @remarks Time O(1) amortized, Space O(1)
|
|
1414
1501
|
* @param element - Element to insert.
|
|
1415
|
-
* @returns
|
|
1502
|
+
* @returns True when the element is added.
|
|
1416
1503
|
*/
|
|
1417
1504
|
push(element) {
|
|
1418
1505
|
const node = this.createNode(element);
|
|
@@ -1421,7 +1508,7 @@ var maxPriorityQueueTyped = (() => {
|
|
|
1421
1508
|
this.mergeWithRoot(node);
|
|
1422
1509
|
if (!this.min || this.comparator(node.element, this.min.element) <= 0) this._min = node;
|
|
1423
1510
|
this._size++;
|
|
1424
|
-
return
|
|
1511
|
+
return true;
|
|
1425
1512
|
}
|
|
1426
1513
|
peek() {
|
|
1427
1514
|
return this.min ? this.min.element : void 0;
|