Skip to content

Commit

Permalink
make AvgDegStats constructor more efficient
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebd99 committed Dec 20, 2023
1 parent 3cddc21 commit 600ed15
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions Source/DegreeStats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,17 @@ struct AvgDegStats <:DegreeStats
end

function AvgDegStats(g::DataGraph, edges::Vector{Tuple{NodeId, NodeId, Bool}}, color_size::Int)
length(edges) == 0 && return AvgDegStats(0,0)
in_counter = counter(NodeId)
out_counter = counter(NodeId)
in_edges = 0
out_edges = 0
for edge in edges
if edge[3]
inc!(out_counter, edge[1])
out_edges += 1
else
inc!(in_counter, edge[1])
in_edges += 1
end
end
avg_in = sum([x for x in values(in_counter)]; init=0)/color_size
avg_out = sum([x for x in values(out_counter)]; init=0)/color_size
avg_in = in_edges/color_size
avg_out = out_edges/color_size
return AvgDegStats(avg_in, avg_out)
end
get_in_deg_estimate(d::AvgDegStats) = d.avg_in
Expand Down

0 comments on commit 600ed15

Please sign in to comment.