<commit_before>module RMExtensions

  class StrongToWeakHash < Hash

    def [](key)
      if val = super
        val.value
      end
    end

    def []=(key, value)
      super(key, value.nil? ? nil : WeakHolder.new(value))
      value
    end

    def delete(key)
      if val = super
        val.value
      end
    end

    def keys
      out = []
      keys = [] + super
      while keys.size > 0
        key = keys.shift
        if val = self[key]
          out << key
        end
      end
      out
    end

    def values
      out = []
      values = [] + super
      while values.size > 0
        value = values.shift
        if val = value.value
          out << val
        end
      end
      out
    end

  end

end
<commit_msg>not sure about this, but seems to fix some edge cases<commit_after>module RMExtensions

  class StrongToWeakHash < Hash

    def [](key)
      if val = super
        if val = val.value
          val.retain.autorelease
        end
      end
    end

    def []=(key, value)
      super(key, value.nil? ? nil : WeakHolder.new(value))
      value
    end

    def delete(key)
      if val = super
        val.value
      end
    end

    def keys
      out = []
      keys = [] + super
      while keys.size > 0
        key = keys.shift
        if val = self[key]
          out << key
        end
      end
      out
    end

    def values
      out = []
      values = [] + super
      while values.size > 0
        value = values.shift
        if val = value.value
          out << val
        end
      end
      out
    end

  end

end

{'fraction_non_alphanumeric': 0.07964601769911504, 'fraction_numerical': 0.0025284450063211127, 'mean_word_length': 1.2485795454545454, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 7, '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': '5304136', 'n_tokens_mistral': 500, 'n_tokens_neox': 477, 'n_words': 154}