Skip to content

Conversation

@ecorm
Copy link
Contributor

@ecorm ecorm commented May 3, 2023

This adds a for_each_prefix_of member function in htrie_map and htrie_set which 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_of with 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_prefix so 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_map and htrie_set. IMHO, there should only be one iterator type that traverses all elements so that htrie_map and htrie_set meet the requirements of a C++ container. All other traversal algorithms should be implemented as free functions (or helper classes) which use the cursor interface.

@ecorm
Copy link
Contributor Author

ecorm commented May 17, 2023

Sorry but... bump?

@Tessil
Copy link
Owner

Tessil commented May 21, 2023

Thank you very much for the contribution and sorry for the delay. It looks good!

@Tessil Tessil merged commit 906e6ab into Tessil:master May 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants