Skip to content
This repository was archived by the owner on Jun 18, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Gvisual/src/gvisual/GrowthRateAnalyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,20 @@ private static double computeDensity(int nodes, int edges) {
private static double computeAvgClustering(Graph<String, edge> g) {
if (g.getVertexCount() == 0) return 0.0;

Map<String, Set<String>> adj = GraphUtils.buildAdjacencyMap(g);
double totalClustering = 0.0;
for (String v : g.getVertices()) {
Collection<String> neighbors = g.getNeighbors(v);
Set<String> neighbors = adj.get(v);
if (neighbors == null) continue;
List<String> neighborList = new ArrayList<>(neighbors);
int k = neighborList.size();
if (k < 2) continue;

int triangles = 0;
for (int i = 0; i < k; i++) {
Set<String> ni = adj.get(neighborList.get(i));
for (int j = i + 1; j < k; j++) {
if (g.isNeighbor(neighborList.get(i), neighborList.get(j))) {
if (ni != null && ni.contains(neighborList.get(j))) {
triangles++;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Gvisual/src/gvisual/NodeSimilarityAnalyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public NodeSimilarityAnalyzer(Graph<String, edge> graph) {
throw new IllegalArgumentException("Graph must not be null");
}
this.graph = graph;
this.neighborCache = new HashMap<String, Set<String>>();
this.neighborCache = GraphUtils.buildAdjacencyMap(graph);
}

// ── Single-pair metrics ─────────────────────────────────────
Expand Down
15 changes: 2 additions & 13 deletions Gvisual/src/gvisual/StructuralHoleAnalyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
public class StructuralHoleAnalyzer {

private final Graph<String, edge> graph;
private Map<String, Set<String>> neighborCache;
private final Map<String, Set<String>> neighborCache;

/**
* Creates a new StructuralHoleAnalyzer for the given graph.
Expand All @@ -64,18 +64,7 @@ public StructuralHoleAnalyzer(Graph<String, edge> graph) {
throw new IllegalArgumentException("Graph must not be null");
}
this.graph = graph;
buildNeighborCache();
}

private void buildNeighborCache() {
neighborCache = new HashMap<>();
for (String v : graph.getVertices()) {
Set<String> nbrs = new LinkedHashSet<>();
for (String n : graph.getNeighbors(v)) {
nbrs.add(n);
}
neighborCache.put(v, nbrs);
}
this.neighborCache = GraphUtils.buildAdjacencyMap(graph);
}

// ── Result classes ──────────────────────────────────────────
Expand Down
Loading