I am trying to find all keys stored in a trie that are valid prefixes of a string.
Example: Given a trie that contains "ab", "abc", "abcd", "bc" and "bcd". Searching for the string "abcdefg" in the trie should yield "abcd", "abc", "ab".
I would like to use the appache commons patricia trie implementation for java but it does not seem to support this kind of lookup. Is there any alternative implementation or simple solution to this problem?
I myself haven't used the Apache Commons PatriciaTrie, but as far as I checked you can easily get only the map of words prefixed with some string. Most of the examples I found are also providing basic operations like insert, find. I also encountered some discussions about a Trie implementation in guava, but nothing really specific.
So here is my simple suggestion of a custom implementation (but should be covered with a good set of tests when a custom implementation is used).