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.
Files changed (75) hide show
  1. package/dist/cjs/index.cjs +207 -71
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +206 -70
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +207 -72
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +206 -71
  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 +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 +189 -13
  14. package/dist/types/data-structures/binary-tree/bst.d.ts +270 -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 +1089 -161
  18. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1243 -350
  19. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +980 -255
  20. package/dist/types/data-structures/binary-tree/tree-set.d.ts +1174 -284
  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 +126 -0
  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 +127 -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/types/types/data-structures/binary-tree/bst.d.ts +1 -0
  35. package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +5 -0
  36. package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +4 -0
  37. package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +4 -0
  38. package/dist/umd/max-priority-queue-typed.js +204 -69
  39. package/dist/umd/max-priority-queue-typed.js.map +1 -1
  40. package/dist/umd/max-priority-queue-typed.min.js +1 -1
  41. package/dist/umd/max-priority-queue-typed.min.js.map +1 -1
  42. package/package.json +2 -2
  43. package/src/common/error.ts +19 -1
  44. package/src/common/index.ts +1 -1
  45. package/src/data-structures/base/iterable-element-base.ts +3 -2
  46. package/src/data-structures/binary-tree/avl-tree.ts +99 -5
  47. package/src/data-structures/binary-tree/binary-indexed-tree.ts +102 -4
  48. package/src/data-structures/binary-tree/binary-tree.ts +239 -78
  49. package/src/data-structures/binary-tree/bst.ts +542 -13
  50. package/src/data-structures/binary-tree/red-black-tree.ts +155 -15
  51. package/src/data-structures/binary-tree/segment-tree.ts +42 -0
  52. package/src/data-structures/binary-tree/tree-map.ts +1223 -261
  53. package/src/data-structures/binary-tree/tree-multi-map.ts +939 -30
  54. package/src/data-structures/binary-tree/tree-multi-set.ts +746 -10
  55. package/src/data-structures/binary-tree/tree-set.ts +1018 -99
  56. package/src/data-structures/graph/abstract-graph.ts +2 -2
  57. package/src/data-structures/graph/directed-graph.ts +71 -1
  58. package/src/data-structures/graph/undirected-graph.ts +64 -1
  59. package/src/data-structures/hash/hash-map.ts +102 -16
  60. package/src/data-structures/heap/heap.ts +153 -23
  61. package/src/data-structures/heap/max-heap.ts +2 -2
  62. package/src/data-structures/linked-list/doubly-linked-list.ts +139 -0
  63. package/src/data-structures/linked-list/singly-linked-list.ts +106 -1
  64. package/src/data-structures/linked-list/skip-linked-list.ts +131 -5
  65. package/src/data-structures/matrix/matrix.ts +65 -9
  66. package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
  67. package/src/data-structures/queue/deque.ts +130 -0
  68. package/src/data-structures/queue/queue.ts +109 -0
  69. package/src/data-structures/stack/stack.ts +75 -5
  70. package/src/data-structures/trie/trie.ts +86 -2
  71. package/src/interfaces/binary-tree.ts +1 -9
  72. package/src/types/data-structures/binary-tree/bst.ts +1 -0
  73. package/src/types/data-structures/binary-tree/tree-map.ts +6 -0
  74. package/src/types/data-structures/binary-tree/tree-multi-set.ts +5 -0
  75. package/src/types/data-structures/binary-tree/tree-set.ts +5 -0
@@ -198,14 +198,6 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
198
198
 
199
199
 
200
200
 
