Created
August 14, 2011 18:56
-
-
Save pavlos/1145176 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is totally a hack