@ac-kit/algo 0.4.0 → 0.5.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 (59) hide show
  1. package/CHANGELOG.md +82 -0
  2. package/README.md +18 -8
  3. package/dist/graph/children-of.d.ts +9 -0
  4. package/dist/graph/children-of.d.ts.map +1 -0
  5. package/dist/graph/children-of.js +2 -0
  6. package/dist/graph/children-of.js.map +1 -0
  7. package/dist/graph/find-cycle.d.ts +31 -0
  8. package/dist/graph/find-cycle.d.ts.map +1 -0
  9. package/dist/graph/find-cycle.js +84 -0
  10. package/dist/graph/find-cycle.js.map +1 -0
  11. package/dist/graph/hierarchy-from-parents.d.ts +41 -0
  12. package/dist/graph/hierarchy-from-parents.d.ts.map +1 -0
  13. package/dist/graph/hierarchy-from-parents.js +75 -0
  14. package/dist/graph/hierarchy-from-parents.js.map +1 -0
  15. package/dist/group/group-indices.d.ts +56 -0
  16. package/dist/group/group-indices.d.ts.map +1 -0
  17. package/dist/group/group-indices.js +112 -0
  18. package/dist/group/group-indices.js.map +1 -0
  19. package/dist/index.d.ts +6 -2
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +6 -2
  22. package/dist/index.js.map +1 -1
  23. package/dist/interval/is-in-sorted-intervals.js +2 -2
  24. package/dist/interval/is-in-sorted-intervals.js.map +1 -1
  25. package/dist/ordered/_binary-search.d.ts +6 -3
  26. package/dist/ordered/_binary-search.d.ts.map +1 -1
  27. package/dist/ordered/_binary-search.js +8 -5
  28. package/dist/ordered/_binary-search.js.map +1 -1
  29. package/dist/ordered/binary-search.d.ts +26 -0
  30. package/dist/ordered/binary-search.d.ts.map +1 -0
  31. package/dist/ordered/binary-search.js +34 -0
  32. package/dist/ordered/binary-search.js.map +1 -0
  33. package/dist/ordered/bisect-center.js +2 -2
  34. package/dist/ordered/bisect-center.js.map +1 -1
  35. package/dist/ordered/bisect-left.js +2 -2
  36. package/dist/ordered/bisect-left.js.map +1 -1
  37. package/dist/ordered/bisect-right.js +2 -2
  38. package/dist/ordered/bisect-right.js.map +1 -1
  39. package/dist/sample/_random-index.d.ts +4 -0
  40. package/dist/sample/_random-index.d.ts.map +1 -0
  41. package/dist/sample/_random-index.js +5 -0
  42. package/dist/sample/_random-index.js.map +1 -0
  43. package/dist/sample/choice.js +2 -2
  44. package/dist/sample/choice.js.map +1 -1
  45. package/dist/sample/shuffle.js +3 -3
  46. package/dist/sample/shuffle.js.map +1 -1
  47. package/dist/sort/sorted-indices.d.ts +18 -0
  48. package/dist/sort/sorted-indices.d.ts.map +1 -0
  49. package/dist/sort/sorted-indices.js +22 -0
  50. package/dist/sort/sorted-indices.js.map +1 -0
  51. package/package.json +5 -5
  52. package/dist/sample/random-boolean.d.ts +0 -23
  53. package/dist/sample/random-boolean.d.ts.map +0 -1
  54. package/dist/sample/random-boolean.js +0 -27
  55. package/dist/sample/random-boolean.js.map +0 -1
  56. package/dist/sample/random-integer.d.ts +0 -27
  57. package/dist/sample/random-integer.d.ts.map +0 -1
  58. package/dist/sample/random-integer.js +0 -40
  59. package/dist/sample/random-integer.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,87 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 34e8cfa: `findCycle(roots, childrenOf, options?)` returns one directed cycle reachable
