@ac-kit/algo 0.6.0 → 0.7.0

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 (156) hide show
  1. package/CHANGELOG.md +67 -0
  2. package/README.md +44 -15
  3. package/dist/combinatorics/cartesian-product.d.ts +46 -0
  4. package/dist/combinatorics/cartesian-product.d.ts.map +1 -0
  5. package/dist/combinatorics/cartesian-product.js +79 -0
  6. package/dist/combinatorics/cartesian-product.js.map +1 -0
  7. package/dist/combinatorics/permutations.d.ts +41 -0
  8. package/dist/combinatorics/permutations.d.ts.map +1 -0
  9. package/dist/combinatorics/permutations.js +70 -0
  10. package/dist/combinatorics/permutations.js.map +1 -0
  11. package/dist/combinatorics/power-set.d.ts +40 -0
  12. package/dist/combinatorics/power-set.d.ts.map +1 -0
  13. package/dist/combinatorics/power-set.js +67 -0
  14. package/dist/combinatorics/power-set.js.map +1 -0
  15. package/dist/graph/bfs.d.ts +66 -0
  16. package/dist/graph/bfs.d.ts.map +1 -0
  17. package/dist/graph/bfs.js +89 -0
  18. package/dist/graph/bfs.js.map +1 -0
  19. package/dist/graph/connected-components.d.ts +35 -0
  20. package/dist/graph/connected-components.d.ts.map +1 -0
  21. package/dist/graph/connected-components.js +75 -0
  22. package/dist/graph/connected-components.js.map +1 -0
  23. package/dist/graph/floyd-warshall.d.ts +67 -0
  24. package/dist/graph/floyd-warshall.d.ts.map +1 -0
  25. package/dist/graph/floyd-warshall.js +106 -0
  26. package/dist/graph/floyd-warshall.js.map +1 -0
  27. package/dist/graph/graph-cycle-error.d.ts +16 -0
  28. package/dist/graph/graph-cycle-error.d.ts.map +1 -0
  29. package/dist/graph/graph-cycle-error.js +20 -0
  30. package/dist/graph/graph-cycle-error.js.map +1 -0
  31. package/dist/graph/lowest-common-ancestor.d.ts +32 -0
  32. package/dist/graph/lowest-common-ancestor.d.ts.map +1 -0
  33. package/dist/graph/lowest-common-ancestor.js +56 -0
  34. package/dist/graph/lowest-common-ancestor.js.map +1 -0
  35. package/dist/graph/topological-sort.d.ts +51 -0
  36. package/dist/graph/topological-sort.d.ts.map +1 -0
  37. package/dist/graph/topological-sort.js +124 -0
  38. package/dist/graph/topological-sort.js.map +1 -0
  39. package/dist/group/_nest-by.d.ts +19 -0
  40. package/dist/group/_nest-by.d.ts.map +1 -0
  41. package/dist/group/_nest-by.js +85 -0
  42. package/dist/group/_nest-by.js.map +1 -0
  43. package/dist/group/count-by.d.ts +31 -0
  44. package/dist/group/count-by.d.ts.map +1 -0
  45. package/dist/group/count-by.js +35 -0
  46. package/dist/group/count-by.js.map +1 -0
  47. package/dist/group/flat-group-by.d.ts +28 -0
  48. package/dist/group/flat-group-by.d.ts.map +1 -0
  49. package/dist/group/flat-group-by.js +30 -0
  50. package/dist/group/flat-group-by.js.map +1 -0
  51. package/dist/group/group-adjacent-by.d.ts +31 -0
  52. package/dist/group/group-adjacent-by.d.ts.map +1 -0
  53. package/dist/group/group-adjacent-by.js +50 -0
  54. package/dist/group/group-adjacent-by.js.map +1 -0
  55. package/dist/group/group-sort.d.ts +38 -0
  56. package/dist/group/group-sort.d.ts.map +1 -0
  57. package/dist/group/group-sort.js +49 -0
  58. package/dist/group/group-sort.js.map +1 -0
  59. package/dist/group/index-by.d.ts +33 -0
  60. package/dist/group/index-by.d.ts.map +1 -0
  61. package/dist/group/index-by.js +42 -0
  62. package/dist/group/index-by.js.map +1 -0
  63. package/dist/group/nested-map.d.ts +12 -0
  64. package/dist/group/nested-map.d.ts.map +1 -0
  65. package/dist/group/nested-map.js +2 -0
  66. package/dist/group/nested-map.js.map +1 -0
  67. package/dist/group/rollup-by.d.ts +62 -0
  68. package/dist/group/rollup-by.d.ts.map +1 -0
  69. package/dist/group/rollup-by.js +72 -0
  70. package/dist/group/rollup-by.js.map +1 -0
  71. package/dist/group/run-length-encode.d.ts +41 -0
  72. package/dist/group/run-length-encode.d.ts.map +1 -0
  73. package/dist/group/run-length-encode.js +66 -0
  74. package/dist/group/run-length-encode.js.map +1 -0
  75. package/dist/index.d.ts +32 -1
  76. package/dist/index.d.ts.map +1 -1
  77. package/dist/index.js +32 -1
  78. package/dist/index.js.map +1 -1
  79. package/dist/ordered/is-sorted.d.ts +33 -0
  80. package/dist/ordered/is-sorted.d.ts.map +1 -0
  81. package/dist/ordered/is-sorted.js +39 -0
  82. package/dist/ordered/is-sorted.js.map +1 -0
  83. package/dist/sample/sample-without-replacement.d.ts +26 -0
  84. package/dist/sample/sample-without-replacement.d.ts.map +1 -0
  85. package/dist/sample/sample-without-replacement.js +41 -0
  86. package/dist/sample/sample-without-replacement.js.map +1 -0
  87. package/dist/sample/shuffle.d.ts +2 -2
  88. package/dist/sample/shuffle.d.ts.map +1 -1
  89. package/dist/sample/shuffle.js +3 -3
  90. package/dist/sample/shuffle.js.map +1 -1
  91. package/dist/sample/weighted-choice-index.d.ts +29 -0
  92. package/dist/sample/weighted-choice-index.d.ts.map +1 -0
  93. package/dist/sample/weighted-choice-index.js +62 -0
  94. package/dist/sample/weighted-choice-index.js.map +1 -0
  95. package/dist/sample/weighted-choice.d.ts +28 -0
  96. package/dist/sample/weighted-choice.d.ts.map +1 -0
  97. package/dist/sample/weighted-choice.js +31 -0
  98. package/dist/sample/weighted-choice.js.map +1 -0
  99. package/dist/select/minmax.d.ts +52 -0
  100. package/dist/select/minmax.d.ts.map +1 -0
  101. package/dist/select/minmax.js +109 -0
  102. package/dist/select/minmax.js.map +1 -0
  103. package/dist/select/{quickselect.d.ts → quickselect-in-place.d.ts} +2 -2
  104. package/dist/select/quickselect-in-place.d.ts.map +1 -0
  105. package/dist/select/{quickselect.js → quickselect-in-place.js} +2 -2
  106. package/dist/select/quickselect-in-place.js.map +1 -0
  107. package/dist/sequence/_matching-runs.d.ts +16 -0
  108. package/dist/sequence/_matching-runs.d.ts.map +1 -0
  109. package/dist/sequence/_matching-runs.js +178 -0
  110. package/dist/sequence/_matching-runs.js.map +1 -0
  111. package/dist/sequence/common-prefix-length.d.ts +26 -0
  112. package/dist/sequence/common-prefix-length.d.ts.map +1 -0
  113. package/dist/sequence/common-prefix-length.js +34 -0
  114. package/dist/sequence/common-prefix-length.js.map +1 -0
  115. package/dist/sequence/diff-sequences.d.ts +59 -0
  116. package/dist/sequence/diff-sequences.d.ts.map +1 -0
  117. package/dist/sequence/diff-sequences.js +67 -0
  118. package/dist/sequence/diff-sequences.js.map +1 -0
  119. package/dist/sequence/levenshtein-distance.d.ts +43 -0
  120. package/dist/sequence/levenshtein-distance.d.ts.map +1 -0
  121. package/dist/sequence/levenshtein-distance.js +102 -0
  122. package/dist/sequence/levenshtein-distance.js.map +1 -0
  123. package/dist/sequence/longest-common-subsequence.d.ts +28 -0
  124. package/dist/sequence/longest-common-subsequence.d.ts.map +1 -0
  125. package/dist/sequence/longest-common-subsequence.js +39 -0
  126. package/dist/sequence/longest-common-subsequence.js.map +1 -0
  127. package/dist/sequence/longest-increasing-subsequence.d.ts +28 -0
  128. package/dist/sequence/longest-increasing-subsequence.d.ts.map +1 -0
  129. package/dist/sequence/longest-increasing-subsequence.js +47 -0
  130. package/dist/sequence/longest-increasing-subsequence.js.map +1 -0
  131. package/dist/sort/_sort-primitives.d.ts +6 -0
  132. package/dist/sort/_sort-primitives.d.ts.map +1 -0
  133. package/dist/sort/_sort-primitives.js +18 -0
  134. package/dist/sort/_sort-primitives.js.map +1 -0
  135. package/dist/sort/counting-sort.d.ts +40 -0
  136. package/dist/sort/counting-sort.d.ts.map +1 -0
  137. package/dist/sort/counting-sort.js +51 -0
  138. package/dist/sort/counting-sort.js.map +1 -0
  139. package/dist/sort/merge-sort.d.ts +26 -0
  140. package/dist/sort/merge-sort.d.ts.map +1 -0
  141. package/dist/sort/merge-sort.js +73 -0
  142. package/dist/sort/merge-sort.js.map +1 -0
  143. package/dist/sort/quick-sort-in-place.d.ts +35 -0
  144. package/dist/sort/quick-sort-in-place.d.ts.map +1 -0
  145. package/dist/sort/quick-sort-in-place.js +98 -0
  146. package/dist/sort/quick-sort-in-place.js.map +1 -0
  147. package/dist/sort/rank.d.ts +64 -0
  148. package/dist/sort/rank.d.ts.map +1 -0
  149. package/dist/sort/rank.js +107 -0
  150. package/dist/sort/rank.js.map +1 -0
  151. package/dist/sort/sort-range.d.ts.map +1 -1
  152. package/dist/sort/sort-range.js +1 -16
  153. package/dist/sort/sort-range.js.map +1 -1
  154. package/package.json +6 -6
  155. package/dist/select/quickselect.d.ts.map +0 -1
  156. package/dist/select/quickselect.js.map +0 -1
@@ -0,0 +1,42 @@
1
+ import { assertSameValueZero_, nestBy_ } from "./_nest-by.js";
2
+ /**
3
+ * Indexes the items of an iterable by their keys, one nested `Map` level per
4
+ * accessor, with the single item holding each key tuple at the innermost level
5
+ * — `groupBy` for keys that are unique, such as ids, which throws instead of
6
+ * silently keeping one of two items that share a key (d3's `index`).
7
+ *
8
+ * Keys appear in the order they first occur.
9
+ *
10
+ * Time complexity: O(n · k) for `k` accessors under the default
11
+ * `"sameValueZero"`. Memory: O(n).
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const byId = indexBy(users, [(user) => user.id]);
16
+ * byId.get(42); // the user with id 42
17
+ * ```;
18
+ *
19
+ * @param iterable - The input iterable.
20
+ * @param keysOf - One or more functions taking an item and returning a key,
21
+ * outermost level first; an array, so a trailing `comparisonStrategy` is not
22
+ * mistaken for one more accessor.
23
+ * @param comparisonStrategy - How keys are compared. Only `"sameValueZero"` is
24
+ * supported, since the index is kept in a `Map`.
25
+ * @returns Nested maps from each key to its item.
26
+ * @throws {RangeError} When two items have the same keys; the message names the
27
+ * position of the second.
28
+ * @throws {UnimplementedError} If `comparisonStrategy` is not
29
+ * `"sameValueZero"`.
30
+ */
31
+ export function indexBy(iterable, keysOf, comparisonStrategy = "sameValueZero") {
32
+ assertSameValueZero_(comparisonStrategy);
33
+ let position = 0;
34
+ return nestBy_(iterable, keysOf, (items, key, item) => {
35
+ if (items.has(key)) {
36
+ throw new RangeError(`indexBy: the item at position ${position} has the keys of an earlier one`);
37
+ }
38
+ items.set(key, item);
39
+ position++;
40
+ });
41
+ }
42
+ //# sourceMappingURL=index-by.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-by.js","sourceRoot":"","sources":["../../src/group/index-by.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAG9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,OAAO,CACtB,QAAqB,EACrB,MAA6B,EAC7B,kBAAkB,GAGd,eAAe;IAEnB,oBAAoB,CAAC,kBAAkB,CAAC,CAAC;IACzC,IAAI,QAAQ,GAAG,CAAC,CAAC;IACjB,OAAO,OAAO,CAAO,QAAQ,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QAC3D,IAAI,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACpB,MAAM,IAAI,UAAU,CACnB,iCAAiC,QAAQ,iCAAiC,CAC1E,CAAC;QACH,CAAC;QACD,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QACrB,QAAQ,EAAE,CAAC;IACZ,CAAC,CAAuB,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { Callable } from "@ac-kit/core";
2
+ /**
3
+ * Nested `Map`s, one level per key in `Keys` (outermost first), with `TLeaf`
4
+ * values at the innermost level: what `countBy`, `rollupBy` and `indexBy`
5
+ * return, as `groupBy` returns `GroupedBy`.
6
+ */
7
+ export type NestedMap<Keys extends readonly unknown[], TLeaf> = Keys extends readonly [infer Head, ...infer Tail] ? Tail extends readonly [] ? Map<Head, TLeaf> : Map<Head, NestedMap<Tail, TLeaf>> : never;
8
+ /** One key accessor per nesting level, typed by the tuple of keys returned. */
9
+ export type KeyAccessors<T, Keys extends readonly unknown[]> = {
10
+ [I in keyof Keys]: Callable<[T], Keys[I]>;
11
+ };
12
+ //# sourceMappingURL=nested-map.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nested-map.d.ts","sourceRoot":"","sources":["../../src/group/nested-map.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE7C;;;;GAIG;AACH,MAAM,MAAM,SAAS,CACpB,IAAI,SAAS,SAAS,OAAO,EAAE,EAC/B,KAAK,IACF,IAAI,SAAS,SAAS,CAAC,MAAM,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,GAClD,IAAI,SAAS,SAAS,EAAE,GACvB,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,GAChB,GAAG,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,GAClC,KAAK,CAAC;AAET,+EAA+E;AAC/E,MAAM,MAAM,YAAY,CAAC,CAAC,EAAE,IAAI,SAAS,SAAS,OAAO,EAAE,IAAI;KAC7D,CAAC,IAAI,MAAM,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;CACzC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=nested-map.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nested-map.js","sourceRoot":"","sources":["../../src/group/nested-map.ts"],"names":[],"mappings":""}
@@ -0,0 +1,62 @@
1
+ import type { Callable, EqualityComparisonStrategy } from "@ac-kit/core";
2
+ import type { KeyAccessors, NestedMap } from "./nested-map.js";
3
+ /**
4
+ * Groups the items of an iterable by their keys, one nested `Map` level per
5
+ * accessor, and reduces each group to one value — SQL's `GROUP BY` with an
6
+ * aggregate, d3's `rollup`. `groupBy` is `rollupBy` with the identity
7
+ * reduction.
8
+ *
9
+ * Keys appear in the order they first occur; `reduce` is called once per group,
10
+ * with its items in input order, once every item has been read.
11
+ *
12
+ * Time complexity: O(n · k) for `k` accessors under the default
13
+ * `"sameValueZero"`, plus the reductions. Memory: O(n) for the groups.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * rollupBy(sales, [(sale) => sale.region], (group) => group.length);
18
+ * // Map { "north" → 12, "south" → 7 }
19
+ * ```;
20
+ *
21
+ * @param iterable - The input iterable.
22
+ * @param keysOf - One or more functions taking an item and returning a key,
23
+ * outermost level first; an array, so a trailing `comparisonStrategy` is not
24
+ * mistaken for one more accessor.
25
+ * @param reduce - Reduces one group to its value.
26
+ * @param comparisonStrategy - How keys are compared. Only `"sameValueZero"` is
27
+ * supported, since the groups are kept in a `Map`.
28
+ * @returns Nested maps from each key to its group's reduced value.
29
+ * @throws {UnimplementedError} If `comparisonStrategy` is not
30
+ * `"sameValueZero"`.
31
+ */
32
+ export declare function rollupBy<T, TResult, const Keys extends readonly [unknown, ...unknown[]]>(iterable: Iterable<T>, keysOf: KeyAccessors<T, Keys>, reduce: Callable<[group: T[]], TResult>, comparisonStrategy?: EqualityComparisonStrategy<Keys[number], Keys[number]>): NestedMap<Keys, TResult>;
33
+ /**
34
+ * {@link rollupBy} flattened into one row per key tuple, `[key₁, …, keyₖ,
35
+ * value]`, in the order the key tuples first occur — d3's `flatRollup`, the
36
+ * shape a table or a chart's data layer takes.
37
+ *
38
+ * Time complexity: O(n · k) for `k` accessors under the default
39
+ * `"sameValueZero"`, plus the reductions. Memory: O(n).
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * flatRollupBy(
44
+ * sales,
45
+ * [(sale) => sale.region, (sale) => sale.year],
46
+ * (group) => group.length,
47
+ * );
48
+ * // [["north", 2025, 5], ["north", 2026, 7], ["south", 2026, 7]]
49
+ * ```;
50
+ *
51
+ * @param iterable - The input iterable.
52
+ * @param keysOf - One or more functions taking an item and returning a key,
53
+ * outermost first.
54
+ * @param reduce - Reduces one group to its value.
55
+ * @param comparisonStrategy - How keys are compared. Only `"sameValueZero"` is
56
+ * supported.
57
+ * @returns One row per key tuple: its keys, then its group's reduced value.
58
+ * @throws {UnimplementedError} If `comparisonStrategy` is not
59
+ * `"sameValueZero"`.
60
+ */
61
+ export declare function flatRollupBy<T, TResult, const Keys extends readonly [unknown, ...unknown[]]>(iterable: Iterable<T>, keysOf: KeyAccessors<T, Keys>, reduce: Callable<[group: T[]], TResult>, comparisonStrategy?: EqualityComparisonStrategy<Keys[number], Keys[number]>): [...Keys, TResult][];
62
+ //# sourceMappingURL=rollup-by.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rollup-by.d.ts","sourceRoot":"","sources":["../../src/group/rollup-by.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AASzE,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAY/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,QAAQ,CACvB,CAAC,EACD,OAAO,EACP,KAAK,CAAC,IAAI,SAAS,SAAS,CAAC,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC,EAEnD,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EACrB,MAAM,EAAE,YAAY,CAAC,CAAC,EAAE,IAAI,CAAC,EAC7B,MAAM,EAAE,QAAQ,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,EACvC,kBAAkB,GAAE,0BAA0B,CAC7C,IAAI,CAAC,MAAM,CAAC,EACZ,IAAI,CAAC,MAAM,CAAC,CACM,GACjB,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,CAG1B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,YAAY,CAC3B,CAAC,EACD,OAAO,EACP,KAAK,CAAC,IAAI,SAAS,SAAS,CAAC,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC,EAEnD,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EACrB,MAAM,EAAE,YAAY,CAAC,CAAC,EAAE,IAAI,CAAC,EAC7B,MAAM,EAAE,QAAQ,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,EACvC,kBAAkB,GAAE,0BAA0B,CAC7C,IAAI,CAAC,MAAM,CAAC,EACZ,IAAI,CAAC,MAAM,CAAC,CACM,GACjB,CAAC,GAAG,IAAI,EAAE,OAAO,CAAC,EAAE,CAMtB"}
@@ -0,0 +1,72 @@
1
+ import { assertSameValueZero_, flattenNested_, groupInto_, mapLeaves_, nestBy_, } from "./_nest-by.js";
2
+ function rollUp_(iterable, keysOf, reduce) {
3
+ const nested = nestBy_(iterable, keysOf, groupInto_);
4
+ mapLeaves_(nested, keysOf.length, reduce);
5
+ return nested;
6
+ }
7
+ /**
8
+ * Groups the items of an iterable by their keys, one nested `Map` level per
9
+ * accessor, and reduces each group to one value — SQL's `GROUP BY` with an
10
+ * aggregate, d3's `rollup`. `groupBy` is `rollupBy` with the identity
11
+ * reduction.
12
+ *
13
+ * Keys appear in the order they first occur; `reduce` is called once per group,
14
+ * with its items in input order, once every item has been read.
15
+ *
16
+ * Time complexity: O(n · k) for `k` accessors under the default
17
+ * `"sameValueZero"`, plus the reductions. Memory: O(n) for the groups.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * rollupBy(sales, [(sale) => sale.region], (group) => group.length);
22
+ * // Map { "north" → 12, "south" → 7 }
23
+ * ```;
24
+ *
25
+ * @param iterable - The input iterable.
26
+ * @param keysOf - One or more functions taking an item and returning a key,
27
+ * outermost level first; an array, so a trailing `comparisonStrategy` is not
28
+ * mistaken for one more accessor.
29
+ * @param reduce - Reduces one group to its value.
30
+ * @param comparisonStrategy - How keys are compared. Only `"sameValueZero"` is
31
+ * supported, since the groups are kept in a `Map`.
32
+ * @returns Nested maps from each key to its group's reduced value.
33
+ * @throws {UnimplementedError} If `comparisonStrategy` is not
34
+ * `"sameValueZero"`.
35
+ */
36
+ export function rollupBy(iterable, keysOf, reduce, comparisonStrategy = "sameValueZero") {
37
+ assertSameValueZero_(comparisonStrategy);
38
+ return rollUp_(iterable, keysOf, reduce);
39
+ }
40
+ /**
41
+ * {@link rollupBy} flattened into one row per key tuple, `[key₁, …, keyₖ,
42
+ * value]`, in the order the key tuples first occur — d3's `flatRollup`, the
43
+ * shape a table or a chart's data layer takes.
44
+ *
45
+ * Time complexity: O(n · k) for `k` accessors under the default
46
+ * `"sameValueZero"`, plus the reductions. Memory: O(n).
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * flatRollupBy(
51
+ * sales,
52
+ * [(sale) => sale.region, (sale) => sale.year],
53
+ * (group) => group.length,
54
+ * );
55
+ * // [["north", 2025, 5], ["north", 2026, 7], ["south", 2026, 7]]
56
+ * ```;
57
+ *
58
+ * @param iterable - The input iterable.
59
+ * @param keysOf - One or more functions taking an item and returning a key,
60
+ * outermost first.
61
+ * @param reduce - Reduces one group to its value.
62
+ * @param comparisonStrategy - How keys are compared. Only `"sameValueZero"` is
63
+ * supported.
64
+ * @returns One row per key tuple: its keys, then its group's reduced value.
65
+ * @throws {UnimplementedError} If `comparisonStrategy` is not
66
+ * `"sameValueZero"`.
67
+ */
68
+ export function flatRollupBy(iterable, keysOf, reduce, comparisonStrategy = "sameValueZero") {
69
+ assertSameValueZero_(comparisonStrategy);
70
+ return flattenNested_(rollUp_(iterable, keysOf, reduce), keysOf.length);
71
+ }
72
+ //# sourceMappingURL=rollup-by.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rollup-by.js","sourceRoot":"","sources":["../../src/group/rollup-by.ts"],"names":[],"mappings":"AAEA,OAAO,EACN,oBAAoB,EACpB,cAAc,EACd,UAAU,EACV,UAAU,EACV,OAAO,GACP,MAAM,eAAe,CAAC;AAGvB,SAAS,OAAO,CACf,QAAqB,EACrB,MAAyC,EACzC,MAAuC;IAEvC,MAAM,MAAM,GAAG,OAAO,CAAS,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;IAC7D,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,OAAO,MAAM,CAAC;AACf,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,QAAQ,CAKvB,QAAqB,EACrB,MAA6B,EAC7B,MAAuC,EACvC,kBAAkB,GAGd,eAAe;IAEnB,oBAAoB,CAAC,kBAAkB,CAAC,CAAC;IACzC,OAAO,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAA6B,CAAC;AACtE,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,YAAY,CAK3B,QAAqB,EACrB,MAA6B,EAC7B,MAAuC,EACvC,kBAAkB,GAGd,eAAe;IAEnB,oBAAoB,CAAC,kBAAkB,CAAC,CAAC;IACzC,OAAO,cAAc,CAAC,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,CAGnE,CAAC;AACL,CAAC"}
@@ -0,0 +1,41 @@
1
+ import { type EqualityComparisonStrategy } from "@ac-kit/core";
2
+ /**
3
+ * Collapses consecutive equal values into `[value, count]` runs, lazily —
4
+ * run-length encoding, the counting form of `groupAdjacentBy`: `a a a b a`
5
+ * gives `[a, 3], [b, 1], [a, 1]`. The inverse is {@link runLengthDecode}.
6
+ *
7
+ * Each run is yielded once the first value of the next has been read (or the
8
+ * input ends), with the first value of the run.
9
+ *
10
+ * Time complexity: O(n), one comparison per value after the first. Memory:
11
+ * O(1).
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * [...runLengthEncode("aaab")]; // [["a", 3], ["b", 1]]
16
+ * ```;
17
+ *
18
+ * @param iterable - The values, read once as the runs are pulled.
19
+ * @param comparisonStrategy - How each value is compared with the first value
20
+ * of the current run. Default `"sameValueZero"`, so `NaN` runs collapse.
21
+ * @returns The runs, in order, each as `[value, count]` with `count ≥ 1`.
22
+ */
23
+ export declare function runLengthEncode<T>(iterable: Iterable<T>, comparisonStrategy?: EqualityComparisonStrategy<T, T>): Generator<[value: T, count: number], void, undefined>;
24
+ /**
25
+ * Expands `[value, count]` runs back into the values they stand for, lazily —
26
+ * the inverse of {@link runLengthEncode}. A run of count `0` yields nothing.
27
+ *
28
+ * Time complexity: O(n + r) for `n` values out and `r` runs in. Memory: O(1).
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * [...runLengthDecode([["a", 3], ["b", 1]])]; // ["a", "a", "a", "b"]
33
+ * ```;
34
+ *
35
+ * @param runs - The runs, read once as the values are pulled.
36
+ * @returns Each run's value, `count` times, run after run.
37
+ * @throws {RangeError} When a count is not a non-negative safe integer, as the
38
+ * run is reached.
39
+ */
40
+ export declare function runLengthDecode<T>(runs: Iterable<readonly [value: T, count: number]>): Generator<T, void, undefined>;
41
+ //# sourceMappingURL=run-length-encode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-length-encode.d.ts","sourceRoot":"","sources":["../../src/group/run-length-encode.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,KAAK,0BAA0B,EAC/B,MAAM,cAAc,CAAC;AAEtB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAiB,eAAe,CAAC,CAAC,EACjC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EACrB,kBAAkB,GAAE,0BAA0B,CAAC,CAAC,EAAE,CAAC,CAAmB,GACpE,SAAS,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,CAkBvD;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAiB,eAAe,CAAC,CAAC,EACjC,IAAI,EAAE,QAAQ,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,GAChD,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,CAO/B"}
@@ -0,0 +1,66 @@
1
+ import { assertInteger, resolveEqualityComparator, } from "@ac-kit/core";
2
+ /**
3
+ * Collapses consecutive equal values into `[value, count]` runs, lazily —
4
+ * run-length encoding, the counting form of `groupAdjacentBy`: `a a a b a`
5
+ * gives `[a, 3], [b, 1], [a, 1]`. The inverse is {@link runLengthDecode}.
6
+ *
7
+ * Each run is yielded once the first value of the next has been read (or the
8
+ * input ends), with the first value of the run.
9
+ *
10
+ * Time complexity: O(n), one comparison per value after the first. Memory:
11
+ * O(1).
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * [...runLengthEncode("aaab")]; // [["a", 3], ["b", 1]]
16
+ * ```;
17
+ *
18
+ * @param iterable - The values, read once as the runs are pulled.
19
+ * @param comparisonStrategy - How each value is compared with the first value
20
+ * of the current run. Default `"sameValueZero"`, so `NaN` runs collapse.
21
+ * @returns The runs, in order, each as `[value, count]` with `count ≥ 1`.
22
+ */
23
+ export function* runLengthEncode(iterable, comparisonStrategy = "sameValueZero") {
24
+ const equals = resolveEqualityComparator(comparisonStrategy);
25
+ let value;
26
+ let count = 0;
27
+ for (const item of iterable) {
28
+ if (count > 0 && equals(value, item)) {
29
+ count++;
30
+ continue;
31
+ }
32
+ if (count > 0) {
33
+ yield [value, count];
34
+ }
35
+ value = item;
36
+ count = 1;
37
+ }
38
+ if (count > 0) {
39
+ yield [value, count];
40
+ }
41
+ }
42
+ /**
43
+ * Expands `[value, count]` runs back into the values they stand for, lazily —
44
+ * the inverse of {@link runLengthEncode}. A run of count `0` yields nothing.
45
+ *
46
+ * Time complexity: O(n + r) for `n` values out and `r` runs in. Memory: O(1).
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * [...runLengthDecode([["a", 3], ["b", 1]])]; // ["a", "a", "a", "b"]
51
+ * ```;
52
+ *
53
+ * @param runs - The runs, read once as the values are pulled.
54
+ * @returns Each run's value, `count` times, run after run.
55
+ * @throws {RangeError} When a count is not a non-negative safe integer, as the
56
+ * run is reached.
57
+ */
58
+ export function* runLengthDecode(runs) {
59
+ for (const [value, count] of runs) {
60
+ assertInteger(count, "runLengthDecode: a run's count", 0);
61
+ for (let index = 0; index < count; index++) {
62
+ yield value;
63
+ }
64
+ }
65
+ }
66
+ //# sourceMappingURL=run-length-encode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-length-encode.js","sourceRoot":"","sources":["../../src/group/run-length-encode.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,aAAa,EACb,yBAAyB,GAEzB,MAAM,cAAc,CAAC;AAEtB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,SAAS,CAAC,CAAC,eAAe,CAC/B,QAAqB,EACrB,kBAAkB,GAAqC,eAAe;IAEtE,MAAM,MAAM,GAAG,yBAAyB,CAAC,kBAAkB,CAAC,CAAC;IAC7D,IAAI,KAAQ,CAAC;IACb,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;QAC7B,IAAI,KAAK,GAAG,CAAC,IAAI,MAAM,CAAC,KAAM,EAAE,IAAI,CAAC,EAAE,CAAC;YACvC,KAAK,EAAE,CAAC;YACR,SAAS;QACV,CAAC;QACD,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;YACf,MAAM,CAAC,KAAM,EAAE,KAAK,CAAC,CAAC;QACvB,CAAC;QACD,KAAK,GAAG,IAAI,CAAC;QACb,KAAK,GAAG,CAAC,CAAC;IACX,CAAC;IACD,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACf,MAAM,CAAC,KAAM,EAAE,KAAK,CAAC,CAAC;IACvB,CAAC;AACF,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,SAAS,CAAC,CAAC,eAAe,CAC/B,IAAkD;IAElD,KAAK,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC;QACnC,aAAa,CAAC,KAAK,EAAE,gCAAgC,EAAE,CAAC,CAAC,CAAC;QAC1D,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC;YAC5C,MAAM,KAAK,CAAC;QACb,CAAC;IACF,CAAC;AACF,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,16 +1,33 @@
1
+ export * from "./combinatorics/cartesian-product.js";
1
2
  export * from "./combinatorics/combinations.js";
