The RegexTrie is a trie where each stored segment of the key is a regex
Pattern. Thus, the full stored key is a
List<String> as in a standard trie. Note that the
retrieve(String) method will be pointwise matched against the
rather than checked for pointwise equality as in a standard trie. Because of this, it may
perform poorly for large datasets.
One can also use a
entry in the
sequence to serve as a wildcard. If
is encountered, all subsequent entries in the sequence will be ignored.
When the retrieval code encounters a
, it will first wait to see if a
more-specific entry matches the sequence. If one does, that more-specific entry will proceed,
even if it subsequently fails to match.
If no more-specific entry matches, the wildcard match will add all remaining
to the list of captures (if enabled) and return the value associated with the wildcard.
A short sample of the wildcard functionality:
List<List<String>> captures = new LinkedList<List<String>>();
RegexTrie<Integer> trie = new RegexTrie<Integer>();
trie.put(2, "a", null);
trie.put(4, "a", "b");
trie.retrieve(captures, "a", "c", "e");
// returns 2. captures is now [, ["c"], ["e"]]
trie.retrieve(captures, "a", "b");
// returns 4. captures is now [, ]
trie.retrieve(captures, "a", "b", "c");
// returns null. captures is now [, ]