201
- * @example
202
- * // Check empty
203
- * console.log(new TreeMap().isEmpty()); // true;
204
- */
205
- isEmpty(): boolean;
206
- /**
207
- * Set or overwrite a value for a key.
208
- * @remarks Expected time O(log n)
209
201
 
210
202
 
211
203
 
@@ -241,6 +233,15 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
241
233
 
242
234
 
243
235
 
236
+ * @example
237
+ * // Check empty
238
+ * console.log(new TreeMap().isEmpty()); // true;
239
+ */
240
+ isEmpty(): boolean;
241
+ /**
242
+ * Set or overwrite a value for a key.
243
+ * @remarks Expected time O(log n)
244
+
244
245
 
245
246
 
246
247
 
@@ -358,31 +359,6 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
358
359
 
359
360
 
360
361
 
361
- * @example
362
- * // Sorted dictionary for a contact book
363
- * const contacts = new TreeMap<string, string>([
364
- * ['Bob', '555-0102'],
365
- * ['Alice', '555-0101'],
366
- * ['Charlie', '555-0103']
367
- * ]);
368
- *
369
- * // Contacts are automatically sorted by name
370
- * console.log([...contacts.keys()]); // ['Alice', 'Bob', 'Charlie'];
371
- * console.log(contacts.get('Bob')); // '555-0102';
372
- *
373
- * // Find the first contact alphabetically after 'B'
374
- * console.log(contacts.ceiling('B')); // ['Bob', '555-0102'];
375
- *
376
- * // Find contacts in range
377
- * console.log(contacts.rangeSearch(['Alice', 'Bob'])); // [
378
- * // ['Alice', '555-0101'],
379
- * // ['Bob', '555-0102']
380
- * // ];
381
- */
382
- set(key: K, value: V | undefined): this;
383
- /**
384
- * Get the value under a key.
385
- * @remarks Expected time O(log n)
386
362
 
387
363
 
388
364
 
@@ -452,6 +428,34 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
452
428
 
453
429
 
454
430
 
431
+ * @example
432
+ * // Sorted dictionary for a contact book
433
+ * const contacts = new TreeMap<string, string>([
434
+ * ['Bob', '555-0102'],
435
+ * ['Alice', '555-0101'],
436
+ * ['Charlie', '555-0103']
437
+ * ]);
438
+ *
439
+ * // Contacts are automatically sorted by name
440
+ * console.log([...contacts.keys()]); // ['Alice', 'Bob', 'Charlie'];
441
+ * console.log(contacts.get('Bob')); // '555-0102';
442
+ *
443
+ * // Find the first contact alphabetically after 'B'
444
+ * console.log(contacts.ceiling('B')); // ['Bob', '555-0102'];
445
+ *
446
+ * // Find contacts in range
447
+ * console.log(contacts.rangeSearch(['Alice', 'Bob'])); // [
448
+ * // ['Alice', '555-0101'],
449
+ * // ['Bob', '555-0102']
450
+ * // ];
451
+ */
452
+ set(key: K, value: V | undefined): this;
453
+ /**
454
+ * Set multiple key-value pairs at once.
455
+ * @remarks Expected time O(m log n), where m is the number of entries.
456
+ * @param entries - Iterable of `[key, value]` tuples.
457
+ * @returns Array of booleans indicating whether each entry was successfully set.
458
+
455
459
 
456
460
 
457
461
 
@@ -467,6 +471,16 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
467
471
 
468
472
 
469
473
 
474
+ * @example
475
+ * // Set multiple key-value pairs
476
+ * const tm = new TreeMap<number, string>();
477
+ * tm.setMany([[1, 'a'], [2, 'b'], [3, 'c']]);
478
+ * console.log(tm.size); // 3;
479
+ */
480
+ setMany(entries: Iterable<[K, V | undefined]>): boolean[];
481
+ /**
482
+ * Get the value under a key.
483
+ * @remarks Expected time O(log n)
470
484
 
471
485
 
472
486
 
@@ -537,22 +551,6 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
537
551
 
538
552
 
539
553
 
540
- * @example
541
- * // Configuration registry with typed lookups
542
- * const config = new TreeMap<string, number>([
543
- * ['maxRetries', 3],
544
- * ['timeout', 5000],
545
- * ['poolSize', 10]
546
- * ]);
547
- *
548
- * console.log(config.get('timeout')); // 5000;
549
- * console.log(config.get('missing')); // undefined;
550
- * console.log(config.size); // 3;
551
- */
552
- get(key: K): V | undefined;
553
- /**
554
- * Test whether a key exists.
555
- * @remarks Expected time O(log n)
556
554
 
557
555
 
558
556
 
@@ -672,6 +670,22 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
672
670
 
673
671
 
674
672
 
673
+ * @example
674
+ * // Configuration registry with typed lookups
675
+ * const config = new TreeMap<string, number>([
676
+ * ['maxRetries', 3],
677
+ * ['timeout', 5000],
678
+ * ['poolSize', 10]
679
+ * ]);
680
+ *
681
+ * console.log(config.get('timeout')); // 5000;
682
+ * console.log(config.get('missing')); // undefined;
683
+ * console.log(config.size); // 3;
684
+ */
685
+ get(key: K): V | undefined;
686
+ /**
687
+ * Test whether a key exists.
688
+ * @remarks Expected time O(log n)
675
689
 
676
690
 
677
691
 
@@ -707,22 +721,6 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
707
721
 
708
722
 
709
723
 
710
- * @example
711
- * // Feature flag checking
712
- * const flags = new TreeMap<string, boolean>([
713
- * ['darkMode', true],
714
- * ['betaFeature', false],
715
- * ['notifications', true]
716
- * ]);
717
- *
718
- * console.log(flags.has('darkMode')); // true;
719
- * console.log(flags.has('unknownFlag')); // false;
720
- */
721
- has(key: K): boolean;
722
- /**
723
- * Delete a key.
724
- * @returns `true` if the key existed; otherwise `false`.
725
- * @remarks Expected time O(log n)
726
724
 
727
725
 
728
726
 
@@ -878,22 +876,21 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
878
876
 
879
877
 
880
878
  * @example
881
- * // Session management with expiry
882
- * const sessions = new TreeMap<string, number>([
883
- * ['sess_abc', Date.now()],
884
- * ['sess_def', Date.now()],
885
- * ['sess_ghi', Date.now()]
879
+ * // Feature flag checking
880
+ * const flags = new TreeMap<string, boolean>([
881
+ * ['darkMode', true],
882
+ * ['betaFeature', false],
883
+ * ['notifications', true]
886
884
  * ]);
887
885
  *
888
- * console.log(sessions.size); // 3;
889
- * sessions.delete('sess_def');
890
- * console.log(sessions.has('sess_def')); // false;
891
- * console.log(sessions.size); // 2;
886
+ * console.log(flags.has('darkMode')); // true;
887
+ * console.log(flags.has('unknownFlag')); // false;
892
888
  */