3
+ export * from "./combinatorics/permutations.js";
4
+ export * from "./combinatorics/power-set.js";
2
5
  export * from "./distribute/spread-evenly.js";
3
6
  export * from "./graph/a-star.js";
4
7
  export * from "./graph/best-first-search.js";
8
+ export * from "./graph/bfs.js";
5
9
  export * from "./graph/children-of.js";
10
+ export * from "./graph/connected-components.js";
6
11
  export * from "./graph/dfs.js";
7
12
  export * from "./graph/find-cycle.js";
13
+ export * from "./graph/floyd-warshall.js";
14
+ export * from "./graph/graph-cycle-error.js";
8
15
  export * from "./graph/hierarchy-from-parents.js";
16
+ export * from "./graph/lowest-common-ancestor.js";
17
+ export * from "./graph/topological-sort.js";
9
18
  export * from "./graph/walk-tree.js";
19
+ export * from "./group/count-by.js";
20
+ export * from "./group/flat-group-by.js";
21
+ export * from "./group/group-adjacent-by.js";
10
22
  export * from "./group/group-by.js";
11
23
  export * from "./group/group-indices.js";
24
+ export * from "./group/group-sort.js";
25
+ export * from "./group/index-by.js";
26
+ export * from "./group/nested-map.js";
12
27
  export * from "./group/partition-indices.js";
13
28
  export * from "./group/partition.js";
29
+ export * from "./group/rollup-by.js";
30
+ export * from "./group/run-length-encode.js";
14
31
  export * from "./interval/complement-intervals.js";
15
32
  export * from "./interval/intersect-intervals.js";
16
33
  export * from "./interval/interval-step.js";
@@ -31,14 +48,24 @@ export * from "./ordered/create-bisector.js";
31
48
  export * from "./ordered/fractional-key-alphabet.js";
32
49
  export * from "./ordered/fractional-key-error.js";
33
50
  export * from "./ordered/fractional-key.js";
51
+ export * from "./ordered/is-sorted.js";
34
52
  export * from "./recursion/run-trampoline.js";
35
53
  export * from "./sample/choice.js";
54
+ export * from "./sample/sample-without-replacement.js";
36
55
  export * from "./sample/shuffle.js";
56
+ export * from "./sample/weighted-choice-index.js";
57
+ export * from "./sample/weighted-choice.js";
37
58
  export * from "./select/max-by.js";
38
59
  export * from "./select/min-by.js";
39
- export * from "./select/quickselect.js";
60
+ export * from "./select/minmax.js";
61
+ export * from "./select/quickselect-in-place.js";
40
62
  export * from "./select/select-at.js";
41
63
  export * from "./select/unique-min-by.js";
64
+ export * from "./sequence/common-prefix-length.js";
65
+ export * from "./sequence/diff-sequences.js";
66
+ export * from "./sequence/levenshtein-distance.js";
67
+ export * from "./sequence/longest-common-subsequence.js";
68
+ export * from "./sequence/longest-increasing-subsequence.js";
42
69
  export * from "./set/difference.js";
43
70
  export * from "./set/duplicates-by.js";
44
71
  export * from "./set/intersection.js";
@@ -50,8 +77,12 @@ export * from "./set/symmetric-difference.js";
50
77
  export * from "./set/union.js";
51
78
  export * from "./set/uniq-by.js";
52
79
  export * from "./set/uniq.js";
80
+ export * from "./sort/counting-sort.js";
81
+ export * from "./sort/merge-sort.js";
82
+ export * from "./sort/quick-sort-in-place.js";
53
83
  export * from "./sort/radix-index-sorter.js";
54
84
  export * from "./sort/radix-sort.js";
85
+ export * from "./sort/rank.js";
55
86
  export * from "./sort/sort-range.js";
56
87
  export * from "./sort/sorted-indices.js";
57
88
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC;AAChD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,mBAAmB,CAAC;AAClC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,mCAAmC,CAAC;AAClD,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sBAAsB,CAAC;AACr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Ac,8BAA8B,CAAC;AAC7C,cAAc,sCAAsC,CAAC;AACrD,cAAc,mCAAmC,CAAC;AAClD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wBAAwB,CAAC;AACvC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,oBAAoB,CAAC;AACnC,cAAc,wCAAwC,CAAC;AACvD,cAAc,qBAAqB,CAAC;AACpC,cAAc,mCAAmC,CAAC;AAClD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kCAAkC,CAAC;AACjD,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oCAAoC,CAAC;AACnD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oCAAoC,CAAC;AACnD,cAAc,0CAA0C,CAAC;AACzD,cAAc,8CAA8C,CAAC;AAC7D,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC"}
package/dist/index.js CHANGED
@@ -1,16 +1,33 @@
1
+ export * from "./combinatorics/cartesian-product.js";
1
2
  export * from "./combinatorics/combinations.js";
