lib/rgraph/graph.rb in rgraph-0.0.12 vs lib/rgraph/graph.rb in rgraph-0.0.13

- old
+ new

@@ -199,9 +199,26 @@ while true return @page_rank if @page_rank.inject(:+) - step_page_rank(d, e).inject(:+) < e end end + def components + distances unless @distance + + @components = [] + + @distance.each do |d| + same = [] + d.each_with_index { |dist, i| same << @nodes[i] if dist != @infinity} + + #its a new component + if @components.select{ |c| c.include?(same.first) }.size == 0 + @components << same + end + end + @components + end + private def step_page_rank(d = 0.85, e = 0.01) n = @nodes.count tmp = Array.new(n, 0)