Method: Containers::Trie#push
- Defined in:
- lib/containers/trie.rb
#push(key, value) ⇒ Object Also known as: []=
Adds a key, value pair to the Trie, and returns the value if successful. The to_s method is called on the parameter to turn it into a string.
Complexity: O(m)
t = Containers::Trie.new
t["hello"] = "world"
t.push("hello", "world") # does the same thing
t["hello"] #=> "world"
t[1] = 1
t[1] #=> 1
54 55 56 57 58 59 |
# File 'lib/containers/trie.rb', line 54 def push(key, value) key = key.to_s return nil if key.empty? @root = push_recursive(@root, key, 0, value) value end |