3
+ export * from "./combinatorics/permutations.js";
4
+ export * from "./combinatorics/power-set.js";
2
5
  export * from "./distribute/spread-evenly.js";
3
6
  export * from "./graph/a-star.js";
4
7
  export * from "./graph/best-first-search.js";
8
+ export * from "./graph/bfs.js";
5
9
  export * from "./graph/children-of.js";
10
+ export * from "./graph/connected-components.js";
6
11
  export * from "./graph/dfs.js";
7
12
  export * from "./graph/find-cycle.js";
13
+ export * from "./graph/floyd-warshall.js";
14
+ export * from "./graph/graph-cycle-error.js";
8
15
  export * from "./graph/hierarchy-from-parents.js";
16
+ export * from "./graph/lowest-common-ancestor.js";
17
+ export * from "./graph/topological-sort.js";
9
18
  export * from "./graph/walk-tree.js";
19
+ export * from "./group/count-by.js";
20
+ export * from "./group/flat-group-by.js";
21
+ export * from "./group/group-adjacent-by.js";
10
22
  export * from "./group/group-by.js";
11
23
  export * from "./group/group-indices.js";
24
+ export * from "./group/group-sort.js";
25
+ export * from "./group/index-by.js";
26
+ export * from "./group/nested-map.js";
12
27
  export * from "./group/partition-indices.js";
