klawson88/MDAG

How to traverse?

trans opened this issue · 1 comments

I am trying to utilize MDAG as the data structure for an optimized Levenshtein distance function as explained here. The MDAG takes the place of a Trie in the original definition. But I'm running into a problem because I don't understand how to traverse the graph. For example I need to translate this Python code to the equivalent Java where trie becomes mdag.

for letter in trie.children:
    searchRecursive( trie.children[letter], letter, ... )

So, what's is the general pattern for traversal?

Well, I think I figured it out, though I am not 100% certain the difference between, KeySet(), navigableKeySet() and descendingKeySet(); .

for(Character nextLetter : node.getOutgoingTransitions().navigableKeySet()) {
    MDAGNode node = node.transition(nextLetter);
    ...
}

I am also a little unsure about node.transition b/c I found another way to do it that seems more right that doesn't have that:

for(Map.Entry<Character,MDAGNode> entry : node.getOutgoingTransitions().entrySet()) {
    Character nextLetter = entry.getKey();
    MDAGNode nextNode = entry.getValue();
    ...
}