| Class | TernaryTrie |
| In: |
lib/utility/ternarytrie.rb
|
| Parent: | Object |
class TernaryTrie implements a ternary search trie. The keys are are assumed to be strings, but the values can be any object. This is a very lightweight and useful object
constructor simply ensures we have a root
# File lib/utility/ternarytrie.rb, line 22 def initialize @root = nil end
Returns array of values that are the shortest possible match of the key.
# File lib/utility/ternarytrie.rb, line 46 def find(key) return [] if !key.respond_to? :to_str key = key.to_str match = [] find_r(@root, key, match, 0) match end
Returns an exact match only of the key or nil if not found
# File lib/utility/ternarytrie.rb, line 36 def find_exact(key) return nil if !key.respond_to? :to_str key = key.to_str return find_exact_r(@root, key, 0) end