Skip to content
This repository was archived by the owner on Jun 18, 2026. It is now read-only.

Commit a93a88a

Browse files
refactor: deduplicate PlanarGraphAnalyzer.countComponents → delegate to GraphUtils
PlanarGraphAnalyzer had a full 20-line BFS implementation of countComponents() that was functionally identical to GraphUtils.countComponents(). Replaced with a one-line delegation to the shared utility, eliminating duplicated graph traversal code. This follows the pattern already established by TreeAnalyzer, FeedbackVertexSetAnalyzer, and GraphSparsificationAnalyzer which all delegate to GraphUtils for component counting.
1 parent 5e8f2b2 commit a93a88a

1 file changed

Lines changed: 2 additions & 23 deletions

File tree

Gvisual/src/gvisual/PlanarGraphAnalyzer.java

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -467,30 +467,9 @@ private static boolean isTriangleFree(Map<String, Set<String>> adj) {
467467
return true;
468468
}
469469

470-
/** Count connected components via BFS. */
470+
/** Count connected components — delegates to shared GraphUtils implementation. */
471471
static int countComponents(Graph<String, Edge> graph) {
472-
Set<String> visited = new HashSet<String>();
473-
int count = 0;
474-
for (String v : graph.getVertices()) {
475-
if (visited.contains(v)) continue;
476-
count++;
477-
Queue<String> q = new ArrayDeque<String>();
478-
q.add(v);
479-
visited.add(v);
480-
while (!q.isEmpty()) {
481-
String curr = q.poll();
482-
Collection<String> nbrs = graph.getNeighbors(curr);
483-
if (nbrs != null) {
484-
for (String n : nbrs) {
485-
if (!visited.contains(n)) {
486-
visited.add(n);
487-
q.add(n);
488-
}
489-
}
490-
}
491-
}
492-
}
493-
return count;
472+
return GraphUtils.countComponents(graph);
494473
}
495474

496475
/**

0 commit comments

Comments
 (0)