Add for_each_prefix_of methods to obtain path to longest prefix #52
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds a
for_each_prefix_ofmember function inhtrie_mapandhtrie_setwhich calls a visitor for each element that is a prefix the given key, fulfilling the feature request #32 proposed by @gh-andre .I had difficulty coming up with a good concise name, and I would be happy to replace
for_each_prefix_ofwith something better.Unfortunately, the current iterator design doesn't lend itself well to extension for other traversal algorithms. It was far simpler for me to adapt
longest_prefixso that it calls a handler function for each match along the path to the longest prefix.Some other trie implementations provide a "cursor" interface and this library could benefit from one as well. It would allow extensibility to implement different types of traversal algorithms without having to modify
htrie_mapandhtrie_set. IMHO, there should only be one iterator type that traverses all elements so thathtrie_mapandhtrie_setmeet the requirements of a C++ container. All other traversal algorithms should be implemented as free functions (or helper classes) which use the cursor interface.