binary-tree-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.
Files changed (73) hide show
  1. package/dist/cjs/index.cjs +146 -52
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +145 -51
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +146 -53
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +145 -52
  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/binary-tree/avl-tree.d.ts +36 -0
  12. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +42 -0
  13. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +77 -2
  14. package/dist/types/data-structures/binary-tree/bst.d.ts +171 -0
  15. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +57 -0
  16. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +18 -0
  17. package/dist/types/data-structures/binary-tree/tree-map.d.ts +409 -0
  18. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +411 -6
  19. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +339 -6
  20. package/dist/types/data-structures/binary-tree/tree-set.d.ts +391 -0
  21. package/dist/types/data-structures/graph/directed-graph.d.ts +30 -0
  22. package/dist/types/data-structures/graph/undirected-graph.d.ts +27 -0
  23. package/dist/types/data-structures/hash/hash-map.d.ts +33 -0
  24. package/dist/types/data-structures/heap/heap.d.ts +42 -0
  25. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +51 -0
  26. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +45 -0
  27. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +54 -0
  28. package/dist/types/data-structures/matrix/matrix.d.ts +24 -0
  29. package/dist/types/data-structures/queue/deque.d.ts +45 -0
  30. package/dist/types/data-structures/queue/queue.d.ts +36 -0
  31. package/dist/types/data-structures/stack/stack.d.ts +30 -0
  32. package/dist/types/data-structures/trie/trie.d.ts +36 -0
  33. package/dist/types/types/data-structures/binary-tree/bst.d.ts +1 -0
  34. package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +5 -0
  35. package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +4 -0
  36. package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +4 -0
  37. package/dist/umd/binary-tree-typed.js +143 -50
  38. package/dist/umd/binary-tree-typed.js.map +1 -1
  39. package/dist/umd/binary-tree-typed.min.js +3 -3
  40. package/dist/umd/binary-tree-typed.min.js.map +1 -1
  41. package/package.json +2 -2
  42. package/src/common/error.ts +19 -1
  43. package/src/common/index.ts +1 -1
  44. package/src/data-structures/base/iterable-element-base.ts +3 -2
  45. package/src/data-structures/binary-tree/avl-tree.ts +47 -0
  46. package/src/data-structures/binary-tree/binary-indexed-tree.ts +46 -4
  47. package/src/data-structures/binary-tree/binary-tree.ts +79 -4
  48. package/src/data-structures/binary-tree/bst.ts +441 -6
  49. package/src/data-structures/binary-tree/red-black-tree.ts +73 -0
  50. package/src/data-structures/binary-tree/segment-tree.ts +18 -0
  51. package/src/data-structures/binary-tree/tree-map.ts +434 -9
  52. package/src/data-structures/binary-tree/tree-multi-map.ts +426 -5
  53. package/src/data-structures/binary-tree/tree-multi-set.ts +350 -6
  54. package/src/data-structures/binary-tree/tree-set.ts +410 -8
  55. package/src/data-structures/graph/abstract-graph.ts +2 -2
  56. package/src/data-structures/graph/directed-graph.ts +30 -0
  57. package/src/data-structures/graph/undirected-graph.ts +27 -0
  58. package/src/data-structures/hash/hash-map.ts +35 -4
  59. package/src/data-structures/heap/heap.ts +46 -4
  60. package/src/data-structures/heap/max-heap.ts +2 -2
  61. package/src/data-structures/linked-list/doubly-linked-list.ts +51 -0
  62. package/src/data-structures/linked-list/singly-linked-list.ts +45 -0
  63. package/src/data-structures/linked-list/skip-linked-list.ts +59 -5
  64. package/src/data-structures/matrix/matrix.ts +33 -9
  65. package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
  66. package/src/data-structures/queue/deque.ts +45 -0
  67. package/src/data-structures/queue/queue.ts +36 -0
  68. package/src/data-structures/stack/stack.ts +30 -0
  69. package/src/data-structures/trie/trie.ts +38 -2
  70. package/src/types/data-structures/binary-tree/bst.ts +1 -0
  71. package/src/types/data-structures/binary-tree/tree-map.ts +6 -0
  72. package/src/types/data-structures/binary-tree/tree-multi-set.ts +5 -0
  73. 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