Skip to content

Instantly share code, notes, and snippets.

@pavlos
Created August 14, 2011 18:56
Show Gist options
  • Select an option

  • Save pavlos/1145176 to your computer and use it in GitHub Desktop.

Select an option

Save pavlos/1145176 to your computer and use it in GitHub Desktop.
class BetterTrie < Containers::Trie
def initialize
@longest_key = 0
super
end
def push(key, value)
key_length = key.to_s.length
@longest_key = key_length if key_length > @longest_key
super key, value
end
def where_key_starts_with string
stars = @longest_key - string.to_s.length
string = string.to_s + ("*" * stars) if stars > 0
keys = wildcard(string)
keys.collect{|k| get(k)}
end
end
@pavlos
Copy link
Copy Markdown
Author

pavlos commented Aug 14, 2011

This is totally a hack

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment