<commit_before>require 'set'

class GraphMatrix
  attr_reader :edges
  
  def initialize
    @edges = {}
  end

  def set(v1, v2, weight)
    vertices = [v1, v2]
    @edges[vertices] << weight
  rescue NoMethodError
    # initializing the key to an array for the first entry
    (@edges[vertices] = []) << weight
  end

  def get(v1, v2)
    edges.fetch [v1, v2]
  rescue KeyError
    raise NoEdgeError, "No edge found between #{v1} and #{v2}!"
  end

  def get_min(v1, v2)
    get(v1, v2).min
  end

  def vertices
    @edges.keys.flatten.uniq.to_set
  end

  def adjacent?(v1, v2)
    @edges.keys.include? [v1, v2]
  end

  def neighbors(vertex)
    @edges.map { |k, v|
      k[1] if k[0] == vertex
    }.compact.to_set
  end

end # class GraphMatrix

class NoEdgeError < StandardError; end<commit_msg>minor<commit_after>require 'set'

class GraphMatrix
  attr_reader :edges
  
  def initialize
    @edges = {}
  end

  def set(v1, v2, weight)
    vertices = [v1, v2]
    @edges[vertices] << weight
  rescue NoMethodError
    # initializing the key to an array for the first entry
    (@edges[vertices] = []) << weight
  end

  def get(v1, v2)
    edges.fetch [v1, v2]
  rescue KeyError
    raise NoEdgeError, "No edge found between #{v1} and #{v2}!"
  end

  def get_min(v1, v2)
    get(v1, v2).min
  end

  def vertices
    edges.keys.flatten.uniq.to_set
  end

  def adjacent?(v1, v2)
    edges.keys.include? [v1, v2]
  end

  def neighbors(vertex)
    edges.map { |k, v|
      k[1] if k[0] == vertex
    }.compact.to_set
  end

end # class GraphMatrix

class NoEdgeError < StandardError; end
{'fraction_non_alphanumeric': 0.1158422041327489, 'fraction_numerical': 0.025046963055729492, 'mean_word_length': 2.8138424821002386, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7362107', 'n_tokens_mistral': 621, 'n_tokens_neox': 611, 'n_words': 173}