@ac-kit/math-graph 0.0.0-stage → 0.1.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.
- package/CHANGELOG.md +91 -0
- package/LICENSE +28 -0
- package/README.md +92 -2
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/layout/_force-forces.d.ts +103 -0
- package/dist/layout/_force-forces.d.ts.map +1 -0
- package/dist/layout/_force-forces.js +490 -0
- package/dist/layout/_force-forces.js.map +1 -0
- package/dist/layout/_hierarchy-table.d.ts +34 -0
- package/dist/layout/_hierarchy-table.d.ts.map +1 -0
- package/dist/layout/_hierarchy-table.js +131 -0
- package/dist/layout/_hierarchy-table.js.map +1 -0
- package/dist/layout/_index-graph.d.ts +32 -0
- package/dist/layout/_index-graph.d.ts.map +1 -0
- package/dist/layout/_index-graph.js +51 -0
- package/dist/layout/_index-graph.js.map +1 -0
- package/dist/layout/_layer-order.d.ts +96 -0
- package/dist/layout/_layer-order.d.ts.map +1 -0
- package/dist/layout/_layer-order.js +462 -0
- package/dist/layout/_layer-order.js.map +1 -0
- package/dist/layout/_layered-acyclic.d.ts +28 -0
- package/dist/layout/_layered-acyclic.d.ts.map +1 -0
- package/dist/layout/_layered-acyclic.js +179 -0
- package/dist/layout/_layered-acyclic.js.map +1 -0
- package/dist/layout/_layered-position.d.ts +56 -0
- package/dist/layout/_layered-position.d.ts.map +1 -0
- package/dist/layout/_layered-position.js +369 -0
- package/dist/layout/_layered-position.js.map +1 -0
- package/dist/layout/_layered-rank.d.ts +54 -0
- package/dist/layout/_layered-rank.d.ts.map +1 -0
- package/dist/layout/_layered-rank.js +436 -0
- package/dist/layout/_layered-rank.js.map +1 -0
- package/dist/layout/_tree-common.d.ts +38 -0
- package/dist/layout/_tree-common.d.ts.map +1 -0
- package/dist/layout/_tree-common.js +73 -0
- package/dist/layout/_tree-common.js.map +1 -0
- package/dist/layout/_treemap-tiling.d.ts +62 -0
- package/dist/layout/_treemap-tiling.d.ts.map +1 -0
- package/dist/layout/_treemap-tiling.js +187 -0
- package/dist/layout/_treemap-tiling.js.map +1 -0
- package/dist/layout/circular-layout.d.ts +27 -0
- package/dist/layout/circular-layout.d.ts.map +1 -0
- package/dist/layout/circular-layout.js +35 -0
- package/dist/layout/circular-layout.js.map +1 -0
- package/dist/layout/create-force-step.d.ts +112 -0
- package/dist/layout/create-force-step.d.ts.map +1 -0
- package/dist/layout/create-force-step.js +134 -0
- package/dist/layout/create-force-step.js.map +1 -0
- package/dist/layout/dendrogram-layout.d.ts +32 -0
- package/dist/layout/dendrogram-layout.d.ts.map +1 -0
- package/dist/layout/dendrogram-layout.js +110 -0
- package/dist/layout/dendrogram-layout.js.map +1 -0
- package/dist/layout/force-directed-layout.d.ts +42 -0
- package/dist/layout/force-directed-layout.d.ts.map +1 -0
- package/dist/layout/force-directed-layout.js +112 -0
- package/dist/layout/force-directed-layout.js.map +1 -0
- package/dist/layout/layered-layout.d.ts +96 -0
- package/dist/layout/layered-layout.d.ts.map +1 -0
- package/dist/layout/layered-layout.js +120 -0
- package/dist/layout/layered-layout.js.map +1 -0
- package/dist/layout/partition-layout.d.ts +31 -0
- package/dist/layout/partition-layout.d.ts.map +1 -0
- package/dist/layout/partition-layout.js +78 -0
- package/dist/layout/partition-layout.js.map +1 -0
- package/dist/layout/phyllotaxis-layout.d.ts +17 -0
- package/dist/layout/phyllotaxis-layout.d.ts.map +1 -0
- package/dist/layout/phyllotaxis-layout.js +32 -0
- package/dist/layout/phyllotaxis-layout.js.map +1 -0
- package/dist/layout/sankey-layout.d.ts +104 -0
- package/dist/layout/sankey-layout.d.ts.map +1 -0
- package/dist/layout/sankey-layout.js +636 -0
- package/dist/layout/sankey-layout.js.map +1 -0
- package/dist/layout/tidy-tree-layout.d.ts +25 -0
- package/dist/layout/tidy-tree-layout.d.ts.map +1 -0
- package/dist/layout/tidy-tree-layout.js +197 -0
- package/dist/layout/tidy-tree-layout.js.map +1 -0
- package/dist/layout/treemap-layout.d.ts +54 -0
- package/dist/layout/treemap-layout.d.ts.map +1 -0
- package/dist/layout/treemap-layout.js +121 -0
- package/dist/layout/treemap-layout.js.map +1 -0
- package/dist/layout/types.d.ts +90 -0
- package/dist/layout/types.d.ts.map +1 -0
- package/dist/layout/types.js +2 -0
- package/dist/layout/types.js.map +1 -0
- package/package.json +66 -3
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { WorkBudget } from "@ac-kit/core";
|
|
2
|
+
import type { IndexGraph } from "./_index-graph.js";
|
|
3
|
+
/**
|
|
4
|
+
* Ranks every node on the longest path to a sink: rank(v) = L − (length of the
|
|
5
|
+
* longest path from v to a sink), where a link spans at least its minimum
|
|
6
|
+
* length and L is the longest path of the graph. Sinks, and the nodes with no
|
|
7
|
+
* link, sit on the last rank L; the ranks start at 0. The same result as
|
|
8
|
+
* dagre's `longestPath` ranker followed by its normalisation.
|
|
9
|
+
*
|
|
10
|
+
* `reversed` flags the links to read backward (the output of
|
|
11
|
+
* `findReversedLinks`); self-loops are ignored.
|
|
12
|
+
*
|
|
13
|
+
* Complexity: O(V + E) time and memory.
|
|
14
|
+
*
|
|
15
|
+
* @param minLengths Per link, a positive integer (default 1).
|
|
16
|
+
* @throws {RangeError} The graph is still cyclic once `reversed` is applied.
|
|
17
|
+
*/
|
|
18
|
+
export declare function longestPathRanks(graph: IndexGraph, reversed: ArrayLike<number>, minLengths?: ArrayLike<number>): Uint32Array;
|
|
19
|
+
/**
|
|
20
|
+
* Ranks that minimise Σ weight·(rank(head) − rank(tail)) subject to rank(head)
|
|
21
|
+
* − rank(tail) ≥ minLength for every link, by the network simplex method of
|
|
22
|
+
* Gansner, Koutsofios, North & Vo 1993 ("A Technique for Drawing Directed
|
|
23
|
+
* Graphs", §2): a feasible ranking from the longest path, a tight spanning tree
|
|
24
|
+
* (§2.3), then pivots: a tree link with a negative cut value leaves, the
|
|
25
|
+
* non-tree link of least slack across its cut enters, and the subtree below the
|
|
26
|
+
* leaving link shifts until that link is tight. The cut values come from
|
|
27
|
+
* subtree sums of out-weight minus in-weight over a depth-first numbering of
|
|
28
|
+
* the tree, recomputed after each pivot (§2.4 updates them incrementally). Ties
|
|
29
|
+
* break by link index, so the result is deterministic.
|
|
30
|
+
*
|
|
31
|
+
* Each weakly connected component is solved on its own and normalised to start
|
|
32
|
+
* at rank 0, so components share the ranks. `reversed` flags the links to read
|
|
33
|
+
* backward; self-loops are ignored. The minimum is unique in value, not in
|
|
34
|
+
* ranks.
|
|
35
|
+
*
|
|
36
|
+
* Complexity: a pivot is O(V + E); the number of pivots is not polynomially
|
|
37
|
+
* bounded in theory and near-linear in practice. The feasible tree costs up to
|
|
38
|
+
* O(V · (V + E)). O(V + E) memory.
|
|
39
|
+
*
|
|
40
|
+
* @param weights Per link, finite ≥ 0 (default 1); a zero-weight link only
|
|
41
|
+
* constrains.
|
|
42
|
+
* @param minLengths Per link, a positive integer (default 1).
|
|
43
|
+
* @param budget Charged V + E (of the component) for the tree and per pivot;
|
|
44
|
+
* whatever it throws propagates.
|
|
45
|
+
* @throws {RangeError} The graph is still cyclic once `reversed` is applied.
|
|
46
|
+
*/
|
|
47
|
+
export declare function networkSimplexRanks(graph: IndexGraph, reversed: ArrayLike<number>, weights?: ArrayLike<number>, minLengths?: ArrayLike<number>, budget?: WorkBudget): Uint32Array;
|
|
48
|
+
/**
|
|
49
|
+
* {@link networkSimplexRanks} as steps: yields right after each budget charge
|
|
50
|
+
* (feasible-tree round, pivot), so a runner can stop or give up the thread
|
|
51
|
+
* between them. Returns the ranks.
|
|
52
|
+
*/
|
|
53
|
+
export declare function networkSimplexRankSteps(graph: IndexGraph, reversed: ArrayLike<number>, weights?: ArrayLike<number>, minLengths?: ArrayLike<number>, budget?: WorkBudget): Generator<void, Uint32Array, undefined>;
|
|
54
|
+
//# sourceMappingURL=_layered-rank.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_layered-rank.d.ts","sourceRoot":"","sources":["../../src/layout/_layered-rank.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAI/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAIpD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAC/B,KAAK,EAAE,UAAU,EACjB,QAAQ,EAAE,SAAS,CAAC,MAAM,CAAC,EAC3B,UAAU,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,GAC5B,WAAW,CAsEb;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,mBAAmB,CAClC,KAAK,EAAE,UAAU,EACjB,QAAQ,EAAE,SAAS,CAAC,MAAM,CAAC,EAC3B,OAAO,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,EAC3B,UAAU,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,EAC9B,MAAM,CAAC,EAAE,UAAU,GACjB,WAAW,CAIb;AAED;;;;GAIG;AACH,wBAAiB,uBAAuB,CACvC,KAAK,EAAE,UAAU,EACjB,QAAQ,EAAE,SAAS,CAAC,MAAM,CAAC,EAC3B,OAAO,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,EAC3B,UAAU,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,EAC9B,MAAM,CAAC,EAAE,UAAU,GACjB,SAAS,CAAC,IAAI,EAAE,WAAW,EAAE,SAAS,CAAC,CAsFzC"}
|
|
@@ -0,0 +1,436 @@
|
|
|
1
|
+
import { groupIndices } from "@ac-kit/algo";
|
|
2
|
+
import { runToCompletion } from "@ac-kit/core";
|
|
3
|
+
import { StaticDisjointSet } from "@ac-kit/data";
|
|
4
|
+
const MAX_RANK_ = 4294967295;
|
|
5
|
+
/**
|
|
6
|
+
* Ranks every node on the longest path to a sink: rank(v) = L − (length of the
|
|
7
|
+
* longest path from v to a sink), where a link spans at least its minimum
|
|
8
|
+
* length and L is the longest path of the graph. Sinks, and the nodes with no
|
|
9
|
+
* link, sit on the last rank L; the ranks start at 0. The same result as
|
|
10
|
+
* dagre's `longestPath` ranker followed by its normalisation.
|
|
11
|
+
*
|
|
12
|
+
* `reversed` flags the links to read backward (the output of
|
|
13
|
+
* `findReversedLinks`); self-loops are ignored.
|
|
14
|
+
*
|
|
15
|
+
* Complexity: O(V + E) time and memory.
|
|
16
|
+
*
|
|
17
|
+
* @param minLengths Per link, a positive integer (default 1).
|
|
18
|
+
* @throws {RangeError} The graph is still cyclic once `reversed` is applied.
|
|
19
|
+
*/
|
|
20
|
+
export function longestPathRanks(graph, reversed, minLengths) {
|
|
21
|
+
const { nodeCount, linkCount, sources, targets } = graph;
|
|
22
|
+
const tails = new Int32Array(linkCount);
|
|
23
|
+
const heads = new Int32Array(linkCount);
|
|
24
|
+
for (let link = 0; link < linkCount; link++) {
|
|
25
|
+
const flipped = reversed[link] === 1;
|
|
26
|
+
const tail = flipped ? targets[link] : sources[link];
|
|
27
|
+
const head = flipped ? sources[link] : targets[link];
|
|
28
|
+
const loop = tail === head;
|
|
29
|
+
tails[link] = loop ? -1 : tail;
|
|
30
|
+
heads[link] = loop ? -1 : head;
|
|
31
|
+
}
|
|
32
|
+
const out = groupIndices(tails, (tail) => tail, nodeCount);
|
|
33
|
+
const inDegrees = new Uint32Array(nodeCount);
|
|
34
|
+
for (let link = 0; link < linkCount; link++) {
|
|
35
|
+
if (heads[link] >= 0) {
|
|
36
|
+
inDegrees[heads[link]]++;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const order = new Uint32Array(nodeCount);
|
|
40
|
+
let ordered = 0;
|
|
41
|
+
for (let node = 0; node < nodeCount; node++) {
|
|
42
|
+
if (inDegrees[node] === 0) {
|
|
43
|
+
order[ordered++] = node;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
for (let at = 0; at < ordered; at++) {
|
|
47
|
+
const node = order[at];
|
|
48
|
+
for (let item = out.offsets[node]; item < out.offsets[node + 1]; item++) {
|
|
49
|
+
const head = heads[out.indices[item]];
|
|
50
|
+
if (--inDegrees[head] === 0) {
|
|
51
|
+
order[ordered++] = head;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (ordered < nodeCount) {
|
|
56
|
+
throw new RangeError("longestPathRanks: the links still contain a cycle");
|
|
57
|
+
}
|
|
58
|
+
// Longest path from each node down to a sink, filled in reverse topological order.
|
|
59
|
+
const lengths = new Float64Array(nodeCount);
|
|
60
|
+
let longest = 0;
|
|
61
|
+
for (let at = nodeCount - 1; at >= 0; at--) {
|
|
62
|
+
const node = order[at];
|
|
63
|
+
let length = 0;
|
|
64
|
+
for (let item = out.offsets[node]; item < out.offsets[node + 1]; item++) {
|
|
65
|
+
const link = out.indices[item];
|
|
66
|
+
const reach = lengths[heads[link]] + (minLengths?.[link] ?? 1);
|
|
67
|
+
if (reach > length) {
|
|
68
|
+
length = reach;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
lengths[node] = length;
|
|
72
|
+
if (length > longest) {
|
|
73
|
+
longest = length;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (longest > MAX_RANK_) {
|
|
77
|
+
throw new RangeError(`longestPathRanks: the longest path (${longest}) does not fit a 32-bit rank; reduce the minimum lengths`);
|
|
78
|
+
}
|
|
79
|
+
const ranks = new Uint32Array(nodeCount);
|
|
80
|
+
for (let node = 0; node < nodeCount; node++) {
|
|
81
|
+
ranks[node] = longest - lengths[node];
|
|
82
|
+
}
|
|
83
|
+
return ranks;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Ranks that minimise Σ weight·(rank(head) − rank(tail)) subject to rank(head)
|
|
87
|
+
* − rank(tail) ≥ minLength for every link, by the network simplex method of
|
|
88
|
+
* Gansner, Koutsofios, North & Vo 1993 ("A Technique for Drawing Directed
|
|
89
|
+
* Graphs", §2): a feasible ranking from the longest path, a tight spanning tree
|
|
90
|
+
* (§2.3), then pivots: a tree link with a negative cut value leaves, the
|
|
91
|
+
* non-tree link of least slack across its cut enters, and the subtree below the
|
|
92
|
+
* leaving link shifts until that link is tight. The cut values come from
|
|
93
|
+
* subtree sums of out-weight minus in-weight over a depth-first numbering of
|
|
94
|
+
* the tree, recomputed after each pivot (§2.4 updates them incrementally). Ties
|
|
95
|
+
* break by link index, so the result is deterministic.
|
|
96
|
+
*
|
|
97
|
+
* Each weakly connected component is solved on its own and normalised to start
|
|
98
|
+
* at rank 0, so components share the ranks. `reversed` flags the links to read
|
|
99
|
+
* backward; self-loops are ignored. The minimum is unique in value, not in
|
|
100
|
+
* ranks.
|
|
101
|
+
*
|
|
102
|
+
* Complexity: a pivot is O(V + E); the number of pivots is not polynomially
|
|
103
|
+
* bounded in theory and near-linear in practice. The feasible tree costs up to
|
|
104
|
+
* O(V · (V + E)). O(V + E) memory.
|
|
105
|
+
*
|
|
106
|
+
* @param weights Per link, finite ≥ 0 (default 1); a zero-weight link only
|
|
107
|
+
* constrains.
|
|
108
|
+
* @param minLengths Per link, a positive integer (default 1).
|
|
109
|
+
* @param budget Charged V + E (of the component) for the tree and per pivot;
|
|
110
|
+
* whatever it throws propagates.
|
|
111
|
+
* @throws {RangeError} The graph is still cyclic once `reversed` is applied.
|
|
112
|
+
*/
|
|
113
|
+
export function networkSimplexRanks(graph, reversed, weights, minLengths, budget) {
|
|
114
|
+
return runToCompletion(networkSimplexRankSteps(graph, reversed, weights, minLengths, budget));
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* {@link networkSimplexRanks} as steps: yields right after each budget charge
|
|
118
|
+
* (feasible-tree round, pivot), so a runner can stop or give up the thread
|
|
119
|
+
* between them. Returns the ranks.
|
|
120
|
+
*/
|
|
121
|
+
export function* networkSimplexRankSteps(graph, reversed, weights, minLengths, budget) {
|
|
122
|
+
const { nodeCount, linkCount, sources, targets } = graph;
|
|
123
|
+
const initial = longestPathRanks(graph, reversed, minLengths);
|
|
124
|
+
const ranks = Float64Array.from(initial);
|
|
125
|
+
const tails = new Int32Array(linkCount);
|
|
126
|
+
const heads = new Int32Array(linkCount);
|
|
127
|
+
for (let link = 0; link < linkCount; link++) {
|
|
128
|
+
const flipped = reversed[link] === 1;
|
|
129
|
+
const tail = flipped ? targets[link] : sources[link];
|
|
130
|
+
const head = flipped ? sources[link] : targets[link];
|
|
131
|
+
const loop = tail === head;
|
|
132
|
+
tails[link] = loop ? -1 : tail;
|
|
133
|
+
heads[link] = loop ? -1 : head;
|
|
134
|
+
}
|
|
135
|
+
const out = groupIndices(tails, (tail) => tail, nodeCount);
|
|
136
|
+
const into = groupIndices(heads, (head) => head, nodeCount);
|
|
137
|
+
const sets = new StaticDisjointSet();
|
|
138
|
+
for (let node = 0; node < nodeCount; node++) {
|
|
139
|
+
sets.makeSet(node);
|
|
140
|
+
}
|
|
141
|
+
for (let link = 0; link < linkCount; link++) {
|
|
142
|
+
if (tails[link] >= 0) {
|
|
143
|
+
sets.union(tails[link], heads[link]);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
// Component ids follow the first node of each component, in input order.
|
|
147
|
+
const componentOf = new Int32Array(nodeCount);
|
|
148
|
+
const idOfRepresentative = new Map();
|
|
149
|
+
for (let node = 0; node < nodeCount; node++) {
|
|
150
|
+
const representative = sets.find(node);
|
|
151
|
+
let id = idOfRepresentative.get(representative);
|
|
152
|
+
if (id === undefined) {
|
|
153
|
+
id = idOfRepresentative.size;
|
|
154
|
+
idOfRepresentative.set(representative, id);
|
|
155
|
+
}
|
|
156
|
+
componentOf[node] = id;
|
|
157
|
+
}
|
|
158
|
+
const componentCount = idOfRepresentative.size;
|
|
159
|
+
const linkComponents = new Int32Array(linkCount);
|
|
160
|
+
for (let link = 0; link < linkCount; link++) {
|
|
161
|
+
linkComponents[link] = tails[link] < 0 ? -1 : componentOf[tails[link]];
|
|
162
|
+
}
|
|
163
|
+
const nodesByComponent = groupIndices(componentOf, (component) => component, componentCount);
|
|
164
|
+
const linksByComponent = groupIndices(linkComponents, (component) => component, componentCount);
|
|
165
|
+
const solver = new ComponentSolver_(ranks, tails, heads, out, into, weights, minLengths, budget);
|
|
166
|
+
for (let component = 0; component < componentCount; component++) {
|
|
167
|
+
yield* solver.solve(nodesByComponent.indices.subarray(nodesByComponent.offsets[component], nodesByComponent.offsets[component + 1]), linksByComponent.indices.subarray(linksByComponent.offsets[component], linksByComponent.offsets[component + 1]));
|
|
168
|
+
}
|
|
169
|
+
for (const rank of ranks) {
|
|
170
|
+
if (rank > MAX_RANK_) {
|
|
171
|
+
throw new RangeError(`networkSimplexRanks: a rank (${rank}) does not fit 32 bits; reduce the minimum lengths`);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return Uint32Array.from(ranks);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Network simplex over one connected component at a time; scratch is shared
|
|
178
|
+
* across components.
|
|
179
|
+
*/
|
|
180
|
+
class ComponentSolver_ {
|
|
181
|
+
ranks;
|
|
182
|
+
tails;
|
|
183
|
+
heads;
|
|
184
|
+
out;
|
|
185
|
+
into;
|
|
186
|
+
weights;
|
|
187
|
+
minLengths;
|
|
188
|
+
budget;
|
|
189
|
+
inTree;
|
|
190
|
+
inTreeNode;
|
|
191
|
+
parentLinks;
|
|
192
|
+
low;
|
|
193
|
+
lim;
|
|
194
|
+
cursors;
|
|
195
|
+
stack;
|
|
196
|
+
subtreeBalances;
|
|
197
|
+
cutValues;
|
|
198
|
+
/**
|
|
199
|
+
* Per tree link, the rounding error bound of its cut value: a few ulps of the
|
|
200
|
+
* sum of the absolute weights it adds up. Integer weights below 2⁵³ add
|
|
201
|
+
* exactly, and the bound stays under 1 where it could hide a cut of −1.
|
|
202
|
+
*/
|
|
203
|
+
cutTolerances;
|
|
204
|
+
subtreeMagnitudes;
|
|
205
|
+
constructor(ranks, tails, heads, out, into, weights, minLengths, budget) {
|
|
206
|
+
this.ranks = ranks;
|
|
207
|
+
this.tails = tails;
|
|
208
|
+
this.heads = heads;
|
|
209
|
+
this.out = out;
|
|
210
|
+
this.into = into;
|
|
211
|
+
this.weights = weights;
|
|
212
|
+
this.minLengths = minLengths;
|
|
213
|
+
this.budget = budget;
|
|
214
|
+
const nodeCount = ranks.length;
|
|
215
|
+
this.inTree = new Uint8Array(tails.length);
|
|
216
|
+
this.inTreeNode = new Uint8Array(nodeCount);
|
|
217
|
+
this.parentLinks = new Int32Array(nodeCount);
|
|
218
|
+
this.low = new Uint32Array(nodeCount);
|
|
219
|
+
this.lim = new Uint32Array(nodeCount);
|
|
220
|
+
this.cursors = new Uint32Array(nodeCount);
|
|
221
|
+
this.stack = new Uint32Array(nodeCount);
|
|
222
|
+
this.subtreeBalances = new Float64Array(nodeCount);
|
|
223
|
+
this.cutValues = new Float64Array(tails.length);
|
|
224
|
+
this.cutTolerances = new Float64Array(tails.length);
|
|
225
|
+
this.subtreeMagnitudes = new Float64Array(nodeCount);
|
|
226
|
+
}
|
|
227
|
+
*solve(nodes, links) {
|
|
228
|
+
if (nodes.length < 2) {
|
|
229
|
+
this.ranks[nodes[0]] = 0;
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
const cost = nodes.length + links.length;
|
|
233
|
+
this.budget?.spend(cost);
|
|
234
|
+
yield;
|
|
235
|
+
yield* this.growFeasibleTree(nodes, links, cost);
|
|
236
|
+
for (;;) {
|
|
237
|
+
this.budget?.spend(cost);
|
|
238
|
+
yield;
|
|
239
|
+
this.numberTree(nodes);
|
|
240
|
+
let leaving = -1;
|
|
241
|
+
for (const link of links) {
|
|
242
|
+
if (this.inTree[link] === 1 &&
|
|
243
|
+
this.cutValues[link] < -this.cutTolerances[link]) {
|
|
244
|
+
leaving = link;
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
if (leaving < 0) {
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
const tail = this.tails[leaving];
|
|
252
|
+
const child = this.parentLinks[tail] === leaving ? tail : this.heads[leaving];
|
|
253
|
+
const low = this.low[child];
|
|
254
|
+
const lim = this.lim[child];
|
|
255
|
+
const inChildSide = (node) => this.lim[node] >= low && this.lim[node] <= lim;
|
|
256
|
+
// The entering link crosses the cut against the leaving link.
|
|
257
|
+
const childIsTail = child === tail;
|
|
258
|
+
let entering = -1;
|
|
259
|
+
let enteringSlack = Infinity;
|
|
260
|
+
for (const link of links) {
|
|
261
|
+
if (this.inTree[link] === 1) {
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
const tailInside = inChildSide(this.tails[link]);
|
|
265
|
+
const headInside = inChildSide(this.heads[link]);
|
|
266
|
+
if (childIsTail ? !tailInside && headInside : tailInside && !headInside) {
|
|
267
|
+
const slack = this.slackOf(link);
|
|
268
|
+
if (slack < enteringSlack) {
|
|
269
|
+
enteringSlack = slack;
|
|
270
|
+
entering = link;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
if (entering < 0) {
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
277
|
+
const shift = childIsTail ? -enteringSlack : enteringSlack;
|
|
278
|
+
if (shift !== 0) {
|
|
279
|
+
for (const node of nodes) {
|
|
280
|
+
if (inChildSide(node)) {
|
|
281
|
+
this.ranks[node] += shift;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
this.inTree[leaving] = 0;
|
|
286
|
+
this.inTree[entering] = 1;
|
|
287
|
+
}
|
|
288
|
+
let minimum = Infinity;
|
|
289
|
+
for (const node of nodes) {
|
|
290
|
+
minimum = Math.min(minimum, this.ranks[node]);
|
|
291
|
+
}
|
|
292
|
+
for (const node of nodes) {
|
|
293
|
+
this.ranks[node] -= minimum;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
weightOf(link) {
|
|
297
|
+
return this.weights?.[link] ?? 1;
|
|
298
|
+
}
|
|
299
|
+
slackOf(link) {
|
|
300
|
+
return (this.ranks[this.heads[link]] -
|
|
301
|
+
this.ranks[this.tails[link]] -
|
|
302
|
+
(this.minLengths?.[link] ?? 1));
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Gansner et al. §2.3: grow a tree of tight links, shifting it by the least
|
|
306
|
+
* slack to reach more nodes.
|
|
307
|
+
*/
|
|
308
|
+
*growFeasibleTree(nodes, links, cost) {
|
|
309
|
+
for (const node of nodes) {
|
|
310
|
+
this.inTreeNode[node] = 0;
|
|
311
|
+
}
|
|
312
|
+
for (const link of links) {
|
|
313
|
+
this.inTree[link] = 0;
|
|
314
|
+
}
|
|
315
|
+
const treeNodes = [nodes[0]];
|
|
316
|
+
this.inTreeNode[nodes[0]] = 1;
|
|
317
|
+
this.expandTightTree(nodes[0], treeNodes);
|
|
318
|
+
while (treeNodes.length < nodes.length) {
|
|
319
|
+
// Each round rescans every link and may shift the whole tree.
|
|
320
|
+
this.budget?.spend(cost);
|
|
321
|
+
yield;
|
|
322
|
+
let best = -1;
|
|
323
|
+
let bestSlack = Infinity;
|
|
324
|
+
for (const link of links) {
|
|
325
|
+
const tailIn = this.inTreeNode[this.tails[link]] === 1;
|
|
326
|
+
const headIn = this.inTreeNode[this.heads[link]] === 1;
|
|
327
|
+
if (tailIn !== headIn) {
|
|
328
|
+
const slack = this.slackOf(link);
|
|
329
|
+
if (slack < bestSlack) {
|
|
330
|
+
bestSlack = slack;
|
|
331
|
+
best = link;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
const tailIn = this.inTreeNode[this.tails[best]] === 1;
|
|
336
|
+
const shift = tailIn ? bestSlack : -bestSlack;
|
|
337
|
+
if (shift !== 0) {
|
|
338
|
+
for (const node of treeNodes) {
|
|
339
|
+
this.ranks[node] += shift;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
const added = tailIn ? this.heads[best] : this.tails[best];
|
|
343
|
+
this.inTree[best] = 1;
|
|
344
|
+
this.inTreeNode[added] = 1;
|
|
345
|
+
treeNodes.push(added);
|
|
346
|
+
this.expandTightTree(added, treeNodes);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
expandTightTree(start, treeNodes) {
|
|
350
|
+
const stack = [start];
|
|
351
|
+
while (stack.length > 0) {
|
|
352
|
+
const node = stack.pop();
|
|
353
|
+
for (const csr of [this.out, this.into]) {
|
|
354
|
+
for (let item = csr.offsets[node]; item < csr.offsets[node + 1]; item++) {
|
|
355
|
+
const link = csr.indices[item];
|
|
356
|
+
const other = this.tails[link] === node ? this.heads[link] : this.tails[link];
|
|
357
|
+
if (this.inTreeNode[other] === 0 && this.slackOf(link) === 0) {
|
|
358
|
+
this.inTreeNode[other] = 1;
|
|
359
|
+
this.inTree[link] = 1;
|
|
360
|
+
treeNodes.push(other);
|
|
361
|
+
stack.push(other);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Depth-first numbering of the tree from the first node: `low`/`lim` bound
|
|
369
|
+
* each subtree's post-order numbers, and the cut value of each tree link is
|
|
370
|
+
* the subtree's total out-weight minus in-weight, negated when the child is
|
|
371
|
+
* the link's head (links inside the subtree cancel).
|
|
372
|
+
*/
|
|
373
|
+
numberTree(nodes) {
|
|
374
|
+
const { out, into, tails, heads, stack, cursors, parentLinks } = this;
|
|
375
|
+
for (const node of nodes) {
|
|
376
|
+
this.subtreeBalances[node] = 0;
|
|
377
|
+
this.subtreeMagnitudes[node] = 0;
|
|
378
|
+
}
|
|
379
|
+
for (const csr of [out, into]) {
|
|
380
|
+
const sign = csr === out ? 1 : -1;
|
|
381
|
+
for (const node of nodes) {
|
|
382
|
+
for (let item = csr.offsets[node]; item < csr.offsets[node + 1]; item++) {
|
|
383
|
+
const weight = this.weightOf(csr.indices[item]);
|
|
384
|
+
this.subtreeBalances[node] += sign * weight;
|
|
385
|
+
this.subtreeMagnitudes[node] += weight;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
let counter = 0;
|
|
390
|
+
let depth = 0;
|
|
391
|
+
const root = nodes[0];
|
|
392
|
+
stack[depth++] = root;
|
|
393
|
+
parentLinks[root] = -1;
|
|
394
|
+
cursors[root] = 0;
|
|
395
|
+
this.low[root] = 1;
|
|
396
|
+
while (depth > 0) {
|
|
397
|
+
const node = stack[depth - 1];
|
|
398
|
+
const outCount = out.offsets[node + 1] - out.offsets[node];
|
|
399
|
+
const total = outCount + (into.offsets[node + 1] - into.offsets[node]);
|
|
400
|
+
let descended = false;
|
|
401
|
+
while (cursors[node] < total) {
|
|
402
|
+
const cursor = cursors[node]++;
|
|
403
|
+
const link = cursor < outCount
|
|
404
|
+
? out.indices[out.offsets[node] + cursor]
|
|
405
|
+
: into.indices[into.offsets[node] + cursor - outCount];
|
|
406
|
+
if (this.inTree[link] === 0 || link === parentLinks[node]) {
|
|
407
|
+
continue;
|
|
408
|
+
}
|
|
409
|
+
const child = tails[link] === node ? heads[link] : tails[link];
|
|
410
|
+
parentLinks[child] = link;
|
|
411
|
+
cursors[child] = 0;
|
|
412
|
+
this.low[child] = counter + 1;
|
|
413
|
+
stack[depth++] = child;
|
|
414
|
+
descended = true;
|
|
415
|
+
break;
|
|
416
|
+
}
|
|
417
|
+
if (descended) {
|
|
418
|
+
continue;
|
|
419
|
+
}
|
|
420
|
+
this.lim[node] = ++counter;
|
|
421
|
+
depth--;
|
|
422
|
+
const parentLink = parentLinks[node];
|
|
423
|
+
if (parentLink >= 0) {
|
|
424
|
+
const balance = this.subtreeBalances[node];
|
|
425
|
+
const parent = tails[parentLink] === node ? heads[parentLink] : tails[parentLink];
|
|
426
|
+
this.cutValues[parentLink] =
|
|
427
|
+
tails[parentLink] === node ? balance : -balance;
|
|
428
|
+
this.subtreeBalances[parent] += balance;
|
|
429
|
+
this.cutTolerances[parentLink] =
|
|
430
|
+
8 * Number.EPSILON * this.subtreeMagnitudes[node];
|
|
431
|
+
this.subtreeMagnitudes[parent] += this.subtreeMagnitudes[node];
|
|
432
|
+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iBAAiB,CAAC,IAAI,CAAE,CAAC;gBACpD,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAE,IAAI,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAE,CAAC;YAClE,CAAC;QACF,CAAC;IACF,CAAC;CACD"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { HierarchyTable, TreeSizeOptions, TreeTraits } from "./types.js";
|
|
2
|
+
/** Siblings 1 apart, other neighbours 2 (the Reingold–Tilford convention). */
|
|
3
|
+
export declare function defaultSeparation<TNode>(a: number, b: number, table: HierarchyTable<TNode>): number;
|
|
4
|
+
/**
|
|
5
|
+
* `traits.separationOf` (or the default) wrapped to refuse a result that is not
|
|
6
|
+
* finite and > 0, naming the two rows.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createCheckedSeparation<TNode>(table: HierarchyTable<TNode>, separationOf: TreeTraits<TNode>["separationOf"], functionName: string): (a: number, b: number) => number;
|
|
9
|
+
export type ResolvedTreeSize = {
|
|
10
|
+
/**
|
|
11
|
+
* True for per-node spacing (`nodeWidth`/`nodeHeight`), false for a layout
|
|
12
|
+
* box.
|
|
13
|
+
*/
|
|
14
|
+
readonly isPerNode: boolean;
|
|
15
|
+
readonly horizontal: number;
|
|
16
|
+
readonly vertical: number;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Reads the box or per-node spacing of a tree layout.
|
|
20
|
+
*
|
|
21
|
+
* @throws {RangeError} A size that is not finite and > 0, a box mixed with a
|
|
22
|
+
* spacing, or only one of `nodeWidth` and `nodeHeight`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function resolveTreeSize(options: TreeSizeOptions, functionName: string): ResolvedTreeSize;
|
|
25
|
+
export type SiblingLinks = {
|
|
26
|
+
/** −1 for a leaf. */
|
|
27
|
+
readonly firstChild: Int32Array;
|
|
28
|
+
readonly lastChild: Int32Array;
|
|
29
|
+
/** −1 for a first child (and the root). */
|
|
30
|
+
readonly previousSibling: Int32Array;
|
|
31
|
+
readonly nextSibling: Int32Array;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* First/last child and neighbouring siblings per row, from the pre-order parent
|
|
35
|
+
* column. O(n).
|
|
36
|
+
*/
|
|
37
|
+
export declare function buildSiblingLinks(parentIndices: Int32Array): SiblingLinks;
|
|
38
|
+
//# sourceMappingURL=_tree-common.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_tree-common.d.ts","sourceRoot":"","sources":["../../src/layout/_tree-common.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE9E,8EAA8E;AAC9E,wBAAgB,iBAAiB,CAAC,KAAK,EACtC,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,KAAK,EAAE,cAAc,CAAC,KAAK,CAAC,GAC1B,MAAM,CAER;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAC5C,KAAK,EAAE,cAAc,CAAC,KAAK,CAAC,EAC5B,YAAY,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC,cAAc,CAAC,EAC/C,YAAY,EAAE,MAAM,GAClB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,MAAM,CAWlC;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC9B;;;OAGG;IACH,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,eAAe,CAC9B,OAAO,EAAE,eAAe,EACxB,YAAY,EAAE,MAAM,GAClB,gBAAgB,CAiClB;AAED,MAAM,MAAM,YAAY,GAAG;IAC1B,qBAAqB;IACrB,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC;IAC/B,2CAA2C;IAC3C,QAAQ,CAAC,eAAe,EAAE,UAAU,CAAC;IACrC,QAAQ,CAAC,WAAW,EAAE,UAAU,CAAC;CACjC,CAAC;AAEF;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,aAAa,EAAE,UAAU,GAAG,YAAY,CAoBzE"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { assertPositive, describeValue } from "@ac-kit/core";
|
|
2
|
+
/** Siblings 1 apart, other neighbours 2 (the Reingold–Tilford convention). */
|
|
3
|
+
export function defaultSeparation(a, b, table) {
|
|
4
|
+
return table.parentIndices[a] === table.parentIndices[b] ? 1 : 2;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* `traits.separationOf` (or the default) wrapped to refuse a result that is not
|
|
8
|
+
* finite and > 0, naming the two rows.
|
|
9
|
+
*/
|
|
10
|
+
export function createCheckedSeparation(table, separationOf, functionName) {
|
|
11
|
+
const read = separationOf ?? defaultSeparation;
|
|
12
|
+
return (a, b) => {
|
|
13
|
+
const separation = read(a, b, table);
|
|
14
|
+
if (!(Number.isFinite(separation) && separation > 0)) {
|
|
15
|
+
throw new RangeError(`${functionName}: separation of rows ${a} and ${b} must be finite and positive, got ${describeValue(separation)}`);
|
|
16
|
+
}
|
|
17
|
+
return separation;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Reads the box or per-node spacing of a tree layout.
|
|
22
|
+
*
|
|
23
|
+
* @throws {RangeError} A size that is not finite and > 0, a box mixed with a
|
|
24
|
+
* spacing, or only one of `nodeWidth` and `nodeHeight`.
|
|
25
|
+
*/
|
|
26
|
+
export function resolveTreeSize(options, functionName) {
|
|
27
|
+
const { width, height, nodeWidth, nodeHeight } = options;
|
|
28
|
+
if (nodeWidth !== undefined || nodeHeight !== undefined) {
|
|
29
|
+
if (width !== undefined || height !== undefined) {
|
|
30
|
+
throw new RangeError(`${functionName}: width/height and nodeWidth/nodeHeight are mutually exclusive`);
|
|
31
|
+
}
|
|
32
|
+
if (nodeWidth === undefined || nodeHeight === undefined) {
|
|
33
|
+
throw new RangeError(`${functionName}: nodeWidth and nodeHeight go together`);
|
|
34
|
+
}
|
|
35
|
+
assertPositive(nodeWidth, `${functionName}: nodeWidth`);
|
|
36
|
+
assertPositive(nodeHeight, `${functionName}: nodeHeight`);
|
|
37
|
+
return { isPerNode: true, horizontal: nodeWidth, vertical: nodeHeight };
|
|
38
|
+
}
|
|
39
|
+
const resolvedWidth = width ?? 1;
|
|
40
|
+
const resolvedHeight = height ?? 1;
|
|
41
|
+
assertPositive(resolvedWidth, `${functionName}: width`);
|
|
42
|
+
assertPositive(resolvedHeight, `${functionName}: height`);
|
|
43
|
+
return {
|
|
44
|
+
isPerNode: false,
|
|
45
|
+
horizontal: resolvedWidth,
|
|
46
|
+
vertical: resolvedHeight,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* First/last child and neighbouring siblings per row, from the pre-order parent
|
|
51
|
+
* column. O(n).
|
|
52
|
+
*/
|
|
53
|
+
export function buildSiblingLinks(parentIndices) {
|
|
54
|
+
const count = parentIndices.length;
|
|
55
|
+
const firstChild = new Int32Array(count).fill(-1);
|
|
56
|
+
const lastChild = new Int32Array(count).fill(-1);
|
|
57
|
+
const previousSibling = new Int32Array(count).fill(-1);
|
|
58
|
+
const nextSibling = new Int32Array(count).fill(-1);
|
|
59
|
+
for (let row = 1; row < count; row++) {
|
|
60
|
+
const parent = parentIndices[row];
|
|
61
|
+
const previous = lastChild[parent];
|
|
62
|
+
if (previous < 0) {
|
|
63
|
+
firstChild[parent] = row;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
previousSibling[row] = previous;
|
|
67
|
+
nextSibling[previous] = row;
|
|
68
|
+
}
|
|
69
|
+
lastChild[parent] = row;
|
|
70
|
+
}
|
|
71
|
+
return { firstChild, lastChild, previousSibling, nextSibling };
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=_tree-common.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_tree-common.js","sourceRoot":"","sources":["../../src/layout/_tree-common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAI7D,8EAA8E;AAC9E,MAAM,UAAU,iBAAiB,CAChC,CAAS,EACT,CAAS,EACT,KAA4B;IAE5B,OAAO,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAClE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,uBAAuB,CACtC,KAA4B,EAC5B,YAA+C,EAC/C,YAAoB;IAEpB,MAAM,IAAI,GAAG,YAAY,IAAI,iBAAiB,CAAC;IAC/C,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QACf,MAAM,UAAU,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;QACrC,IAAI,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,UAAU,GAAG,CAAC,CAAC,EAAE,CAAC;YACtD,MAAM,IAAI,UAAU,CACnB,GAAG,YAAY,wBAAwB,CAAC,QAAQ,CAAC,qCAAqC,aAAa,CAAC,UAAU,CAAC,EAAE,CACjH,CAAC;QACH,CAAC;QACD,OAAO,UAAU,CAAC;IACnB,CAAC,CAAC;AACH,CAAC;AAYD;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAC9B,OAAwB,EACxB,YAAoB;IAEpB,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,OAKhD,CAAC;IAEF,IAAI,SAAS,KAAK,SAAS,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;QACzD,IAAI,KAAK,KAAK,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