13
28
  export * from "./group/partition.js";
29
+ export * from "./group/rollup-by.js";
30
+ export * from "./group/run-length-encode.js";
14
31
  export * from "./interval/complement-intervals.js";
15
32
  export * from "./interval/intersect-intervals.js";
16
33
  export * from "./interval/interval-step.js";
@@ -31,14 +48,24 @@ export * from "./ordered/create-bisector.js";
31
48
  export * from "./ordered/fractional-key-alphabet.js";
32
49
  export * from "./ordered/fractional-key-error.js";
33
50
  export * from "./ordered/fractional-key.js";
51
+ export * from "./ordered/is-sorted.js";
34
52
  export * from "./recursion/run-trampoline.js";
35
53
  export * from "./sample/choice.js";
54
+ export * from "./sample/sample-without-replacement.js";
36
55
  export * from "./sample/shuffle.js";
56
+ export * from "./sample/weighted-choice-index.js";
57
+ export * from "./sample/weighted-choice.js";
37
58
  export * from "./select/max-by.js";
38
59
  export * from "./select/min-by.js";
39
- export * from "./select/quickselect.js";
60
+ export * from "./select/minmax.js";
61
+ export * from "./select/quickselect-in-place.js";
40
62
  export * from "./select/select-at.js";
41
63
  export * from "./select/unique-min-by.js";
64
+ export * from "./sequence/common-prefix-length.js";
65
+ export * from "./sequence/diff-sequences.js";
66
+ export * from "./sequence/levenshtein-distance.js";
67
+ export * from "./sequence/longest-common-subsequence.js";
68
+ export * from "./sequence/longest-increasing-subsequence.js";
42
69
  export * from "./set/difference.js";
43
70
  export * from "./set/duplicates-by.js";
44
71
  export * from "./set/intersection.js";
@@ -50,8 +77,12 @@ export * from "./set/symmetric-difference.js";
50
77
  export * from "./set/union.js";
51
78
  export * from "./set/uniq-by.js";
52
79
  export * from "./set/uniq.js";
80
+ export * from "./sort/counting-sort.js";
81
+ export * from "./sort/merge-sort.js";
82
+ export * from "./sort/quick-sort-in-place.js";
53
83
  export * from "./sort/radix-index-sorter.js";
54
84
  export * from "./sort/radix-sort.js";
85
+ export * from "./sort/rank.js";
55
86
  export * from "./sort/sort-range.js";
56
87
  export * from "./sort/sorted-indices.js";
57
88
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC;AAChD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,mBAAmB,CAAC;AAClC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,mCAAmC,CAAC;AAClD,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sBAAsB,CAAC;AACrC,cAAc,oCAAoC,CAAC;AACnD,cAAc,mCAAmC,CAAC;AAClD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sCAAsC,CAAC;AACrD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kCAAkC,CAAC;AACjD,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AA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c,qBAAqB,CAAC;AACpC,cAAc,mCAAmC,CAAC;AAClD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kCAAkC,CAAC;AACjD,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oCAAoC,CAAC;AACnD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oCAAoC,CAAC;AACnD,cAAc,0CAA0C,CAAC;AACzD,cAAc,8CAA8C,CAAC;AAC7D,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC"}
@@ -0,0 +1,33 @@
1
+ import type { Comparator } from "@ac-kit/core";
2
+ export type IsSortedOptions = {
3
+ /**
4
+ * Also reject two neighbours `compare` finds equivalent, so the items must be
5
+ * strictly increasing — the precondition of a sorted set rather than of a
6
+ * sorted list. Default `false`.
7
+ */
8
+ strict?: boolean;
9
+ };
10
+ /**
11
+ * Whether `items` are in non-decreasing order under `compare` — the
12
+ * precondition `bisect`, `isInSortedIntervals` and every other search over a
13
+ * sorted collection assumes and none of them checks, for an assertion at a
14
+ * trust boundary or a test.
15
+ *
16
+ * Compares each item with the one before it and stops at the first pair out of
17
+ * order, so it reads an iterable once and never sorts or copies it.
18
+ *
19
+ * Time complexity: O(n), at most `n − 1` calls to `compare`. Memory: O(1).
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * isSorted([1, 2, 2, 3], compareNaturalAscending); // true
24
+ * isSorted([1, 2, 2, 3], compareNaturalAscending, { strict: true }); // false
25
+ * ```;
26
+ *
27
+ * @param items - The items, in order; an empty or one-item input is sorted.
28
+ * @param compare - The ordering the items should follow.
29
+ * @param options - Whether equivalent neighbours are allowed.
30
+ * @returns `true` when no item is ordered before the one preceding it.
31
+ */
32
+ export declare function isSorted<T>(items: Iterable<T>, compare: Comparator<T>, options?: IsSortedOptions): boolean;
33
+ //# sourceMappingURL=is-sorted.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-sorted.d.ts","sourceRoot":"","sources":["../../src/ordered/is-sorted.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,MAAM,MAAM,eAAe,GAAG;IAC7B;;;;OAIG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EACzB,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,EAClB,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,EACtB,OAAO,GAAE,eAAoB,GAC3B,OAAO,CAeT"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Whether `items` are in non-decreasing order under `compare` — the
3
+ * precondition `bisect`, `isInSortedIntervals` and every other search over a
4
+ * sorted collection assumes and none of them checks, for an assertion at a
5
+ * trust boundary or a test.
6
+ *
7
+ * Compares each item with the one before it and stops at the first pair out of
8
+ * order, so it reads an iterable once and never sorts or copies it.
9
+ *
10
+ * Time complexity: O(n), at most `n − 1` calls to `compare`. Memory: O(1).
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * isSorted([1, 2, 2, 3], compareNaturalAscending); // true
15
+ * isSorted([1, 2, 2, 3], compareNaturalAscending, { strict: true }); // false
16
+ * ```;
17
+ *
18
+ * @param items - The items, in order; an empty or one-item input is sorted.
19
+ * @param compare - The ordering the items should follow.
20
+ * @param options - Whether equivalent neighbours are allowed.
21
+ * @returns `true` when no item is ordered before the one preceding it.
22
+ */
23
+ export function isSorted(items, compare, options = {}) {
24
+ const strict = options.strict ?? false;
25
+ let previous;
26
+ let hasPrevious = false;
27
+ for (const item of items) {
28
+ if (hasPrevious) {
29
+ const order = compare(previous, item);
30
+ if (order > 0 || (strict && order === 0)) {
31
+ return false;
32
+ }
33
+ }
34
+ previous = item;
35
+ hasPrevious = true;
36
+ }
37
+ return true;
38
+ }
39
+ //# sourceMappingURL=is-sorted.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-sorted.js","sourceRoot":"","sources":["../../src/ordered/is-sorted.ts"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,QAAQ,CACvB,KAAkB,EAClB,OAAsB,EACtB,OAAO,GAAoB,EAAE;IAE7B,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,KAAK,CAAC;IACvC,IAAI,QAAW,CAAC;IAChB,IAAI,WAAW,GAAG,KAAK,CAAC;IACxB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAC1B,IAAI,WAAW,EAAE,CAAC;YACjB,MAAM,KAAK,GAAG,OAAO,CAAC,QAAS,EAAE,IAAI,CAAC,CAAC;YACvC,IAAI,KAAK,GAAG,CAAC,IAAI,CAAC,MAAM,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;gBAC1C,OAAO,KAAK,CAAC;YACd,CAAC;QACF,CAAC;QACD,QAAQ,GAAG,IAAI,CAAC;QAChB,WAAW,GAAG,IAAI,CAAC;IACpB,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { type RandomFn } from "@ac-kit/core";
2
+ /**
3
+ * Draws `size` distinct positions' elements of `items`, uniformly: every
4
+ * ordered selection of `size` positions is equally likely, so the result is
5
+ * also in random order. A raffle, a random subset for review, a test sample.
6
+ *
7
+ * The first `size` steps of a Fisher–Yates shuffle, with the positions it would
8
+ * have swapped kept in a sparse `Map` rather than in a copy of `items`, so the
9
+ * cost follows the sample, not the input: drawing 10 of a million is 10 steps.
10
+ *
11
+ * Time complexity: O(size), `size` calls to `random`. Memory: O(size).
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * sampleWithoutReplacement(entrants, 3, Math.random); // three winners
16
+ * ```;
17
+ *
18
+ * @param items - The population; not copied or modified. Equal elements at
19
+ * different positions are distinct draws.
20
+ * @param size - How many to draw, an integer in `[0, items.length]`.
21
+ * @param random - A source in `[0, 1)`, called once per draw.
22
+ * @returns A fresh array of `size` elements.
23
+ * @throws {RangeError} When `size` is not an integer in `[0, items.length]`.
24
+ */
25
+ export declare function sampleWithoutReplacement<T>(items: readonly T[], size: number, random: RandomFn): T[];
26
+ //# sourceMappingURL=sample-without-replacement.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sample-without-replacement.d.ts","sourceRoot":"","sources":["../../src/sample/sample-without-replacement.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAI5D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,EACzC,KAAK,EAAE,SAAS,CAAC,EAAE,EACnB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,QAAQ,GACd,CAAC,EAAE,CAcL"}