Possible to walk the trie?
See original GitHub issueI don’t see any methods that would allow for just proceeding one edge in the trie, for example:
trie = marisa_trie.Trie([u'key1', u'key2', u'kite'])
trie.edges('k') #would return [u'ke', u'ki']
Using the prefixes method for something like this would be very expensive if the trie is big and the prefix is short. Is there some technical detail I’m missing for why implementing a function for this would be costly, or some other reason this isn’t implemented? It seems like it’s a necessary step in the traversal with the prefixes()
method anyway, and quite useful for predictive lookup operations.
Issue Analytics
- State:
- Created 9 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Bottom-up traversal of a Trie - GeeksforGeeks
The idea to do this is to start traversing from the root node of the trie, whenever we find a NON-NULL child node,...
Read more >Trie Data Structure in C/C++ - DigitalOcean
A Trie data structure acts as a container for a dynamic array. In this article, we shall look at how we can implement...
Read more >Trie - Wikipedia
In computer science, a trie, also called digital tree or prefix tree, is a type of k-ary search tree, a tree data structure...
Read more >Trie Data Structure - Medium
Insertion begins by starting at the root node of the tree and walking through the Trie according the string that is being inserted....
Read more >Iteratively Construct Trie from a Tree - clojure - Stack Overflow
I would propose to take a look at clojure's walk api. It allows you to recursively apply some function to nested collections. In...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Actually, this is the second time that this feature would be very useful to me, so I thought I might mention it here. I also looked through other Python trie libraries (PyTrie, patricia-trie, python-trie) and neither of them support this.
My usecase (which I would expect to be not that rare) is walking down the tree while computing Levenshtein distance, I use it for fuzzy matches similar to @EliFinkelshteyn.
Alright, I’ll investigate a bit more, and if it still looks useful, I’ll send over a PR. Closing the issue out here, since it’d be much easier to do for DAWG than the Marisa-Trie.