8
+ from `roots` as its nodes in edge order (each has an edge to the next, the last
9
+ to the first; a self-loop is a single node), or `undefined` when there is none.
10
+ Nodes are compared by identity, the search is iterative so a deep graph cannot
11
+ overflow the stack, and `options.budget` is charged 1 per node entered and 1 per
12
+ successor scanned (a repeated successor included). O(V + E) time.
13
+ - 34e8cfa: `groupIndices(items, groupOf, groupCount)` groups the positions of `items` by
14
+ the group number `groupOf(item, index)` gives each one and returns them as two
15
+ `Uint32Array`s, `offsets` (`groupCount + 1` entries) and `indices`, so group
16
+ `g` is `indices[offsets[g] … offsets[g + 1])` in ascending order: the
17
+ compressed sparse row layout of an adjacency list or a parent → children
18
+ table, in O(n + groupCount). Group numbers already in an array take the
19
+ identity callback (`groupIndices(parentOf, (parent) => parent, n)`). A group
20
+ of `-1` leaves the position out; any other result that is not an integer in
21
+ `[0, groupCount)` throws a `RangeError` naming the position and the value.
22
+ `groupOf` is called twice per item and must be deterministic: if it answers
23
+ differently the second time, the result groups the second answers when the
24
+ group sizes still match, and a `RangeError` is thrown otherwise.
25
+ - 34e8cfa: New `hierarchyFromParents(items, { keyOf, parentKeyOf })`: children lists from
26
+ rows that carry a key and a parent key (d3 `stratify`), as flat `Uint32Array`
27
+ offsets and indices with a ready-made `childrenOf`. One root is used as it is,
28
+ zero or several get a synthetic root; keys compare as `Map` keys and children
29
+ keep input order. Throws `RangeError` on a duplicate key or an unknown parent
30
+ key, naming the rows and the key (with `@ac-kit/core`'s `describeValue`), or on
31
+ a cycle. New type `ChildrenOf<TNode>`, the callback `walkTree` and the
32
+ hierarchy layouts take.
33
+
34
+ `@ac-kit/algo` no longer depends on `@ac-kit/math-geometry`,
35
+ `@ac-kit/math-linear` or `@ac-kit/math-scalar`.
36
+ - 34e8cfa: `randomInteger` and `randomBoolean` move from `@ac-kit/algo` to
37
+ `@ac-kit/math-random`, with unchanged behaviour. **Breaking for
38
+ `@ac-kit/algo`:** import them from `@ac-kit/math-random` instead
39
+ (`import { randomBoolean, randomInteger } from "@ac-kit/math-random"`);
40
+ `choice` and `shuffle` stay in `@ac-kit/algo`. `@ac-kit/math-stats` and
41
+ `@ac-kit/model-markup` now depend on `@ac-kit/math-random`.
42
+ - 34e8cfa: `sortedIndices(values, compare)` returns the positions of `values` in the order
43
+ a comparator sorts them (an argsort), stable on ties, without modifying the
44
+ values. It accepts any array-like, typed arrays included, and returns a plain
45
+ `number[]`.
46
+ - 34e8cfa: `binarySearch(low, high, predicate)` finds the first integer in `[low, high)`
47
+ where a monotonic predicate turns false — what C++ and Rust call
48
+ `partition_point`. It searches an answer rather than an array, the smallest
49
+ capacity that fits or the first millisecond a condition holds, over any range of
50
+ safe integers.
51
+
52
+ ### Patch Changes
53
+
54
+ - Updated dependencies [34e8cfa]
55
+ - Updated dependencies [34e8cfa]
56
+ - Updated dependencies [34e8cfa]
57
+ - Updated dependencies [34e8cfa]
58
+ - Updated dependencies [34e8cfa]
59
+ - Updated dependencies [34e8cfa]
60
+ - Updated dependencies [34e8cfa]
61
+ - Updated dependencies [34e8cfa]
62
+ - Updated dependencies [34e8cfa]
63
+ - Updated dependencies [34e8cfa]
64
+ - Updated dependencies [34e8cfa]
65
+ - Updated dependencies [34e8cfa]
66
+ - Updated dependencies [34e8cfa]
67
+ - Updated dependencies [34e8cfa]
68
+ - Updated dependencies [34e8cfa]
69
+ - Updated dependencies [34e8cfa]
70
+ - Updated dependencies [34e8cfa]
71
+ - Updated dependencies [34e8cfa]
72
+ - @ac-kit/core@0.12.0
73
+ - @ac-kit/data@0.4.0
74
+
75
+ ## 0.4.1
76
+
77
+ ### Patch Changes
78
+
79
+ - Updated dependencies [065cf8d]
80
+ - Updated dependencies [065cf8d]
81
+ - Updated dependencies [065cf8d]
82
+ - @ac-kit/core@0.11.0
83
+ - @ac-kit/data@0.3.3
84
+
3
85
  ## 0.4.0
4
86
 
5
87
  ### Minor Changes
package/README.md CHANGED
@@ -31,7 +31,10 @@ const distinct = [...uniqBy(events, (event) => event.correlationId)];
31
31
  optional work budget, safe on hostile deep trees), `aStar`
