<commit_before>class SumSum < Hash
  def initialize(*args)
    @parent = args.pop if args[-1].is_a?(self.class)
    @name = args.shift
    @args = args.compact.dup
    @count = 0
    super()
  end
  
  attr_reader :name, :args, :count, :parent
  
  def add(hash, increase_by=1)
    key = hash[name]
    @count = @count + increase_by
    unless bottom?
      self[key] ||= SumSum.new(*args, self)
      self[key].add(hash, increase_by)
    end
    self
  end
  
  def share
    root? ? 1.0 : count/parent.count.to_f
  end
  
  def sort!
    values.each(&:sort!) unless bottom?
    to_a.tap do |array|
      array.reverse!(&:count)
      clear
      array.each{|k, v| self[k] = v }
    end
    self
  end
  
  def root?
    parent.nil?
  end
  
  def bottom?
    name.nil?
  end
  
  def inspect
    bottom? ? "#{count}" : "{#{name}:#{count} #{super.gsub(/^\{|\}$/, "")}}"
  end
  
  def dump<commit_msg>Added pp support<commit_after>class SumSum < Hash
  def initialize(*args)
    @parent = args.pop if args[-1].is_a?(self.class)
    @name = args.shift
    @args = args.compact.dup
    @count = 0
    super()
  end
  
  attr_reader :name, :args, :count, :parent
  
  def add(hash, increase_by=1)
    key = hash[name]
    @count = @count + increase_by
    unless bottom?
      self[key] ||= SumSum.new(*args, self)
      self[key].add(hash, increase_by)
    end
    self
  end
  
  def share
    root? ? 1.0 : count/parent.count.to_f
  end
  
  def sort!
    values.each(&:sort!) unless bottom?
    to_a.tap do |array|
      array.reverse!(&:count)
      clear
      array.each{|k, v| self[k] = v }
    end
    self
  end
  
  def root?
    parent.nil?
  end
  
  def bottom?
    name.nil?
  end
  
  def inspect
    bottom? ? "#{count}" : "{#{name}:#{count} #{super.gsub(/^\{|\}$/, "")}}"
  end
  
  def pretty_print(pp)
    return pp.text(" #{count}") if bottom?
    super
  end
  
  def dump
{'fraction_non_alphanumeric': 0.15380549682875264, 'fraction_numerical': 0.005285412262156448, 'mean_word_length': 2.252577319587629, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4283088', 'n_tokens_mistral': 729, 'n_tokens_neox': 723, 'n_words': 170}