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

Commit cb9ccf7

Browse files
refactor: remove duplicated adjacency map building, use GraphUtils
code_cleanup: GraphIsomorphismAnalyzer had a private buildAdjacencyMap() method identical to GraphUtils.buildAdjacencyMap() — removed it and switched to the shared utility. MotifAnalyzer had an inline 8-line neighbor cache loop identical to GraphUtils — replaced with one-liner. Both changes reduce duplication and ensure consistent null-safety handling (GraphUtils checks for null neighbors). All 1009 tests pass (2 pre-existing InfluenceSpreadSimulator failures unchanged).
1 parent f097681 commit cb9ccf7

2 files changed

Lines changed: 3 additions & 19 deletions

File tree

Gvisual/src/gvisual/GraphIsomorphismAnalyzer.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ public IsomorphismResult analyze() {
150150
}
151151

152152
// Build adjacency sets for fast lookup
153-
Map<String, Set<String>> adj1 = buildAdjacencyMap(graph1);
154-
Map<String, Set<String>> adj2 = buildAdjacencyMap(graph2);
153+
Map<String, Set<String>> adj1 = GraphUtils.buildAdjacencyMap(graph1);
154+
Map<String, Set<String>> adj2 = GraphUtils.buildAdjacencyMap(graph2);
155155

156156
// Group vertices by degree for pruning
157157
Map<Integer, List<String>> byDegree1 = groupByDegree(graph1, vertices1);
@@ -209,14 +209,6 @@ private List<Integer> getSortedDegreeSequence(Graph<String, edge> g,
209209
/**
210210
* Build adjacency map: vertex → set of neighbors.
211211
*/
212-
private Map<String, Set<String>> buildAdjacencyMap(Graph<String, edge> g) {
213-
Map<String, Set<String>> adj = new HashMap<String, Set<String>>();
214-
for (String v : g.getVertices()) {
215-
adj.put(v, new HashSet<String>(g.getNeighbors(v)));
216-
}
217-
return adj;
218-
}
219-
220212
/**
221213
* Group vertices by their degree.
222214
*/

Gvisual/src/gvisual/MotifAnalyzer.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,7 @@ public MotifAnalyzer compute() {
9090
}
9191

9292
// Build neighbor cache for O(1) lookups
93-
neighborCache = new HashMap<String, Set<String>>(vertices.size() * 2);
94-
for (String v : vertices) {
95-
Collection<String> neighbors = graph.getNeighbors(v);
96-
Set<String> set = new HashSet<String>();
97-
if (neighbors != null) {
98-
set.addAll(neighbors);
99-
}
100-
neighborCache.put(v, set);
101-
}
93+
neighborCache = GraphUtils.buildAdjacencyMap(graph);
10294

10395
// Initialize participation counts
10496
for (String v : vertices) {

0 commit comments

Comments
 (0)