32
32
  (which is Dijkstra's algorithm when you give it no heuristic) and greedy
33
33
  `bestFirstSearch`, all over a `childrenOf`/`neighboursOf` callback rather than
34
- any particular graph type.
34
+ any particular graph type. `findCycle` returns one concrete directed cycle
35
+ (or nothing), for an error message that names it. `hierarchyFromParents` turns rows with a key and a
36
+ parent key (a chart's frame) into the `childrenOf` those take, as flat
37
+ `Uint32Array` offsets and indices (d3 `stratify`).
35
38
  - **Recursion without a stack** — `runTrampoline` runs a recursive algorithm
36
39
  written as native synchronous generators (`const value = yield child`) on
37
40
  an explicit stack, so a hostile nesting depth costs heap, not a stack
@@ -42,16 +45,23 @@ const distinct = [...uniqBy(events, (event) => event.correlationId)];
42
45
  `backtrack` for constraint search that undoes its own moves on the way back
43
46
  out of a dead end.
44
47
  - **Binary search** — `bisect`, `bisectLeft`, `bisectRight`, `bisectCenter` and
45
- a reusable `createBisector` bound to one accessor, plus membership testing
46
- against sorted, disjoint intervals.
48
+ a reusable `createBisector` bound to one accessor, `binarySearch` over any
49
+ integer range driven by a predicate alone, plus membership testing against
50
+ sorted, disjoint intervals.
47
51
  - **Selection** — `quickselect` for order statistics, `minBy`/`maxBy` for the
48
52
  extreme item by a derived key, `uniqueMinBy` for the smallest item under a
49
53
  comparator only when no other ties with it, `selectAt` for picking positions.
50
- - **Sorting** — `radixSort`, a stable, comparator-free sort over an integer key.
54
+ - **Sorting** — `radixSort`, a stable, comparator-free sort over an integer key,
55
+ and `sortedIndices`, the stable permutation a comparator sorts values into
56
+ (an argsort), to reorder parallel arrays or write results back in place.
51
57
  - **Combinatorics** — `combinations` and `combinationsLazy`, every `k`-subset
52
58
  of your items.
53
59
  - **Grouping** — `groupBy` (nesting one `Map` level per accessor), `partition`,
54
- `partitionIndices`, `uniq` and `uniqBy`.
60
+ `partitionIndices`, `uniq` and `uniqBy`; `groupIndices(items, groupOf,
61
+ groupCount)` groups positions by an integer group number into two flat
62
+ `Uint32Array`s (offsets and indices, the CSR layout of an adjacency list or a
63
+ parent → children table) by counting sort. Group numbers already in an array
64
+ take the identity callback: `groupIndices(parentOf, (parent) => parent, n)`.
55
65
  - **Set algebra** — `union`, `intersection`, `difference`,
56
66
  `symmetricDifference`, and the `isSubsetOf` / `isSupersetOf` /
57
67
  `isDisjointFrom` predicates — over any iterables; `duplicatesBy` yields each
@@ -59,9 +69,9 @@ const distinct = [...uniqBy(events, (event) => event.correlationId)];
59
69
  over another.
60
70
  - **Shuffling** — `shuffle` (Fisher–Yates or Sattolo) with the random source
61
71
  injectable, so results can be made reproducible, and `spreadEvenly` to
62
- interleave two collections at evenly spaced positions; `randomInteger`,
63
- `randomBoolean` and `choice` draw one integer, one boolean or one element
64
- from an injectable random source.
72
+ interleave two collections at evenly spaced positions; `choice` draws one
73
+ element from an injectable random source. (`randomInteger` and
74
+ `randomBoolean` live in `@ac-kit/math-random`.)
65
75
 
66
76
  ## What's not included
67
77
 
@@ -0,0 +1,9 @@
1
+ import type { Callable } from "@ac-kit/core";
2
+ /**
3
+ * Children of a node, or `undefined`/empty for a leaf. Called once per node;
4
+ * the result must not change during the call. The same shape `walkTree` takes.
5
+ */
6
+ export type ChildrenOf<TNode> = Callable<[
7
+ node: TNode
8
+ ], ArrayLike<TNode> | undefined>;
9
+ //# sourceMappingURL=children-of.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"children-of.d.ts","sourceRoot":"","sources":["../../src/graph/children-of.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE7C;;;GAGG;AACH,MAAM,MAAM,UAAU,CAAC,KAAK,IAAI,QAAQ,CACvC;IAAC,IAAI,EAAE,KAAK;CAAC,EACb,SAAS,CAAC,KAAK,CAAC,GAAG,SAAS,CAC5B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=children-of.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"children-of.js","sourceRoot":"","sources":["../../src/graph/children-of.ts"],"names":[],"mappings":""}
@@ -0,0 +1,31 @@
1
+ import type { WorkBudget } from "@ac-kit/core";
2
+ export type FindCycleOptions = {
3
+ /**
4
+ * Charged 1 before each node is entered and 1 for each successor read (each
5
+ * edge scanned, repeated ones included), so a search over an untrusted graph
6
+ * can be capped. Whatever `spend` throws propagates unchanged.
7
+ */
8
+ budget?: WorkBudget;
9
+ };
10
+ /**
11
+ * Finds one directed cycle reachable from `roots`, for an error message or a
12
+ * "cannot order these" report. Iterative depth-first search, so a hostile deep
13
+ * graph cannot overflow the stack.
14
+ *
15
+ * Nodes are compared by identity (`Map` semantics, so `NaN` equals `NaN`).
16
+ * `childrenOf` is called once per node, and the iterable it returns is read
17
+ * once. Whichever way the search ends, the iterators still open are closed with
18
+ * `return()`; an error from that is dropped in favour of the one being thrown.
19
+ *
20
+ * Time complexity: O(V + E). Memory: O(V).
21
+ *
22
+ * @param roots - Where to start; nodes already reached from an earlier root are
23
+ * not entered again. Pass every node to check a whole graph.
24
+ * @param childrenOf - The successors of a node, or `undefined` for none.
25
+ * @returns The nodes of one cycle in edge order: each one has an edge to the
26
+ * next and the last one to the first (a self-loop is a single node); the
27
+ * search order decides which cycle. `undefined` when no cycle is reachable.
28
+ * @throws Whatever `options.budget.spend`, `childrenOf` or an iterator throws.
29
+ */
30
+ export declare function findCycle<TNode>(roots: Iterable<TNode>, childrenOf: (node: TNode) => Iterable<TNode> | undefined, options?: FindCycleOptions): TNode[] | undefined;
31
+ //# sourceMappingURL=find-cycle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-cycle.d.ts","sourceRoot":"","sources":["../../src/graph/find-cycle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,MAAM,MAAM,gBAAgB,GAAG;IAC9B;;;;OAIG;IACH,MAAM,CAAC,EAAE,UAAU,CAAC;CACpB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAC9B,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,EACtB,UAAU,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,QAAQ,CAAC,KAAK,CAAC,GAAG,SAAS,EACxD,OAAO,GAAE,gBAAqB,GAC5B,KAAK,EAAE,GAAG,SAAS,CAWrB"}
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Finds one directed cycle reachable from `roots`, for an error message or a
3
+ * "cannot order these" report. Iterative depth-first search, so a hostile deep
4
+ * graph cannot overflow the stack.
5
+ *
6
+ * Nodes are compared by identity (`Map` semantics, so `NaN` equals `NaN`).
7
+ * `childrenOf` is called once per node, and the iterable it returns is read
8
+ * once. Whichever way the search ends, the iterators still open are closed with
9
+ * `return()`; an error from that is dropped in favour of the one being thrown.
10
+ *
11
+ * Time complexity: O(V + E). Memory: O(V).
12
+ *
13
+ * @param roots - Where to start; nodes already reached from an earlier root are
14
+ * not entered again. Pass every node to check a whole graph.
15
+ * @param childrenOf - The successors of a node, or `undefined` for none.
16
+ * @returns The nodes of one cycle in edge order: each one has an edge to the
17
+ * next and the last one to the first (a self-loop is a single node); the
18
+ * search order decides which cycle. `undefined` when no cycle is reachable.
19
+ * @throws Whatever `options.budget.spend`, `childrenOf` or an iterator throws.
20
+ */
21
+ export function findCycle(roots, childrenOf, options = {}) {
22
+ const pending = [];
23
+ let result;
24
+ try {
25
+ result = search_(roots, childrenOf, options.budget, pending);
26
+ }
27
+ catch (error) {
28
+ closeAll_(pending, false);
29
+ throw error;
30
+ }
31
+ closeAll_(pending, true);
32
+ return result;
33
+ }
34
+ function search_(roots, childrenOf, budget, pending) {
35
+ // Index on the current path while a node is open, -1 once it is finished.
36
+ const pathIndices = new Map();
37
+ const path = [];
38
+ const enter = (node) => {
39
+ budget?.spend(1);
40
+ pathIndices.set(node, path.length);
41
+ path.push(node);
42
+ pending.push((childrenOf(node) ?? [])[Symbol.iterator]());
43
+ };
44
+ for (const root of roots) {
45
+ if (pathIndices.has(root)) {
46
+ continue;
47
+ }
48
+ enter(root);
49
+ while (path.length > 0) {
50
+ const next = pending[pending.length - 1].next();
51
+ if (next.done) {
52
+ pathIndices.set(path.pop(), -1);
53
+ pending.pop();
54
+ continue;
55
+ }
56
+ budget?.spend(1);
57
+ const index = pathIndices.get(next.value);
58
+ if (index === undefined) {
59
+ enter(next.value);
60
+ }
61
+ else if (index >= 0) {
62
+ return path.slice(index);
63
+ }
64
+ }
65
+ }
66
+ return undefined;
67
+ }
68
+ // Closes innermost first; every iterator gets its `return()`, and only when
69
+ // `report` is set does the first error from one propagate.
70
+ function closeAll_(pending, report) {
71
+ let failure;
72
+ while (pending.length > 0) {
73
+ try {
74
+ pending.pop().return?.();
75
+ }
76
+ catch (error) {
77
+ failure ??= { error };
78
+ }
79
+ }
80
+ if (report && failure !== undefined) {
81
+ throw failure.error;
82
+ }
83
+ }
84
+ //# sourceMappingURL=find-cycle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-cycle.js","sourceRoot":"","sources":["../../src/graph/find-cycle.ts"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,SAAS,CACxB,KAAsB,EACtB,UAAwD,EACxD,OAAO,GAAqB,EAAE;IAE9B,MAAM,OAAO,GAAsB,EAAE,CAAC;IACtC,IAAI,MAA2B,CAAC;IAChC,IAAI,CAAC;QACJ,MAAM,GAAG,OAAO,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,SAAS,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAC1B,MAAM,KAAK,CAAC;IACb,CAAC;IACD,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACzB,OAAO,MAAM,CAAC;AACf,CAAC;AAED,SAAS,OAAO,CACf,KAAsB,EACtB,UAAwD,EACxD,MAA8B,EAC9B,OAA0B;IAE1B,0EAA0E;IAC1E,MAAM,WAAW,GAAG,IAAI,GAAG,EAAiB,CAAC;IAC7C,MAAM,IAAI,GAAY,EAAE,CAAC;IAEzB,MAAM,KAAK,GAAG,CAAC,IAAW,EAAQ,EAAE;QACnC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;QACjB,WAAW,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QACnC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAChB,OAAO,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,IAAI,CA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B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,OAAO,KAAK,EAAE,KAAK,EAAE,CAAC;QACvB,CAAC;IACF,CAAC;IACD,IAAI,MAAM,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QACrC,MAAM,OAAO,CAAC,KAAK,CAAC;IACrB,CAAC;AACF,CAAC"}
@@ -0,0 +1,41 @@
1
+ import { type Callable } from "@ac-kit/core";
2
+ export type ParentTraits<TItem, TKey> = {
3
+ readonly keyOf: Callable<[item: TItem, index: number], TKey>;
4
+ /** `null` or `undefined` for a root. */
5
+ readonly parentKeyOf: Callable<[
6
+ item: TItem,
7
+ index: number
8
+ ], TKey | null | undefined>;
9
+ };
10
+ export type IndexedHierarchy = {
11
+ /**
12
+ * The node to lay out from: the single root's index, or `itemCount` — a
13
+ * synthetic node whose children are the roots — when there are zero or
14
+ * several roots.
15
+ */
16
+ readonly root: number;
17
+ /**
18
+ * `itemCount + 2` offsets: node i's children are `children[childStarts[i] …
19
+ * childStarts[i + 1])`, node `itemCount` being the synthetic root.
20
+ */
21
+ readonly childStarts: Uint32Array;
22
+ readonly children: Uint32Array;
23
+ /**
24
+ * Ready for the layouts' `childrenOf`: a `subarray` view, no copy of the
25
+ * data.
26
+ */
27
+ readonly childrenOf: Callable<[node: number], Uint32Array>;
28
+ };
29
+ /**
30
+ * Children lists from a parent relation (d3 `stratify`): rows with a key and a
31
+ * parent key, as a chart's frame has. Keys compare with SameValueZero. Children
32
+ * keep input order.
33
+ *
34
+ * Complexity: O(n) expected (one `Map`).
35
+ *
36
+ * @throws {RangeError} A duplicate key (naming both rows and the key), a parent
37
+ * key no row has (naming the row and the key), or a cycle (rows unreachable
38
+ * from every root; names the lowest). Keys are named with `describeValue`.
39
+ */
40
+ export declare function hierarchyFromParents<TItem, TKey>(items: readonly TItem[], traits: ParentTraits<TItem, TKey>): IndexedHierarchy;
41
+ //# sourceMappingURL=hierarchy-from-parents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hierarchy-from-parents.d.ts","sourceRoot":"","sources":["../../src/graph/hierarchy-from-parents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAK5D,MAAM,MAAM,YAAY,CAAC,KAAK,EAAE,IAAI,IAAI;IACvC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC;IAC7D,wCAAwC;IACxC,QAAQ,CAAC,WAAW,EAAE,QAAQ,CAC7B;QAAC,IAAI,EAAE,KAAK;QAAE,KAAK,EAAE,MAAM;KAAC,EAC5B,IAAI,GAAG,IAAI,GAAG,SAAS,CACvB,CAAC;CACF,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC9B;;;;OAIG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAClC,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;IAC/B;;;OAGG;IACH,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,WAAW,CAAC,CAAC;CAC3D,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,IAAI,EAC/C,KAAK,EAAE,SAAS,KAAK,EAAE,EACvB,MAAM,EAAE,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,GAC/B,gBAAgB,CAwDlB"}
@@ -0,0 +1,75 @@
1
+ import { describeValue } from "@ac-kit/core";
2
+ import { groupIndices } from "../group/group-indices.js";
3
+ import { walkTree } from "./walk-tree.js";
4
+ /**
5
+ * Children lists from a parent relation (d3 `stratify`): rows with a key and a
6
+ * parent key, as a chart's frame has. Keys compare with SameValueZero. Children
7
+ * keep input order.
8
+ *
9
+ * Complexity: O(n) expected (one `Map`).
10
+ *
11
+ * @throws {RangeError} A duplicate key (naming both rows and the key), a parent
12
+ * key no row has (naming the row and the key), or a cycle (rows unreachable
13
+ * from every root; names the lowest). Keys are named with `describeValue`.
14
+ */
15
+ export function hierarchyFromParents(items, traits) {
16
+ const itemCount = items.length;
17
+ const rowOfKey = new Map();
18
+ const parentKeys = [];
19
+ // Keys are named with `describeValue`, which never throws or runs their code.
20
+ for (let row = 0; row < itemCount; row++) {
21
+ const key = traits.keyOf(items[row], row);
22
+ const earlier = rowOfKey.get(key);
23
+ if (earlier !== undefined) {
24
+ throw new RangeError(`hierarchyFromParents: rows ${earlier} and ${row} have the same key ${describeValue(key)}`);
25
+ }
26
+ rowOfKey.set(key, row);
27
+ parentKeys.push(traits.parentKeyOf(items[row], row));
28
+ }
29
+ // Parent row per item; itemCount (the synthetic node) marks a root.
30
+ const parents = new Int32Array(itemCount);
31
+ let rootCount = 0;
32
+ let onlyRoot = itemCount;
33
+ for (let row = 0; row < itemCount; row++) {
34
+ const parentKey = parentKeys[row];
35
+ if (parentKey === null || parentKey === undefined) {
36
+ parents[row] = itemCount;
37
+ rootCount++;
38
+ onlyRoot = row;
39
+ continue;
40
+ }
41
+ const parent = rowOfKey.get(parentKey);
42
+ if (parent === undefined) {
43
+ throw new RangeError(`hierarchyFromParents: row ${row} has the parent key ${describeValue(parentKey)}, which no row has`);
44
+ }
45
+ parents[row] = parent;
46
+ }
47
+ let root = itemCount;
48
+ if (rootCount === 1) {
49
+ root = onlyRoot;
50
+ parents[root] = -1;
51
+ }
52
+ const { offsets: childStarts, indices: children } = groupIndices(parents, (parent) => parent, itemCount + 1);
53
+ const childrenOf = (node) => children.subarray(childStarts[node], childStarts[node + 1]);
54
+ assertReachable_(itemCount, root, childrenOf);
55
+ return { root, childStarts, children, childrenOf };
56
+ }
57
+ function assertReachable_(itemCount, root, childrenOf) {
58
+ const reached = new Uint8Array(itemCount + 1);
59
+ let reachedCount = 0;
60
+ walkTree(root, childrenOf, (node) => {
61
+ reached[node] = 1;
62
+ reachedCount++;
63
+ return undefined;
64
+ });
65
+ // The synthetic root counts when it is the start.
66
+ const expected = root === itemCount ? itemCount + 1 : itemCount;
67
+ if (reachedCount < expected) {
68
+ let lowest = 0;
69
+ while (reached[lowest] === 1) {
70
+ lowest++;
71
+ }
72
+ throw new RangeError(`hierarchyFromParents: row ${lowest} is in a cycle or below one: it cannot be reached from a root`);
73
+ }
74
+ }
75
+ //# sourceMappingURL=hierarchy-from-parents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hierarchy-from-parents.js","sourceRoot":"","sources":["../../src/graph/hierarchy-from-parents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAiB,MAAM,cAAc,CAAC;AAE5D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AA+B1C;;;;;;;;;;GAUG;AACH,MAAM,UAAU,oBAAoB,CACnC,KAAuB,EACvB,MAAiC;IAEjC,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC;IAC/B,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAgB,CAAC;IACzC,MAAM,UAAU,GAAgC,EAAE,CAAC;IAEnD,8EAA8E;IAC9E,KAAK,IAAI,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,SAAS,EAAE,GAAG,EAAE,EAAE,CAAC;QAC1C,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAE,EAAE,GAAG,CAAC,CAAC;QAC3C,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAClC,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC3B,MAAM,IAAI,UAAU,CACnB,8BAA8B,OAAO,QAAQ,GAAG,sBAAsB,aAAa,CAAC,GAAG,CAAC,EAAE,CAC1F,CAAC;QACH,CAAC;QACD,QAAQ,CAAC,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AClB,SAAS,GAAG,CAAC,CACb,CAAC;IACF,MAAM,UAAU,GAAG,CAAC,IAAY,EAAe,EAAE,CAChD,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAE,EAAE,WAAW,CAAC,IAAI,GAAG,CAAC,CAAE,CAAC,CAAC;IAE/D,gBAAgB,CAAC,SAAS,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC;IAE9C,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC;AACpD,CAAC;AAED,SAAS,gBAAgB,CACxB,SAAiB,EACjB,IAAY,EACZ,UAAyC;IAEzC,MAAM,OAAO,GAAG,IAAI,UAAU,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC;IAC9C,IAAI,YAAY,GAAG,CAAC,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,UAAU,EAAE,CAAC,IAAI,EAAE,EAAE;QACnC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAClB,YAAY,EAAE,CAAC;QACf,OAAO,SAAS,CAAC;IAClB,CAAC,CAAC,CAAC;IAEH,kDAAkD;IAClD,MAAM,QAAQ,GAAG,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAChE,IAAI,YAAY,GAAG,QAAQ,EAAE,CAAC;QAC7B,IAAI,MAAM,GAAG,CAAC,CAAC;QACf,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YAC9B,MAAM,EAAE,CAAC;QACV,CAAC;QACD,MAAM,IAAI,UAAU,CACnB,6BAA6B,MAAM,+DAA+D,CAClG,CAAC;IACH,CAAC;AACF,CAAC"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Positions grouped by group number: group `g` holds `indices[offsets[g] …
3
+ * offsets[g + 1])`, ascending.
4
+ */
5
+ export type IndexGroups = {
6
+ /** `groupCount + 1` ascending offsets into `indices`, the first `0`. */
7
+ readonly offsets: Uint32Array;
8
+ /**
9
+ * The positions of `groups`, group after group, each group in ascending
10
+ * order; positions whose group is `-1` are absent.
11
+ */
12
+ readonly indices: Uint32Array;
13
+ };
14
+ /**
15
+ * Groups the positions of `items` by the group number `groupOf` gives each one
16
+ * — the compressed sparse row (CSR) layout an adjacency list, a parent →
17
+ * children table or a bucket index is built on, in two flat arrays rather than
18
+ * an array of arrays.
19
+ *
20
+ * A counting sort: count, prefix-sum, stable fill, in O(n + groupCount) time
21
+ * and no memory beyond the result. A group of `-1` means "no group" and leaves
22
+ * the position out; every other group must be an integer in `[0, groupCount)`.
23
+ *
24
+ * `groupOf` is called twice per item, once per pass, and its results are never
25
+ * stored, so it must be deterministic. Every result is checked in both passes:
26
+ * when the second call answers differently, the result groups the second
27
+ * answers if the group sizes still match, and a `RangeError` is thrown
28
+ * otherwise; no inconsistent result is ever returned.
29
+ *
30
+ * @example
31
+ * const tasks = [{ owner: 1 }, { owner: 0 }, { owner: -1 }, { owner: 1 }];
32
+ * const { offsets, indices } = groupIndices(tasks, (task) => task.owner, 2);
33
+ * // offsets: [0, 1, 3], indices: [1, 0, 3]
34
+ * // group 0 holds indices[0 … 1) = [1]; group 1 holds indices[1 … 3) = [0, 3]
35
+ *
36
+ * @example
37
+ * // Group numbers already in an array: the identity callback.
38
+ * const parentOf = Int32Array.of(-1, 0, 0, 1);
39
+ * const children = groupIndices(
40
+ * parentOf,
41
+ * (parent) => parent,
42
+ * parentOf.length,
43
+ * );
44
+ *
45
+ * @param items - The items to group.
46
+ * @param groupOf - The group of an item, or `-1` for none; deterministic.
47
+ * @param groupCount - How many groups there are.
48
+ * @returns The offsets and the grouped positions.
49
+ * @throws {RangeError} When `groupCount` or `items.length` is not an integer in
50
+ * `[0, 2³² − 1]`, or `groupOf` returns neither `-1` nor an integer in `[0,
51
+ * groupCount)`; the message names the position and the result. Also when
52
+ * `groupOf` answers differently in the second pass and the group sizes no
53
+ * longer match.
54
+ */
55
+ export declare function groupIndices<T>(items: ArrayLike<T>, groupOf: (item: T, index: number) => number, groupCount: number): IndexGroups;
56
+ //# sourceMappingURL=group-indices.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"group-indices.d.ts","sourceRoot":"","sources":["../../src/group/group-indices.ts"],"names":[],"mappings":"AAKA;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG;IACzB,wEAAwE;IACxE,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;IAC9B;;;OAGG;IACH,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;CAC9B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAC7B,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,EACnB,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,EAC3C,UAAU,EAAE,MAAM,GAChB,WAAW,CAsEb"}
@@ -0,0 +1,112 @@
1
+ import { assertInteger, describeValue, isIntegerInRange } from "@ac-kit/core";
2
+ const MAX_UINT32_ = 0xffffffff;
3
+ const UNWRITTEN_ = 0xffffffff;
4
+ /**
5
+ * Groups the positions of `items` by the group number `groupOf` gives each one
6
+ * — the compressed sparse row (CSR) layout an adjacency list, a parent →
7
+ * children table or a bucket index is built on, in two flat arrays rather than
8
+ * an array of arrays.
9
+ *
10
+ * A counting sort: count, prefix-sum, stable fill, in O(n + groupCount) time
11
+ * and no memory beyond the result. A group of `-1` means "no group" and leaves
12
+ * the position out; every other group must be an integer in `[0, groupCount)`.
13
+ *
14
+ * `groupOf` is called twice per item, once per pass, and its results are never
15
+ * stored, so it must be deterministic. Every result is checked in both passes:
16
+ * when the second call answers differently, the result groups the second
17
+ * answers if the group sizes still match, and a `RangeError` is thrown
18
+ * otherwise; no inconsistent result is ever returned.
19
+ *
20
+ * @example
21
+ * const tasks = [{ owner: 1 }, { owner: 0 }, { owner: -1 }, { owner: 1 }];
22
+ * const { offsets, indices } = groupIndices(tasks, (task) => task.owner, 2);
23
+ * // offsets: [0, 1, 3], indices: [1, 0, 3]
24
+ * // group 0 holds indices[0 … 1) = [1]; group 1 holds indices[1 … 3) = [0, 3]
25
+ *
26
+ * @example
27
+ * // Group numbers already in an array: the identity callback.
28
+ * const parentOf = Int32Array.of(-1, 0, 0, 1);
29
+ * const children = groupIndices(
30
+ * parentOf,
31
+ * (parent) => parent,
32
+ * parentOf.length,
33
+ * );
34
+ *
35
+ * @param items - The items to group.
36
+ * @param groupOf - The group of an item, or `-1` for none; deterministic.
37
+ * @param groupCount - How many groups there are.
38
+ * @returns The offsets and the grouped positions.
39
+ * @throws {RangeError} When `groupCount` or `items.length` is not an integer in
40
+ * `[0, 2³² − 1]`, or `groupOf` returns neither `-1` nor an integer in `[0,
41
+ * groupCount)`; the message names the position and the result. Also when
42
+ * `groupOf` answers differently in the second pass and the group sizes no
43
+ * longer match.
44
+ */
45
+ export function groupIndices(items, groupOf, groupCount) {
46
+ assertInteger(groupCount, "groupCount", 0, MAX_UINT32_);
47
+ const length = items.length;
48
+ assertInteger(length, "items.length", 0, MAX_UINT32_);
49
+ // Counted one slot up, so the prefix sum leaves each group's start in the
50
+ // slot of its own number and the total in the last.
51
+ const offsets = new Uint32Array(groupCount + 1);
52
+ let kept = 0;
53
+ for (let position = 0; position < length; position++) {
54
+ const group = groupOf(items[position], position);
55
+ if (group === -1) {
56
+ continue;
57
+ }
58
+ if (!isIntegerInRange(group, 0, groupCount)) {
59
+ throw new RangeError(`groupOf(items[${position}], ${position}) must be -1 or an integer in [0, ${groupCount}), got ${describeValue(group)}`);
60
+ }
61
+ offsets[group + 1]++;
62
+ kept++;
63
+ }
64
+ for (let group = 0; group < groupCount; group++) {
65
+ offsets[group + 1] += offsets[group];
66
+ }
67
+ // Each group's start serves as its write cursor, which leaves it at the
68
+ // group's end, the next group's start: shifting by one slot restores them.
69
+ //
70
+ // `groupOf` is called twice, and may answer differently the
71
+ // second time. Every slot starts as a mark no position can equal (positions
72
+ // stay below 2³² − 1), and a write must land, inside the array, on a marked
73
+ // slot. With as many writes as counted entries, a group that took fewer than
74
+ // its share would leave a slot no group can reach, so the first group to
75
+ // stray took more and ran onto the next group's first slot: a collision, a
76
+ // write past the end, or, when no later group writes, cursors out of order.
77
+ const indices = new Uint32Array(kept).fill(UNWRITTEN_);
78
+ let written = 0;
79
+ for (let position = 0; position < length; position++) {
80
+ const group = groupOf(items[position], position);
81
+ if (group === -1) {
82
+ continue;
83
+ }
84
+ if (!isIntegerInRange(group, 0, groupCount)) {
85
+ throw changed_(position);
86
+ }
87
+ const slot = offsets[group]++;
88
+ if (slot >= kept || indices[slot] !== UNWRITTEN_) {
89
+ throw changed_(position);
90
+ }
91
+ indices[slot] = position;
92
+ written++;
93
+ }
94
+ if (written !== kept) {
95
+ throw changed_();
96
+ }
97
+ for (let group = 1; group < groupCount; group++) {
98
+ if (offsets[group - 1] > offsets[group]) {
99
+ throw changed_();
100
+ }
101
+ }
102
+ offsets.copyWithin(1, 0, groupCount);
103
+ offsets[0] = 0;
104
+ return { offsets, indices };
105
+ }
106
+ function changed_(position) {
107
+ const where = position === undefined
108
+ ? "groupOf's results"
109
+ : `groupOf(items[${position}], ${position})`;
110
+ return new RangeError(`${where} changed between groupIndices' counting and filling passes; groupOf must be deterministic`);
111
+ }
112
+ //# sourceMappingURL=group-indices.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"group-indices.js","sourceRoot":"","sources":["../../src/group/group-indices.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAE9E,MAAM,WAAW,GAAG,UAAU,CAAC;AAC/B,MAAM,UAAU,GAAG,UAAU,CAAC;AAgB9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,MAAM,UAAU,YAAY,CAC3B,KAAmB,EACnB,OAA2C,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AC;IAEf,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;AAC7B,CAAC;AAED,SAAS,QAAQ,CAAC,QAAiB;IAClC,MAAM,KAAK,GACV,QAAQ,KAAK,SAAS;QACrB,CAAC,CAAC,mBAAmB;QACrB,CAAC,CAAC,iBAAiB,QAAQ,MAAM,QAAQ,GAAG,CAAC;IAE/C,OAAO,IAAI,UAAU,CACpB,GAAG,KAAK,2FAA2F,CACnG,CAAC;AACH,CAAC"}
package/dist/index.d.ts CHANGED
@@ -2,9 +2,13 @@ export * from "./combinatorics/combinations.js";
2
2
  export * from "./distribute/spread-evenly.js";
