lib/networkx/multidigraph.rb
# Returns the size of the graph
#
# @example
#   graph.size(true)
#
# @param is_weighted [Bool] if true, method returns sum of weights of all edges
#                           else returns number of edges
Returns the size of the graph
Returns the size of the graph
def size(is_weighted=false)
      if is_weighted
        graph_size = 0
        @adj.each do |_, hash_val|
          hash_val.each { |_, v| v.each { |_, attrs| graph_size += attrs[:weight] if attrs.key?(:weight) } }
        end
        return graph_size
      end
      number_of_edges
    end
def size ( is_weighted = false ) if is_weighted graph_size = 0 @adj . each do | _ , hash_val | hash_val . each { | _ , v | v . each { | _ , attrs | graph_size += attrs [ :weight ] if attrs . key? ( :weight ) } } end return graph_size end number_of_edges end
Returns the size of the graph
Returns the size of the graph
is_weighted
if true, method returns sum of weights of all edges else returns number of edges
if true method returns sum of weights of all edges else returns number of edges
example
None