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

Commit 3a90814

Browse files
refactor: eliminate redundant adjacency map rebuilds in ChordalGraphAnalyzer
- analyze(): pass pre-computed adj to findMaxCliqueGreedy instead of calling the no-arg overload that rebuilds adjacency from scratch - minimalSeparators(): compute adj + MCS + PEO once and reuse, instead of calling allMaximalCliques() (which rebuilds both) and then buildCliqueTreeFromCliques separately Removes 2 redundant O(V+E) adjacency map constructions and 1 redundant O(V+E) MCS traversal per call.
1 parent 61ff9d1 commit 3a90814

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

Gvisual/src/gvisual/ChordalGraphAnalyzer.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,15 @@ public static FillInResult computeFillIn(Graph<String, Edge> graph) {
526526
* @return list of minimal separators
527527
*/
528528
public static List<Set<String>> minimalSeparators(Graph<String, Edge> graph) {
529-
List<Set<String>> cliques = allMaximalCliques(graph);
529+
if (graph == null || graph.getVertexCount() == 0) {
530+
return Collections.emptyList();
531+
}
532+
// Reuse a single adjacency map + MCS instead of rebuilding both
533+
// inside allMaximalCliques and again for the clique tree.
534+
Map<String, Set<String>> adj = GraphUtils.buildAdjacencyMap(graph);
535+
List<String> peo = maximumCardinalitySearch(graph, adj);
536+
Map<String, Integer> pos = buildPositionMap(peo);
537+
List<Set<String>> cliques = maximalCliquesFromPEO(peo, pos, adj);
530538
List<CliqueTreeNode> tree = buildCliqueTreeFromCliques(cliques);
531539
if (tree.size() <= 1) return Collections.emptyList();
532540

@@ -654,7 +662,7 @@ public static ChordalReport analyze(Graph<String, Edge> graph) {
654662
} else {
655663
fillIn = fillInFromMCS(mcsOrder, pos, adj);
656664
coloring = colorFromPEO(mcsOrder, adj);
657-
maxClique = findMaxCliqueGreedy(graph);
665+
maxClique = findMaxCliqueGreedy(graph, adj);
658666
}
659667

660668
return new ChordalReport(chordality, coloring, maxClique, maximalCliques,

0 commit comments

Comments
 (0)