max-priority-queue-typed 2.5.1 → 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 +207 -71
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +206 -70
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +207 -72
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +206 -71
- 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 +86 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +98 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +189 -13
- package/dist/types/data-structures/binary-tree/bst.d.ts +270 -3
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +136 -8
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +42 -0
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +1089 -161
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1243 -350
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +980 -255
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +1174 -284
- package/dist/types/data-structures/graph/directed-graph.d.ts +70 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +63 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +84 -6
- package/dist/types/data-structures/heap/heap.d.ts +140 -12
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +126 -0
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +106 -1
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +126 -0
- package/dist/types/data-structures/matrix/matrix.d.ts +56 -0
- package/dist/types/data-structures/queue/deque.d.ts +127 -0
- package/dist/types/data-structures/queue/queue.d.ts +97 -0
- package/dist/types/data-structures/stack/stack.d.ts +72 -2
- package/dist/types/data-structures/trie/trie.d.ts +84 -0
- package/dist/types/interfaces/binary-tree.d.ts +2 -3
- 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 +204 -69
- 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 +99 -5
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +102 -4
- package/src/data-structures/binary-tree/binary-tree.ts +239 -78
- package/src/data-structures/binary-tree/bst.ts +542 -13
- package/src/data-structures/binary-tree/red-black-tree.ts +155 -15
- package/src/data-structures/binary-tree/segment-tree.ts +42 -0
- package/src/data-structures/binary-tree/tree-map.ts +1223 -261
- package/src/data-structures/binary-tree/tree-multi-map.ts +939 -30
- package/src/data-structures/binary-tree/tree-multi-set.ts +746 -10
- package/src/data-structures/binary-tree/tree-set.ts +1018 -99
- package/src/data-structures/graph/abstract-graph.ts +2 -2
- package/src/data-structures/graph/directed-graph.ts +71 -1
- package/src/data-structures/graph/undirected-graph.ts +64 -1
- package/src/data-structures/hash/hash-map.ts +102 -16
- package/src/data-structures/heap/heap.ts +153 -23
- package/src/data-structures/heap/max-heap.ts +2 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +139 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +106 -1
- package/src/data-structures/linked-list/skip-linked-list.ts +131 -5
- package/src/data-structures/matrix/matrix.ts +65 -9
- package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
- package/src/data-structures/queue/deque.ts +130 -0
- package/src/data-structures/queue/queue.ts +109 -0
- package/src/data-structures/stack/stack.ts +75 -5
- package/src/data-structures/trie/trie.ts +86 -2
- package/src/interfaces/binary-tree.ts +1 -9
- 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
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import type {
|
|
10
|
-
|
|
10
|
+
BTNRep,
|
|
11
11
|
CRUD,
|
|
12
12
|
EntryCallback,
|
|
13
13
|
FamilyPosition, NodePredicate,
|
|
@@ -332,14 +332,36 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
|
|
|
332
332
|
}
|
|
333
333
|
|
|
334
334
|
/**
|
|
335
|
-
* Remove all nodes
|
|
335
|
+
* Remove all nodes, clear the key→value store (if in map mode) and internal caches.
|
|
336
336
|
* @remarks Time O(n), Space O(1)
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
|
|
343
365
|
|
|
344
366
|
|
|
345
367
|
|
|
@@ -554,6 +576,7 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
|
|
|
554
576
|
node.left = NIL;
|
|
555
577
|
node.right = NIL;
|
|
556
578
|
node.color = 'RED';
|
|
579
|
+
this._updateCountAlongPath(node);
|
|
557
580
|
this._insertFixup(node);
|
|
558
581
|
if (this.isRealNode(this._root)) this._root.color = 'BLACK';
|
|
559
582
|
}
|
|
@@ -684,6 +707,7 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
|
|
|
684
707
|
newNode.right = NIL;
|
|
685
708
|
newNode.color = 'RED';
|
|
686
709
|
|
|
710
|
+
this._updateCountAlongPath(newNode);
|
|
687
711
|
this._insertFixup(newNode);
|
|
688
712
|
if (this.isRealNode(this._root)) this._root.color = 'BLACK';
|
|
689
713
|
else return undefined;
|
|
@@ -956,6 +980,34 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
|
|
|
956
980
|
|
|
957
981
|
|
|
958
982
|
|
|
983
|
+
|
|
984
|
+
|
|
985
|
+
|
|
986
|
+
|
|
987
|
+
|
|
988
|
+
|
|
989
|
+
|
|
990
|
+
|
|
991
|
+
|
|
992
|
+
|
|
993
|
+
|
|
994
|
+
|
|
995
|
+
|
|
996
|
+
|
|
997
|
+
|
|
998
|
+
|
|
999
|
+
|
|
1000
|
+
|
|
1001
|
+
|
|
1002
|
+
|
|
1003
|
+
|
|
1004
|
+
|
|
1005
|
+
|
|
1006
|
+
|
|
1007
|
+
|
|
1008
|
+
|
|
1009
|
+
|
|
1010
|
+
|
|
959
1011
|
|
|
960
1012
|
|
|
961
1013
|
|
|
@@ -1156,6 +1208,34 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
|
|
|
1156
1208
|
|
|
1157
1209
|
|
|
1158
1210
|
|
|
1211
|
+
|
|
1212
|
+
|
|
1213
|
+
|
|
1214
|
+
|
|
1215
|
+
|
|
1216
|
+
|
|
1217
|
+
|
|
1218
|
+
|
|
1219
|
+
|
|
1220
|
+
|
|
1221
|
+
|
|
1222
|
+
|
|
1223
|
+
|
|
1224
|
+
|
|
1225
|
+
|
|
1226
|
+
|
|
1227
|
+
|
|
1228
|
+
|
|
1229
|
+
|
|
1230
|
+
|
|
1231
|
+
|
|
1232
|
+
|
|
1233
|
+
|
|
1234
|
+
|
|
1235
|
+
|
|
1236
|
+
|
|
1237
|
+
|
|
1238
|
+
|
|
1159
1239
|
|
|
1160
1240
|
|
|
1161
1241
|
|
|
@@ -1186,16 +1266,15 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
|
|
|
1186
1266
|
*/
|
|
1187
1267
|
override delete(
|
|
1188
1268
|
keyNodeEntryRawOrPredicate: BTNRep<K, V, RedBlackTreeNode<K, V>> | NodePredicate<RedBlackTreeNode<K, V> | null>
|
|
1189
|
-
):
|
|
1190
|
-
if (keyNodeEntryRawOrPredicate === null) return
|
|
1269
|
+
): boolean {
|
|
1270
|
+
if (keyNodeEntryRawOrPredicate === null) return false;
|
|
1191
1271
|
|
|
1192
|
-
const results: BinaryTreeDeleteResult<RedBlackTreeNode<K, V>>[] = [];
|
|
1193
1272
|
let nodeToDelete: OptNode<RedBlackTreeNode<K, V>>;
|
|
1194
1273
|
if (this._isPredicate(keyNodeEntryRawOrPredicate)) nodeToDelete = this.getNode(keyNodeEntryRawOrPredicate);
|
|
1195
1274
|
else nodeToDelete = this.isRealNode(keyNodeEntryRawOrPredicate) ? keyNodeEntryRawOrPredicate : this.getNode(keyNodeEntryRawOrPredicate);
|
|
1196
1275
|
|
|
1197
1276
|
if (!nodeToDelete) {
|
|
1198
|
-
return
|
|
1277
|
+
return false;
|
|
1199
1278
|
}
|
|
1200
1279
|
|
|
1201
1280
|
// Track min/max cache updates before structural modifications.
|
|
@@ -1245,6 +1324,9 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
|
|
|
1245
1324
|
if (this._isMapMode) this._store.delete(nodeToDelete.key);
|
|
1246
1325
|
this._size--;
|
|
1247
1326
|
|
|
1327
|
+
// Update order-statistic counts from replacement up to root
|
|
1328
|
+
this._updateCountAlongPath(replacementNode?.parent as RedBlackTreeNode<K, V> | undefined ?? replacementNode);
|
|
1329
|
+
|
|
1248
1330
|
// Update min/max caches.
|
|
1249
1331
|
if (this._size <= 0) {
|
|
1250
1332
|
this._setMinCache(undefined);
|
|
@@ -1265,9 +1347,7 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
|
|
|
1265
1347
|
this._deleteFixup(replacementNode);
|
|
1266
1348
|
}
|
|
1267
1349
|
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
return results;
|
|
1350
|
+
return true;
|
|
1271
1351
|
}
|
|
1272
1352
|
|
|
1273
1353
|
/**
|
|
@@ -1352,6 +1432,27 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
|
|
|
1352
1432
|
|
|
1353
1433
|
|
|
1354
1434
|
|
|
1435
|
+
|
|
1436
|
+
|
|
1437
|
+
|
|
1438
|
+
|
|
1439
|
+
|
|
1440
|
+
|
|
1441
|
+
|
|
1442
|
+
|
|
1443
|
+
|
|
1444
|
+
|
|
1445
|
+
|
|
1446
|
+
|
|
1447
|
+
|
|
1448
|
+
|
|
1449
|
+
|
|
1450
|
+
|
|
1451
|
+
|
|
1452
|
+
|
|
1453
|
+
|
|
1454
|
+
|
|
1455
|
+
|
|
1355
1456
|
|
|
1356
1457
|
|
|
1357
1458
|
|
|
@@ -1493,6 +1594,34 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
|
|
|
1493
1594
|
|
|
1494
1595
|
|
|
1495
1596
|
|
|
1597
|
+
|
|
1598
|
+
|
|
1599
|
+
|
|
1600
|
+
|
|
1601
|
+
|
|
1602
|
+
|
|
1603
|
+
|
|
1604
|
+
|
|
1605
|
+
|
|
1606
|
+
|
|
1607
|
+
|
|
1608
|
+
|
|
1609
|
+
|
|
1610
|
+
|
|
1611
|
+
|
|
1612
|
+
|
|
1613
|
+
|
|
1614
|
+
|
|
1615
|
+
|
|
1616
|
+
|
|
1617
|
+
|
|
1618
|
+
|
|
1619
|
+
|
|
1620
|
+
|
|
1621
|
+
|
|
1622
|
+
|
|
1623
|
+
|
|
1624
|
+
|
|
1496
1625
|
|
|
1497
1626
|
|
|
1498
1627
|
|
|
@@ -1632,6 +1761,9 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
|
|
|
1632
1761
|
node.right = NIL;
|
|
1633
1762
|
node.color = 'RED';
|
|
1634
1763
|
|
|
1764
|
+
// Update counts along insertion path before fixup
|
|
1765
|
+
this._updateCountAlongPath(node);
|
|
1766
|
+
|
|
1635
1767
|
this._insertFixup(node);
|
|
1636
1768
|
return 'CREATED';
|
|
1637
1769
|
}
|
|
@@ -1835,6 +1967,10 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
|
|
|
1835
1967
|
|
|
1836
1968
|
y.left = x;
|
|
1837
1969
|
x.parent = y;
|
|
1970
|
+
|
|
1971
|
+
// Update counts: x first (now child), then y (now parent)
|
|
1972
|
+
this._updateCount(x);
|
|
1973
|
+
this._updateCount(y);
|
|
1838
1974
|
}
|
|
1839
1975
|
|
|
1840
1976
|
/**
|
|
@@ -1867,5 +2003,9 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
|
|
|
1867
2003
|
|
|
1868
2004
|
x.right = y;
|
|
1869
2005
|
y.parent = x;
|
|
2006
|
+
|
|
2007
|
+
// Update counts: y first (now child), then x (now parent)
|
|
2008
|
+
this._updateCount(y);
|
|
2009
|
+
this._updateCount(x);
|
|
1870
2010
|
}
|
|
1871
2011
|
}
|
|
@@ -102,6 +102,13 @@ export class SegmentTree<E = number> implements Iterable<E> {
|
|
|
102
102
|
|
|
103
103
|
|
|
104
104
|
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
105
112
|
|
|
106
113
|
|
|
107
114
|
|
|
@@ -174,6 +181,13 @@ export class SegmentTree<E = number> implements Iterable<E> {
|
|
|
174
181
|
|
|
175
182
|
|
|
176
183
|
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
|
|
177
191
|
|
|
178
192
|
|
|
179
193
|
|
|
@@ -241,6 +255,13 @@ export class SegmentTree<E = number> implements Iterable<E> {
|
|
|
241
255
|
|
|
242
256
|
|
|
243
257
|
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
|
|
244
265
|
|
|
245
266
|
|
|
246
267
|
|
|
@@ -315,6 +336,13 @@ export class SegmentTree<E = number> implements Iterable<E> {
|
|
|
315
336
|
|
|
316
337
|
|
|
317
338
|
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
|
|
318
346
|
|
|
319
347
|
|
|
320
348
|
|
|
@@ -365,6 +393,13 @@ export class SegmentTree<E = number> implements Iterable<E> {
|
|
|
365
393
|
|
|
366
394
|
|
|
367
395
|
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
|
|
368
403
|
|
|
369
404
|
|
|
370
405
|
|
|
@@ -454,6 +489,13 @@ export class SegmentTree<E = number> implements Iterable<E> {
|
|
|
454
489
|
|
|
455
490
|
|
|
456
491
|
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
|
|
498
|
+
|
|
457
499
|
|
|
458
500
|
|
|
459
501
|
|