app/server/vendor/hamster/lib/hamster/trie.rb
# Returns a copy of <tt>self</tt> with the given value associated with the key.
Returns a copy of self with the given value associated with the key.
Returns a copy of self with the given value associated with the key .
def put(key, value)
      index = index_for(key)
      entry = @entries[index]
      if !entry
        entries = @entries.dup
        entries[index] = Entry.new(key, value)
        self.class.new(@significant_bits, @size + 1, entries, @children)
      elsif entry.key.eql?(key)
        entries = @entries.dup
        entries[index] = Entry.new(key, value)
        self.class.new(@significant_bits, @size, entries, @children)
      else
        children = @children.dup
        child = children[index]
        child_size = child ? child.size : 0
        if child
          children[index] = child.put(key, value)
        else
          children[index] = self.class.new(@significant_bits + 5).put!(key, value)
        end
        new_child_size = children[index].size
        new_self_size = @size + (new_child_size - child_size)
        self.class.new(@significant_bits, new_self_size, @entries, children)
      end
    end
def put ( key , value ) index = index_for ( key ) entry = @entries [ index ] if ! entry entries = @entries . dup entries [ index ] = Entry . new ( key , value ) self . class . new ( @significant_bits , @size + 1 , entries , @children ) elsif entry . key . eql? ( key ) entries = @entries . dup entries [ index ] = Entry . new ( key , value ) self . class . new ( @significant_bits , @size , entries , @children ) else children = @children . dup child = children [ index ] child_size = child ? child . size : 0 if child children [ index ] = child . put ( key , value ) else children [ index ] = self . class . new ( @significant_bits + 5 ) . put! ( key , value ) end new_child_size = children [ index ] . size new_self_size = @size + ( new_child_size - child_size ) self . class . new ( @significant_bits , new_self_size , @entries , children ) end end
Returns a copy of <tt>self</tt> with the given value associated with the key.
Returns a copy of <tt > self< / tt > with the given value associated with the key .
key
<not_specific>
value
<not_specific>