This repository was archived by the owner on Jun 18, 2026. It is now read-only.
Commit 7d2425c
committed
refactor(TopologicalSortAnalyzer): cache directed adjacency map and analysis result
TopologicalSortAnalyzer rebuilt the directed adjacency map (O(V+E)) in
every public method call — analyze(), analyzeDependencies(), countChoicePoints().
generateSummary() was worst: it called analyze() + countChoicePoints(), which
itself called analyze() again, resulting in 3× redundant O(V+E) traversals
and 3× redundant adjacency map constructions per summary generation.
Cache both buildDirectedAdj() and analyze() results as lazy instance fields.
Subsequent calls to any method reuse the cached structures instead of
recomputing from scratch.
Impact: generateSummary() drops from ~3× O(V+E) graph traversals to 1×.
analyzeDependencies() no longer rebuilds adjacency + re-runs full Kahn's
algorithm just to get the depth map.1 parent dd5dbfc commit 7d2425c
1 file changed
Lines changed: 15 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
36 | 42 | | |
37 | 43 | | |
38 | 44 | | |
| |||
188 | 194 | | |
189 | 195 | | |
190 | 196 | | |
191 | | - | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
192 | 201 | | |
193 | 202 | | |
194 | 203 | | |
| |||
206 | 215 | | |
207 | 216 | | |
208 | 217 | | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
209 | 221 | | |
210 | 222 | | |
211 | 223 | | |
| |||
301 | 313 | | |
302 | 314 | | |
303 | 315 | | |
304 | | - | |
| 316 | + | |
305 | 317 | | |
306 | 318 | | |
| 319 | + | |
307 | 320 | | |
308 | 321 | | |
309 | 322 | | |
| |||
0 commit comments