max-priority-queue-typed 2.5.1 → 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.
- package/dist/cjs/index.cjs +104 -55
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +103 -54
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +104 -56
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +103 -55
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/types/common/error.d.ts +9 -0
- package/dist/types/common/index.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +36 -0
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +42 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +77 -2
- package/dist/types/data-structures/binary-tree/bst.d.ts +171 -0
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +57 -0
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +18 -0
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +409 -0
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +411 -6
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +339 -6
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +391 -0
- package/dist/types/data-structures/graph/directed-graph.d.ts +30 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +27 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +33 -0
- package/dist/types/data-structures/heap/heap.d.ts +42 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +51 -0
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +45 -0
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +54 -0
- package/dist/types/data-structures/matrix/matrix.d.ts +24 -0
- package/dist/types/data-structures/queue/deque.d.ts +45 -0
- package/dist/types/data-structures/queue/queue.d.ts +36 -0
- package/dist/types/data-structures/stack/stack.d.ts +30 -0
- package/dist/types/data-structures/trie/trie.d.ts +36 -0
- package/dist/types/types/data-structures/binary-tree/bst.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +5 -0
- package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +4 -0
- package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +4 -0
- package/dist/umd/max-priority-queue-typed.js +101 -53
- 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/common/error.ts +19 -1
- package/src/common/index.ts +1 -1
- package/src/data-structures/base/iterable-element-base.ts +3 -2
- package/src/data-structures/binary-tree/avl-tree.ts +47 -0
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +46 -4
- package/src/data-structures/binary-tree/binary-tree.ts +79 -4
- package/src/data-structures/binary-tree/bst.ts +441 -6
- package/src/data-structures/binary-tree/red-black-tree.ts +73 -0
- package/src/data-structures/binary-tree/segment-tree.ts +18 -0
- package/src/data-structures/binary-tree/tree-map.ts +434 -9
- package/src/data-structures/binary-tree/tree-multi-map.ts +426 -5
- package/src/data-structures/binary-tree/tree-multi-set.ts +350 -6
- package/src/data-structures/binary-tree/tree-set.ts +410 -8
- package/src/data-structures/graph/abstract-graph.ts +2 -2
- package/src/data-structures/graph/directed-graph.ts +30 -0
- package/src/data-structures/graph/undirected-graph.ts +27 -0
- package/src/data-structures/hash/hash-map.ts +35 -4
- package/src/data-structures/heap/heap.ts +46 -4
- package/src/data-structures/heap/max-heap.ts +2 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +51 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +45 -0
- package/src/data-structures/linked-list/skip-linked-list.ts +59 -5
- package/src/data-structures/matrix/matrix.ts +33 -9
- package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
- package/src/data-structures/queue/deque.ts +45 -0
- package/src/data-structures/queue/queue.ts +36 -0
- package/src/data-structures/stack/stack.ts +30 -0
- package/src/data-structures/trie/trie.ts +38 -2
- package/src/types/data-structures/binary-tree/bst.ts +1 -0
- package/src/types/data-structures/binary-tree/tree-map.ts +6 -0
- package/src/types/data-structures/binary-tree/tree-multi-set.ts +5 -0
- package/src/types/data-structures/binary-tree/tree-set.ts +5 -0
|
@@ -446,6 +446,18 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
|
|
|
446
446
|
|
|
447
447
|
|
|
448
448
|
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
|
|
449
461
|
|
|
450
462
|
|
|
451
463
|
|
|
@@ -554,6 +566,7 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
|
|
|
554
566
|
node.left = NIL;
|
|
555
567
|
node.right = NIL;
|
|
556
568
|
node.color = 'RED';
|
|
569
|
+
this._updateCountAlongPath(node);
|
|
557
570
|
this._insertFixup(node);
|
|
558
571
|
if (this.isRealNode(this._root)) this._root.color = 'BLACK';
|
|
559
572
|
}
|
|
@@ -684,6 +697,7 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
|
|
|
684
697
|
newNode.right = NIL;
|
|
685
698
|
newNode.color = 'RED';
|
|
686
699
|
|
|
700
|
+
this._updateCountAlongPath(newNode);
|
|
687
701
|
this._insertFixup(newNode);
|
|
688
702
|
if (this.isRealNode(this._root)) this._root.color = 'BLACK';
|
|
689
703
|
else return undefined;
|
|
@@ -964,6 +978,18 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
|
|
|
964
978
|
|
|
965
979
|
|
|
966
980
|
|
|
981
|
+
|
|
982
|
+
|
|
983
|
+
|
|
984
|
+
|
|
985
|
+
|
|
986
|
+
|
|
987
|
+
|
|
988
|
+
|
|
989
|
+
|
|
990
|
+
|
|
991
|
+
|
|
992
|
+
|
|
967
993
|
|
|
968
994
|
|
|
969
995
|
|
|
@@ -1164,6 +1190,18 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
|
|
|
1164
1190
|
|
|
1165
1191
|
|
|
1166
1192
|
|
|
1193
|
+
|
|
1194
|
+
|
|
1195
|
+
|
|
1196
|
+
|
|
1197
|
+
|
|
1198
|
+
|
|
1199
|
+
|
|
1200
|
+
|
|
1201
|
+
|
|
1202
|
+
|
|
1203
|
+
|
|
1204
|
+
|
|
1167
1205
|
|
|
1168
1206
|
|
|
1169
1207
|
|
|
@@ -1245,6 +1283,9 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
|
|
|
1245
1283
|
if (this._isMapMode) this._store.delete(nodeToDelete.key);
|
|
1246
1284
|
this._size--;
|
|
1247
1285
|
|
|
1286
|
+
// Update order-statistic counts from replacement up to root
|
|
1287
|
+
this._updateCountAlongPath(replacementNode?.parent as RedBlackTreeNode<K, V> | undefined ?? replacementNode);
|
|
1288
|
+
|
|
1248
1289
|
// Update min/max caches.
|
|
1249
1290
|
if (this._size <= 0) {
|
|
1250
1291
|
this._setMinCache(undefined);
|
|
@@ -1363,6 +1404,15 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
|
|
|
1363
1404
|
|
|
1364
1405
|
|
|
1365
1406
|
|
|
1407
|
+
|
|
1408
|
+
|
|
1409
|
+
|
|
1410
|
+
|
|
1411
|
+
|
|
1412
|
+
|
|
1413
|
+
|
|
1414
|
+
|
|
1415
|
+
|
|
1366
1416
|
|
|
1367
1417
|
|
|
1368
1418
|
|
|
@@ -1501,6 +1551,18 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
|
|
|
1501
1551
|
|
|
1502
1552
|
|
|
1503
1553
|
|
|
1554
|
+
|
|
1555
|
+
|
|
1556
|
+
|
|
1557
|
+
|
|
1558
|
+
|
|
1559
|
+
|
|
1560
|
+
|
|
1561
|
+
|
|
1562
|
+
|
|
1563
|
+
|
|
1564
|
+
|
|
1565
|
+
|
|
1504
1566
|
|
|
1505
1567
|
|
|
1506
1568
|
|
|
@@ -1632,6 +1694,9 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
|
|
|
1632
1694
|
node.right = NIL;
|
|
1633
1695
|
node.color = 'RED';
|
|
1634
1696
|
|
|
1697
|
+
// Update counts along insertion path before fixup
|
|
1698
|
+
this._updateCountAlongPath(node);
|
|
1699
|
+
|
|
1635
1700
|
this._insertFixup(node);
|
|
1636
1701
|
return 'CREATED';
|
|
1637
1702
|
}
|
|
@@ -1835,6 +1900,10 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
|
|
|
1835
1900
|
|
|
1836
1901
|
y.left = x;
|
|
1837
1902
|
x.parent = y;
|
|
1903
|
+
|
|
1904
|
+
// Update counts: x first (now child), then y (now parent)
|
|
1905
|
+
this._updateCount(x);
|
|
1906
|
+
this._updateCount(y);
|
|
1838
1907
|
}
|
|
1839
1908
|
|
|
1840
1909
|
/**
|
|
@@ -1867,5 +1936,9 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
|
|
|
1867
1936
|
|
|
1868
1937
|
x.right = y;
|
|
1869
1938
|
y.parent = x;
|
|
1939
|
+
|
|
1940
|
+
// Update counts: y first (now child), then x (now parent)
|
|
1941
|
+
this._updateCount(y);
|
|
1942
|
+
this._updateCount(x);
|
|
1870
1943
|
}
|
|
1871
1944
|
}
|
|
@@ -106,6 +106,9 @@ export class SegmentTree<E = number> implements Iterable<E> {
|
|
|
106
106
|
|
|
107
107
|
|
|
108
108
|
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
109
112
|
|
|
110
113
|
|
|
111
114
|
|
|
@@ -178,6 +181,9 @@ export class SegmentTree<E = number> implements Iterable<E> {
|
|
|
178
181
|
|
|
179
182
|
|
|
180
183
|
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
181
187
|
|
|
182
188
|
|
|
183
189
|
|
|
@@ -245,6 +251,9 @@ export class SegmentTree<E = number> implements Iterable<E> {
|
|
|
245
251
|
|
|
246
252
|
|
|
247
253
|
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
248
257
|
|
|
249
258
|
|
|
250
259
|
|
|
@@ -319,6 +328,9 @@ export class SegmentTree<E = number> implements Iterable<E> {
|
|
|
319
328
|
|
|
320
329
|
|
|
321
330
|
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
|
|
322
334
|
|
|
323
335
|
|
|
324
336
|
|
|
@@ -369,6 +381,9 @@ export class SegmentTree<E = number> implements Iterable<E> {
|
|
|
369
381
|
|
|
370
382
|
|
|
371
383
|
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
|
|
372
387
|
|
|
373
388
|
|
|
374
389
|
|
|
@@ -458,6 +473,9 @@ export class SegmentTree<E = number> implements Iterable<E> {
|
|
|
458
473
|
|
|
459
474
|
|
|
460
475
|
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
|
|
461
479
|
|
|
462
480
|
|
|
463
481
|
|