893
- delete(key: K): boolean;
889
+ has(key: K): boolean;
894
890
  /**
895
- * Remove all entries.
896
-
891
+ * Delete a key.
892
+ * @returns `true` if the key existed; otherwise `false`.
893
+ * @remarks Expected time O(log n)
897
894
 
898
895
 
899
896
 
@@ -1036,15 +1033,6 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
1036
1033
 
1037
1034
 
1038
1035
 
1039
- * @example
1040
- * // Remove all
1041
- * const tm = new TreeMap<number, string>([[1, 'a']]);
1042
- * tm.clear();
1043
- * console.log(tm.isEmpty()); // true;
1044
- */
1045
- clear(): void;
1046
- /**
1047
- * Iterate over keys in ascending order.
1048
1036
 
1049
1037
 
1050
1038
 
@@ -1092,6 +1080,29 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
1092
1080
 
1093
1081
 
1094
1082
 
1083
+ * @example
1084
+ * // Session management with expiry
1085
+ * const sessions = new TreeMap<string, number>([
1086
+ * ['sess_abc', Date.now()],
1087
+ * ['sess_def', Date.now()],
1088
+ * ['sess_ghi', Date.now()]
1089
+ * ]);
1090
+ *
1091
+ * console.log(sessions.size); // 3;
1092
+ * sessions.delete('sess_def');
1093
+ * console.log(sessions.has('sess_def')); // false;
1094
+ * console.log(sessions.size); // 2;
1095
+ */
1096
+ delete(key: K): boolean;
1097
+ /**
1098
+ * Delete all entries matching a predicate.
1099
+ * @remarks Time O(N), Space O(N)
1100
+ * @param predicate - Function (key, value, index, map) → boolean; return true to delete.
1101
+ * @returns True if at least one entry was deleted.
1102
+ */
1103
+ deleteWhere(predicate: (key: K, value: V | undefined, index: number, map: this) => boolean): boolean;
1104
+ /**
1105
+ * Remove all entries.
1095
1106
 
1096
1107
 
1097
1108
 
@@ -1188,17 +1199,6 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
1188
1199
 
1189
1200
 
1190
1201
 
1191
- * @example
1192
- * // Get sorted keys
1193
- * const tm = new TreeMap<number, string>([[3, 'c'], [1, 'a']]);
1194
- * console.log([...tm.keys()]); // [1, 3];
1195
- */
1196
- keys(): IterableIterator<K>;
1197
- private _entryFromKey;
1198
- /**
1199
- * Iterate over values in ascending key order.
1200
- *
1201
- * Note: values may be `undefined` (TreeMap allows storing `undefined`, like native `Map`).
1202
1202
 
1203
1203
 
1204
1204
 
@@ -1281,6 +1281,15 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
1281
1281
 
1282
1282
 
1283
1283
 
1284
+ * @example
1285
+ * // Remove all
1286
+ * const tm = new TreeMap<number, string>([[1, 'a']]);
1287
+ * tm.clear();
1288
+ * console.log(tm.isEmpty()); // true;
1289
+ */
1290
+ clear(): void;
1291
+ /**
1292
+ * Iterate over keys in ascending order.
1284
1293
 
1285
1294
 
1286
1295
 
@@ -1342,16 +1351,6 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
1342
1351
 
1343
1352
 
1344
1353
 
1345
- * @example
1346
- * // Get values in key order
1347
- * const tm = new TreeMap<number, string>([[2, 'b'], [1, 'a']]);
1348
- * console.log([...tm.values()]); // ['a', 'b'];
1349
- */
1350
- values(): IterableIterator<V | undefined>;
1351
- /**
1352
- * Iterate over `[key, value]` entries in ascending key order.
1353
- *
1354
- * Note: values may be `undefined`.
1355
1354
 
1356
1355
 
1357
1356
 
@@ -1469,6 +1468,17 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
1469
1468
 
1470
1469
 
1471
1470
 
1471
+ * @example
1472
+ * // Get sorted keys
1473
+ * const tm = new TreeMap<number, string>([[3, 'c'], [1, 'a']]);
1474
+ * console.log([...tm.keys()]); // [1, 3];
1475
+ */
1476
+ keys(): IterableIterator<K>;
1477
+ private _entryFromKey;
1478
+ /**
1479
+ * Iterate over values in ascending key order.
1480
+ *
1481
+ * Note: values may be `undefined` (TreeMap allows storing `undefined`, like native `Map`).
1472
1482
 
1473
1483
 
1474
1484
 
@@ -1495,17 +1505,6 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
1495
1505
 
1496
1506
 
1497
1507
 
1498
- * @example
1499
- * // Iterate key-value pairs
1500
- * const tm = new TreeMap<number, string>([[3, 'c'], [1, 'a'], [2, 'b']]);
1501
- * console.log([...tm.entries()]); // [[1, 'a'], [2, 'b'], [3, 'c']];
1502
- */
1503
- entries(): IterableIterator<[K, V | undefined]>;
1504
- [Symbol.iterator](): IterableIterator<[K, V | undefined]>;
1505
- /**
1506
- * Visit each entry in ascending key order.
1507
- *
1508
- * Note: callback value may be `undefined`.
1509
1508
 
1510
1509
 
1511
1510
 
@@ -1649,19 +1648,6 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
1649
1648
 
1650
1649
 
1651
1650
 
1652
- * @example
1653
- * // Execute for each entry
1654
- * const tm = new TreeMap<number, string>([[1, 'a'], [2, 'b']]);
1655
- * const pairs: string[] = [];
1656
- * tm.forEach((v, k) => pairs.push(`${k}:${v}`));
1657
- * console.log(pairs); // ['1:a', '2:b'];
1658
- */
1659
- forEach(cb: (value: V | undefined, key: K, map: TreeMap<K, V>) => void, thisArg?: unknown): void;
1660
- /**
1661
- * Create a new TreeMap by mapping each entry to a new `[key, value]` entry.
1662
- *
1663
- * This mirrors `RedBlackTree.map`: mapping produces a new ordered container.
1664
- * @remarks Time O(n log n) expected, Space O(n)
1665
1651
 
1666
1652
 
1667
1653
 
@@ -1671,6 +1657,16 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
1671
1657
 
1672
1658
 
1673
1659
 
1660
+ * @example
1661
+ * // Get values in key order
1662
+ * const tm = new TreeMap<number, string>([[2, 'b'], [1, 'a']]);
1663
+ * console.log([...tm.values()]); // ['a', 'b'];
1664
+ */
1665
+ values(): IterableIterator<V | undefined>;
1666
+ /**
1667
+ * Iterate over `[key, value]` entries in ascending key order.
1668
+ *
1669
+ * Note: values may be `undefined`.
1674
1670
 
1675
1671
 
1676
1672
 
@@ -1805,18 +1801,477 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
1805
1801
 
1806
1802
 
1807
1803
 
1808
- * @example
1809
- * // Transform entries
1810
- * const tm = new TreeMap<number, number>([[1, 10], [2, 20]]);
1811
- * const doubled = tm.map((v, k) => [k, (v ?? 0) * 2] as [number, number]);
1812
- * console.log([...doubled.values()]); // [20, 40];
1813
- */
1814
- map<MK, MV>(callbackfn: TreeMapEntryCallback<K, V, [MK, MV], TreeMap<K, V>>, options?: Omit<TreeMapOptions<MK, MV>, 'toEntryFn'> & {
1815
- comparator?: (a: MK, b: MK) => number;
1816
- }, thisArg?: unknown): TreeMap<MK, MV>;
1817
- /**
1818
- * Create a new TreeMap containing only entries that satisfy the predicate.
1819
- * @remarks Time O(n log n) expected, Space O(n)
1804
+
1805
+
1806
+
1807
+
1808
+
1809
+
1810
+
1811
+
1812
+
1813
+
1814
+
1815
+
1816
+
1817
+
1818
+
1819
+
1820
+
1821
+
1822
+
1823
+
1824
+
1825
+
1826
+
1827
+
1828
+
1829
+
1830
+
1831
+
1832
+
1833
+
1834
+
1835
+
1836
+
1837
+
1838
+
1839
+
1840
+
1841
+
1842
+
1843
+
1844
+
1845
+
1846
+
1847
+
1848
+ * @example
1849
+ * // Iterate key-value pairs
1850
+ * const tm = new TreeMap<number, string>([[3, 'c'], [1, 'a'], [2, 'b']]);
1851
+ * console.log([...tm.entries()]); // [[1, 'a'], [2, 'b'], [3, 'c']];
1852
+ */
1853
+ entries(): IterableIterator<[K, V | undefined]>;
1854
+ [Symbol.iterator](): IterableIterator<[K, V | undefined]>;
1855
+ /**
1856
+ * Visit each entry in ascending key order.
1857
+ *
1858
+ * Note: callback value may be `undefined`.
1859
+
1860
+
1861
+
1862
+
1863
+
1864
+
1865
+
1866
+
1867
+
1868
+
1869
+
1870
+
1871
+
1872
+
1873
+
1874
+
1875
+
1876
+
1877
+
1878
+
1879
+
1880
+
1881
+
1882
+
1883
+
1884
+
1885
+
1886
+
1887
+
1888
+
1889
+
1890
+
1891
+
1892
+
1893
+
1894
+
1895
+
1896
+
1897
+
1898
+
1899
+
1900
+
1901
+
1902
+
1903
+
1904
+
1905
+
1906
+
1907
+
1908
+
1909
+
1910
+
1911
+
1912
+
1913
+
1914
+
1915
+
1916
+
1917
+
1918
+
1919
+
1920
+
1921
+
1922
+
1923
+
1924
+
1925
+
1926
+
1927
+
1928
+
1929
+
1930
+
1931
+
1932
+
1933
+
1934
+
1935
+
1936
+
1937
+
1938
+
1939
+
1940
+
1941
+
1942
+
1943
+
1944
+
1945
+
1946
+
1947
+
1948
+
1949
+
1950
+
1951
+
1952
+
1953
+
1954
+
1955
+
1956
+
1957
+
1958
+
1959
+
1960
+
1961
+
1962
+
1963
+
1964
+
1965
+
1966
+
1967
+
1968
+
1969
+
1970
+
1971
+
1972
+
1973
+
1974
+
1975
+
1976
+
1977
+
1978
+
1979
+
1980
+
1981
+
1982
+
1983
+
1984
+
1985
+
1986
+
1987
+
1988
+
1989
+
1990
+
1991
+
1992
+
1993
+
1994
+
1995
+
1996
+
1997
+
1998
+
1999
+
2000
+
2001
+
2002
+
2003
+
2004
+
2005
+
2006
+
2007
+
2008
+
2009
+
2010
+
2011
+
2012
+
2013
+
2014
+
2015
+
2016
+
2017
+
2018
+
2019
+
2020
+
2021
+
2022
+
2023
+
2024
+
2025
+
2026
+
2027
+
2028
+
2029
+
2030
+
2031
+
2032
+
2033
+
2034
+
2035
+
2036
+
2037
+ * @example
2038
+ * // Execute for each entry
2039
+ * const tm = new TreeMap<number, string>([[1, 'a'], [2, 'b']]);
2040
+ * const pairs: string[] = [];
2041
+ * tm.forEach((v, k) => pairs.push(`${k}:${v}`));
2042
+ * console.log(pairs); // ['1:a', '2:b'];
2043
+ */
2044
+ forEach(cb: (value: V | undefined, key: K, map: TreeMap<K, V>) => void, thisArg?: unknown): void;
2045
+ /**
2046
+ * Create a new TreeMap by mapping each entry to a new `[key, value]` entry.
2047
+ *
2048
+ * This mirrors `RedBlackTree.map`: mapping produces a new ordered container.
2049
+ * @remarks Time O(n log n) expected, Space O(n)
2050
+
2051
+
2052
+
2053
+
2054
+
2055
+
2056
+
2057
+
2058
+
2059
+
2060
+
2061
+
2062
+
2063
+
2064
+
2065
+
2066
+
2067
+
2068
+
2069
+
2070
+
2071
+
2072
+
2073
+
2074
+
2075
+
2076
+
2077
+
2078
+
2079
+
2080
+
2081
+
2082
+
2083
+
2084
+
2085
+
2086
+
2087
+
2088
+
2089
+
2090
+
2091
+
2092
+
2093
+
2094
+
2095
+
2096
+
2097
+
2098
+
2099
+
2100
+
2101
+
2102
+
2103
+
2104
+
2105
+
2106
+
2107
+
2108
+
2109
+
2110
+
2111
+
2112
+
2113
+
2114
+
2115
+
2116
+
2117
+
2118
+
2119
+
2120
+
2121
+
2122
+
2123
+
2124
+
2125
+
2126
+
2127
+
2128
+
2129
+
2130
+
2131
+
2132
+
2133
+
2134
+
2135
+
2136
+
2137
+
2138
+
2139
+
2140
+
2141
+
2142
+
2143
+
2144
+
2145
+
2146
+
2147
+
2148
+
2149
+
2150
+
2151
+
2152
+
2153
+
2154
+
2155
+
2156
+
2157
+
2158
+
2159
+
2160
+
2161
+
2162
+
2163
+
2164
+
2165
+
2166
+
2167
+
2168
+
2169
+
2170
+
2171
+
2172
+
2173
+
2174
+
2175
+
2176
+
2177
+
2178
+
2179
+
2180
+
2181
+
2182
+
2183
+
2184
+
2185
+
2186
+
2187
+
2188
+
2189
+
2190
+
2191
+
2192
+
2193
+
2194
+
2195
+
2196
+
2197
+
2198
+
2199
+
2200
+
2201
+
2202
+
2203
+
2204
+
2205
+
2206
+
2207
+
2208
+
2209
+
2210
+
2211
+
2212
+
2213
+
2214
+
2215
+
2216
+
2217
+
2218
+
2219
+
2220
+
2221
+
2222
+
2223
+
2224
+
2225
+
2226
+
2227
+
2228
+ * @example
2229
+ * // Transform entries
2230
+ * const tm = new TreeMap<number, number>([[1, 10], [2, 20]]);
2231
+ * const doubled = tm.map((v, k) => [k, (v ?? 0) * 2] as [number, number]);
2232
+ * console.log([...doubled.values()]); // [20, 40];
2233
+ */
2234
+ map<MK, MV>(callbackfn: TreeMapEntryCallback<K, V, [MK, MV], TreeMap<K, V>>, options?: Omit<TreeMapOptions<MK, MV>, 'toEntryFn'> & {
2235
+ comparator?: (a: MK, b: MK) => number;
2236
+ }, thisArg?: unknown): TreeMap<MK, MV>;
2237
+ /**
2238
+ * Create a new TreeMap containing only entries that satisfy the predicate.
2239
+ * @remarks Time O(n log n) expected, Space O(n)
2240
+
2241
+
2242
+
2243
+
2244
+
2245
+
2246
+
2247
+
2248
+
2249
+
2250
+
2251
+
2252
+
2253
+
2254
+
2255
+
2256
+
2257
+
2258
+
2259
+
2260
+
2261
+
2262
+
2263
+
2264
+
2265
+
2266
+
2267
+
2268
+
2269
+
2270
+
2271
+
2272
+
2273
+
2274
+
1820
2275
 
1821
2276
 
1822
2277
 
@@ -2092,6 +2547,41 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
2092
2547
 
2093
2548
 
2094
2549
 
2550
+
2551
+
2552
+
2553
+
2554
+
2555
+
2556
+
2557
+
2558
+
2559
+
2560
+
2561
+
2562
+
2563
+
2564
+
2565
+
2566
+
2567
+
2568
+
2569
+
2570
+
2571
+
2572
+
2573
+
2574
+
2575
+
2576
+
2577
+
2578
+
2579
+
2580
+
2581
+
2582
+
2583
+
2584
+
2095
2585
 
2096
2586
 
2097
2587
 
@@ -2242,6 +2732,41 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
2242
2732
 
2243
2733
 
2244
2734
 
2735
+
2736
+
2737
+
2738
+
2739
+
2740
+
2741
+
2742
+
2743
+
2744
+
2745
+
2746
+
2747
+
2748
+
2749
+
2750
+
2751
+
2752
+
2753
+
2754
+
2755
+
2756
+
2757
+
2758
+
2759
+
2760
+
2761
+
2762
+
2763
+
2764
+
2765
+
2766
+
2767
+
2768
+
2769
+
2245
2770
 
2246
2771
 
2247
2772
 
@@ -2392,6 +2917,41 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
2392
2917
 
2393
2918
 
2394
2919
 
2920
+
2921
+
2922
+
2923
+
2924
+
2925
+
2926
+
2927
+
2928
+
2929
+
2930
+
2931
+
2932
+
2933
+
2934
+
2935
+
2936
+
2937
+
2938
+
2939
+
2940
+
2941
+
2942
+
2943
+
2944
+
2945
+
2946
+
2947
+
2948
+
2949
+
2950
+
2951
+
2952
+
2953
+
2954
+
2395
2955
 
2396
2956
 
2397
2957
 
@@ -2564,15 +3124,120 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
2564
3124
 
2565
3125
 
2566
3126
 
2567
- * @example
2568
- * // Find matching entry
2569
- * const tm = new TreeMap<number, string>([[1, 'a'], [2, 'b']]);
2570
- * console.log(tm.find(v => v === 'b')?.[0]); // 2;
2571
- */
2572
- find(callbackfn: TreeMapEntryCallback<K, V, boolean, TreeMap<K, V>>, thisArg?: unknown): [K, V | undefined] | undefined;
2573
- /**
2574
- * Materialize the map into an array of `[key, value]` tuples.
2575
- * @remarks Time O(n), Space O(n)
3127
+
3128
+
3129
+
3130
+
3131
+
3132
+
3133
+
3134
+
3135
+
3136
+
3137
+
3138
+
3139
+
3140
+
3141
+
3142
+
3143
+
3144
+
3145
+
3146
+
3147
+
3148
+
3149
+
3150
+
3151
+
3152
+
3153
+
3154
+
3155
+
3156
+
3157
+
3158
+
3159
+
3160
+
3161
+
3162
+ * @example
3163
+ * // Find matching entry
3164
+ * const tm = new TreeMap<number, string>([[1, 'a'], [2, 'b']]);
3165
+ * console.log(tm.find(v => v === 'b')?.[0]); // 2;
3166
+ */
3167
+ find(callbackfn: TreeMapEntryCallback<K, V, boolean, TreeMap<K, V>>, thisArg?: unknown): [K, V | undefined] | undefined;
3168
+ /**
3169
+ * Materialize the map into an array of `[key, value]` tuples.
3170
+ * @remarks Time O(n), Space O(n)
3171
+
3172
+
3173
+
3174
+
3175
+
3176
+
3177
+
3178
+
3179
+
3180
+
3181
+
3182
+
3183
+
3184
+
3185
+
3186
+
3187
+
3188
+
3189
+
3190
+
3191
+
3192
+
3193
+
3194
+
3195
+
3196
+
3197
+
3198
+
3199
+
3200
+
3201
+
3202
+
3203
+
3204
+
3205
+
3206
+
3207
+
3208
+
3209
+
3210
+
3211
+
3212
+
3213
+
3214
+
3215
+
3216
+
3217
+
3218
+
3219
+
3220
+
3221
+
3222
+
3223
+
3224
+
3225
+
3226
+
3227
+
3228
+
3229
+
3230
+
3231
+
3232
+
3233
+
3234
+
3235
+
3236
+
3237
+
3238
+
3239
+
3240
+
2576
3241
 
2577
3242
 
2578
3243
 
@@ -2681,6 +3346,15 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
2681
3346
 
2682
3347
 
2683
3348
 
3349
+ * @example
3350
+ * // Convert to array
3351
+ * const tm = new TreeMap<number, string>([[2, 'b'], [1, 'a']]);
3352
+ * console.log(tm.toArray()); // [[1, 'a'], [2, 'b']];
3353
+ */
3354
+ toArray(): Array<[K, V | undefined]>;
3355
+ /**
3356
+ * Print a human-friendly representation.
3357
+ * @remarks Time O(n), Space O(n)
2684
3358
 
2685
3359
 
2686
3360
 
@@ -2716,15 +3390,6 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
2716
3390
 
2717
3391
 
2718
3392
 
2719
- * @example
2720
- * // Convert to array
2721
- * const tm = new TreeMap<number, string>([[2, 'b'], [1, 'a']]);
2722
- * console.log(tm.toArray()); // [[1, 'a'], [2, 'b']];
2723
- */
2724
- toArray(): Array<[K, V | undefined]>;
2725
- /**
2726
- * Print a human-friendly representation.
2727
- * @remarks Time O(n), Space O(n)
2728
3393
 
2729
3394
 
2730
3395
 
@@ -2900,6 +3565,13 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
2900
3565
 
2901
3566
 
2902
3567
 
3568
+
3569
+
3570
+
3571
+
3572
+
3573
+
3574
+
2903
3575
 
2904
3576
 
2905
3577
 
@@ -2962,6 +3634,13 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
2962
3634
 
2963
3635
 
2964
3636
 
3637
+
3638
+
3639
+
3640
+
3641
+
3642
+
3643
+
2965
3644
 
2966
3645
 
2967
3646
 
@@ -3008,6 +3687,13 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
3008
3687
 
3009
3688
 
3010
3689
 
3690
+
3691
+
3692
+
3693
+
3694
+
3695
+
3696
+
3011
3697
 
3012
3698
 
3013
3699
 
@@ -3056,6 +3742,13 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
3056
3742
 
3057
3743
 
3058
3744
 
3745
+
3746
+
3747
+
3748
+
3749
+
3750
+
3751
+
3059
3752
 
3060
3753
 
3061
3754
 
@@ -3181,6 +3874,34 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
3181
3874
 
3182
3875
 
3183
3876
 
3877
+
3878
+
3879
+
3880
+
3881
+
3882
+
3883
+
3884
+
3885
+
3886
+
3887
+
3888
+
3889
+
3890
+
3891
+
3892
+
3893
+
3894
+
3895
+
3896
+
3897
+
3898
+
3899
+
3900
+
3901
+
3902
+
3903
+
3904
+
3184
3905
 
3185
3906
 
3186
3907
 
@@ -3338,6 +4059,34 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
3338
4059
 
3339
4060
 
3340
4061
 
4062
+
4063
+
4064
+
4065
+
4066
+
4067
+
4068
+
4069
+
4070
+
4071
+
4072
+
4073
+
4074
+
4075
+
4076
+
4077
+
4078
+
4079
+
4080
+
4081
+
4082
+
4083
+
4084
+
4085
+
4086
+
4087
+
4088
+
4089
+
3341
4090
 
3342
4091
 
3343
4092
 
@@ -3479,6 +4228,34 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
3479
4228
 
3480
4229
 
3481
4230
 
4231
+
4232
+
4233
+
4234
+
4235
+
4236
+
4237
+
4238
+
4239
+
4240
+
4241
+
4242
+
4243
+
4244
+
4245
+
4246
+
4247
+
4248
+
4249
+
4250
+
4251
+
4252
+
4253
+
4254
+
4255
+
4256
+
4257
+
4258
+
3482
4259
 
3483
4260
 
3484
4261
 
@@ -3620,6 +4397,34 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
3620
4397
 
3621
4398
 
3622
4399
 
4400
+
4401
+
4402
+
4403
+
4404
+
4405
+
4406
+
4407
+
4408
+
4409
+
4410
+
4411
+
4412
+
4413
+
4414
+
4415
+
4416
+
4417
+
4418
+
4419
+
4420
+
4421
+
4422
+
4423
+
4424
+
4425
+
4426
+
4427
+
3623
4428
 
3624
4429
 
3625
4430
 
@@ -3762,6 +4567,34 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
3762
4567
 
3763
4568
 
3764
4569
 
4570
+
4571
+
4572
+
4573
+
4574
+
4575
+
4576
+
4577
+
4578
+
4579
+
4580
+
4581
+
4582
+
4583
+
4584
+
4585
+
4586
+
4587
+
4588
+
4589
+
4590
+
4591
+
4592
+
4593
+
4594
+
4595
+
4596
+
4597
+
3765
4598
 
3766
4599
 
3767
4600
 
@@ -3815,6 +4648,66 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
3815
4648
  * console.log(totalValue); // toBeCloseTo;
3816
4649
  */
