@@ -5,15 +5,14 @@ import (
55 "sync"
66
77 "github.com/elecbug/netkit/graph"
8- "github.com/elecbug/netkit/graph/node"
98)
109
1110// ClusteringCoefficientAll computes local clustering coefficients for all nodes.
1211// - If g.IsBidirectional()==false (directed): Fagiolo (2007) directed clustering (matches NetworkX).
1312// - If g.IsBidirectional()==true (undirected): standard undirected clustering.
14- // Returns map[node.ID ]float64 with a value for every node in g.
15- func ClusteringCoefficient (g * graph.Graph , cfg * Config ) map [node. ID ]float64 {
16- res := make (map [node. ID ]float64 )
13+ // Returns map[graph.NodeID ]float64 with a value for every node in g.
14+ func ClusteringCoefficient (g * graph.Graph , cfg * Config ) map [graph. NodeID ]float64 {
15+ res := make (map [graph. NodeID ]float64 )
1716 if g == nil {
1817 return res
1918 }
@@ -35,10 +34,10 @@ func ClusteringCoefficient(g *graph.Graph, cfg *Config) map[node.ID]float64 {
3534 // Build helper structures
3635 // outNeighbors[v] = slice of out-neighbors of v (exclude self)
3736 // inNeighbors[v] = slice of in-neighbors of v (exclude self) - only needed for directed
38- outNeighbors := make (map [node. ID ][]node. ID , n )
37+ outNeighbors := make (map [graph. NodeID ][]graph. NodeID , n )
3938 for _ , v := range nodes {
4039 ns := g .Neighbors (v )
41- buf := make ([]node. ID , 0 , len (ns ))
40+ buf := make ([]graph. NodeID , 0 , len (ns ))
4241 for _ , w := range ns {
4342 if w != v {
4443 buf = append (buf , w )
@@ -48,9 +47,9 @@ func ClusteringCoefficient(g *graph.Graph, cfg *Config) map[node.ID]float64 {
4847 }
4948
5049 isDirected := ! g .IsBidirectional ()
51- var inNeighbors map [node. ID ][]node. ID
50+ var inNeighbors map [graph. NodeID ][]graph. NodeID
5251 if isDirected {
53- inNeighbors = make (map [node. ID ][]node. ID , n )
52+ inNeighbors = make (map [graph. NodeID ][]graph. NodeID , n )
5453 for _ , u := range nodes {
5554 for _ , w := range outNeighbors [u ] {
5655 // u -> w, so u is in-neighbor of w
@@ -59,13 +58,13 @@ func ClusteringCoefficient(g *graph.Graph, cfg *Config) map[node.ID]float64 {
5958 }
6059 }
6160
62- type job struct { v node. ID }
61+ type job struct { v graph. NodeID }
6362 jobs := make (chan job , workers * 2 )
6463 var wg sync.WaitGroup
6564 var mu sync.Mutex // protects res map
6665
6766 // Edge multiplicity for Fagiolo: b(u,v) = a_uv + a_vu ∈ {0,1,2}
68- b := func (u , v node. ID ) int {
67+ b := func (u , v graph. NodeID ) int {
6968 sum := 0
7069
7170 if g .HasEdge (u , v ) {
@@ -98,7 +97,7 @@ func ClusteringCoefficient(g *graph.Graph, cfg *Config) map[node.ID]float64 {
9897 mu .Unlock ()
9998 continue
10099 }
101- outSet := make (map [node. ID ]struct {}, kOut )
100+ outSet := make (map [graph. NodeID ]struct {}, kOut )
102101 for _ , w := range outNeighbors [v ] {
103102 outSet [w ] = struct {}{}
104103 }
@@ -119,15 +118,15 @@ func ClusteringCoefficient(g *graph.Graph, cfg *Config) map[node.ID]float64 {
119118
120119 // T_v = sum_{j != k} b(v,j) * b(j,k) * b(k,v)
121120 // with j,k in tot = in(v) ∪ out(v)
122- totSet := make (map [node. ID ]struct {}, kTot ) // upper bound
121+ totSet := make (map [graph. NodeID ]struct {}, kTot ) // upper bound
123122 for _ , u := range outNeighbors [v ] {
124123 totSet [u ] = struct {}{}
125124 }
126125 for _ , u := range inNeighbors [v ] {
127126 totSet [u ] = struct {}{}
128127 }
129128 // Make a slice to iterate
130- tot := make ([]node. ID , 0 , len (totSet ))
129+ tot := make ([]graph. NodeID , 0 , len (totSet ))
131130 for u := range totSet {
132131 if u != v { // guard (shouldn't be in set anyway)
133132 tot = append (tot , u )
0 commit comments