3
3
  export * from "./graph/a-star.js";
4
4
  export * from "./graph/best-first-search.js";
5
+ export * from "./graph/children-of.js";
5
6
  export * from "./graph/dfs.js";
7
+ export * from "./graph/find-cycle.js";
8
+ export * from "./graph/hierarchy-from-parents.js";
6
9
  export * from "./graph/walk-tree.js";
7
10
  export * from "./group/group-by.js";
11
+ export * from "./group/group-indices.js";
8
12
  export * from "./group/partition-indices.js";
9
13
  export * from "./group/partition.js";
10
14
  export * from "./interval/complement-intervals.js";
@@ -16,6 +20,7 @@ export * from "./interval/subtract-intervals.js";
16
20
  export * from "./optimize/backtrack.js";
17
21
  export * from "./optimize/beam-search.js";
18
22
  export * from "./optimize/viterbi.js";
23
+ export * from "./ordered/binary-search.js";
19
24
  export * from "./ordered/bisect-center.js";
20
25
  export * from "./ordered/bisect-left.js";
21
26
  export * from "./ordered/bisect-right.js";
@@ -23,8 +28,6 @@ export * from "./ordered/bisect.js";
23
28
  export * from "./ordered/create-bisector.js";
24
29
  export * from "./recursion/run-trampoline.js";
25
30
  export * from "./sample/choice.js";
26
- export * from "./sample/random-boolean.js";
27
- export * from "./sample/random-integer.js";
28
31
  export * from "./sample/shuffle.js";
29
32
  export * from "./select/max-by.js";
30
33
  export * from "./select/min-by.js";
@@ -43,4 +46,5 @@ export * from "./set/union.js";
43
46
  export * from "./set/uniq-by.js";
44
47
  export * from "./set/uniq.js";
45
48
  export * from "./sort/radix-sort.js";
49
+ export * from "./sort/sorted-indices.js";
46
50
  //# 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,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,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;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC;AACpC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,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,s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