<commit_before>module Hamster

  class Trie

    include Enumerable

    def initialize(significant_bits = 0)
      @significant_bits = significant_bits
      @entries = []
      @children = []
    end

    # Returns the number of key-value pairs in the trie.
    def size
      # TODO: This definitely won't scale!
      to_a.size
    end

    # Returns <tt>true</tt> if the trie contains no key-value pairs.
    def empty?
      size == 0
    end

    # Returns <tt>true</tt> if the given key is present in the trie.
    def has_key?(key)
      !! get(key)
    end

    # Calls <tt>block</tt> once for each key in the trie, passing the key-value pair as parameters.
    def each
      block_given? or return enum_for(__method__)
      @entries.each { |entry| yield entry.key, entry.value if entry }
      @children.each do |child|
        child.each { |key, value| yield key, value } if child
      end
      self
    end

    # Associates the value given by with the key.
    def put(key, value)
      self.dup.put!(key, value)
    end

    # Retrieves the value corresponding to the given key. If not found, returns nil.
    def get(key)
      index = index_for(key)
      entry = @entries[index]
      if entry
        if entry.has_key?(key)
          entry.value
        else
          child = @children[index]
          child.get(key) if child
        end
      end
    end

    protected

    def put!(key, value)<commit_msg>No _real_ reason not to allow mutation<commit_after>module Hamster

  class Trie

    include Enumerable

    def initialize(significant_bits = 0)
      @significant_bits = significant_bits
      @entries = []
      @children = []
    end

    # Returns the number of key-value pairs in the trie.
    def size
      # TODO: This definitely won't scale!
      to_a.size
    end

    # Returns <tt>true</tt> if the trie contains no key-value pairs.
    def empty?
      size == 0
    end

    # Returns <tt>true</tt> if the given key is present in the trie.
    def has_key?(key)
      !! get(key)
    end

    # Calls <tt>block</tt> once for each key in the trie, passing the key-value pair as parameters.
    def each
      block_given? or return enum_for(__method__)
      @entries.each { |entry| yield entry.key, entry.value if entry }
      @children.each do |child|
        child.each { |key, value| yield key, value } if child
      end
      self
    end

    # Associates the value given by with the key.
    def put(key, value)
      self.dup.put!(key, value)
    end

    # Retrieves the value corresponding to the given key. If not found, returns nil.
    def get(key)
      index = index_for(key)
      entry = @entries[index]
      if entry
        if entry.has_key?(key)
          entry.value
        else
          child = @children[index]
          child.get(key) if child
        end
      end
    end

    def put!(key, value)
{'fraction_non_alphanumeric': 0.08414464534075104, 'fraction_numerical': 0.0013908205841446453, 'mean_word_length': 2.070437566702241, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '6158064', 'n_tokens_mistral': 900, 'n_tokens_neox': 860, 'n_words': 312}