3817
4650
  rangeSearch(range: [K, K], options?: TreeMapRangeOptions): Array<[K, V | undefined]>;
4651
+ /**
4652
+ * Returns the entry at the k-th position in tree order (0-indexed).
4653
+ * @remarks Time O(log n). Requires `enableOrderStatistic: true`.
4654
+
4655
+
4656
+
4657
+ * @example
4658
+ * // Find k-th entry in a TreeMap
4659
+ * const map = new TreeMap<string, number>(
4660
+ * [['alice', 95], ['bob', 87], ['charlie', 92]],
4661
+ * { enableOrderStatistic: true }
4662
+ * );
4663
+ * console.log(map.getByRank(0)); // 'alice';
4664
+ * console.log(map.getByRank(1)); // 'bob';
4665
+ * console.log(map.getByRank(2)); // 'charlie';
4666
+ */
4667
+ getByRank(k: number): [K, V | undefined] | undefined;
4668
+ /**
4669
+ * Returns the 0-based rank of a key (number of elements that precede it in tree order).
4670
+ * @remarks Time O(log n). Requires `enableOrderStatistic: true`.
4671
+ * @example
4672
+ * // Get the rank of a key in sorted order
4673
+ * const tree = new TreeMap<number>(
4674
+ * [10, 20, 30, 40, 50],
4675
+ * { enableOrderStatistic: true }
4676
+ * );
4677
+ * console.log(tree.getRank(10)); // 0; // smallest → rank 0
4678
+ * console.log(tree.getRank(30)); // 2; // 2 elements before 30 in tree order
4679
+ * console.log(tree.getRank(50)); // 4; // largest → rank 4
4680
+ * console.log(tree.getRank(25)); // 2;
4681
+ */
4682
+ getRank(key: K): number;
4683
+ /**
4684
+ * Returns keys by rank range (0-indexed, inclusive on both ends).
4685
+ * @remarks Time O(log n + k). Requires `enableOrderStatistic: true`.
4686
+
4687
+
4688
+
4689
+
4690
+
4691
+
4692
+
4693
+
4694
+
4695
+ * @example
4696
+ * // Pagination by position in tree order
4697
+ * const tree = new TreeMap<number>(
4698
+ * [10, 20, 30, 40, 50, 60, 70, 80, 90],
4699
+ * { enableOrderStatistic: true }
4700
+ * );
4701
+ * const pageSize = 3;
4702
+ *
4703
+ * // Page 1
4704
+ * console.log(tree.rangeByRank(0, pageSize - 1)); // [10, 20, 30];
4705
+ * // Page 2
4706
+ * console.log(tree.rangeByRank(pageSize, 2 * pageSize - 1)); // [40, 50, 60];
4707
+ * // Page 3
4708
+ * console.log(tree.rangeByRank(2 * pageSize, 3 * pageSize - 1)); // [70, 80, 90];
4709
+ */
4710
+ rangeByRank(start: number, end: number): Array<[K, V | undefined]>;
3818
4711
  /**
3819
4712
  * Creates a shallow clone of this map.
3820
4713
  * @remarks Time O(n log n), Space O(n)
@@ -3941,6 +4834,41 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
3941
4834
 
3942
4835
 
3943
4836
 
4837
+
4838
+
4839
+
4840
+
4841
+
4842
+
4843
+
4844
+
4845
+
4846
+
4847
+
4848
+
4849
+
4850
+
4851
+
4852
+
4853
+
4854
+
4855
+
4856
+
4857
+
4858
+
4859
+
4860
+
4861
+
4862
+
4863
+
4864
+
4865
+
4866
+
4867
+
4868
+
4869
+
4870
+
4871
+
3944
4872
 
3945
4873
 
3946
4874