This repository was archived by the owner on Jun 18, 2026. It is now read-only.
Commit 8abb4c1
committed
refactor(graph-utils): extract subset-aware IndexedGraph ctor; dedupe in WienerIndexCalculator
WienerIndexCalculator carried its own private `buildAdjacency(n, idxMap)`
helper that materialised int[][] adjacency over a single component using
exactly the same `List<Integer>[] -> int[][]` pattern already in use by
NodeCentralityAnalyzer, RandomWalkAnalyzer, GraphIsomorphismChecker, and
GraphUtils.IndexedGraph itself. The duplication was an attractor for
bugs (any future change to the adjacency representation has to be made
in N places) and obscured the fact that WienerIndexCalculator's "build
indexed adjacency over the largest component" step is just an instance
of the general "indexed view restricted to a vertex subset" operation.
Changes:
* GraphUtils.IndexedGraph: add a second constructor that takes a
Collection<String> vertex subset and only includes edges with both
endpoints in the subset. Vertex order is preserved from the
collection's iteration order so callers can rely on stable integer
indices (matches what WienerIndexCalculator was doing manually).
* WienerIndexCalculator: replace the local `buildAdjacency` helper +
manual index map with a single `new GraphUtils.IndexedGraph(graph,
component)` call. Net deletion: ~25 lines.
No behaviour change. Verified with mvn -q -DskipTests compile (exit 0)
and a smoke test asserting Wiener(P5)=20, Wiener(K4)=6, Wiener(empty)=0
all match pre-refactor values.1 parent bb6574e commit 8abb4c1
2 files changed
Lines changed: 49 additions & 28 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
560 | 560 | | |
561 | 561 | | |
562 | 562 | | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
563 | 605 | | |
564 | 606 | | |
565 | 607 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
| |||
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | 183 | | |
205 | 184 | | |
206 | 185 | | |
| |||
0 commit comments