Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature suggestion: obtaining a path to the longest prefix #32

Open
gh-andre opened this issue Oct 23, 2020 · 8 comments
Open

Feature suggestion: obtaining a path to the longest prefix #32

gh-andre opened this issue Oct 23, 2020 · 8 comments

Comments

@gh-andre
Copy link

It would be quite useful if it was possible not just get an iterator to the longest prefix, but also a path leading to that prefix from the shortest prefix. Such a method would return a vector of iterators pointing to values that matched the first characters of the longest prefix argument. In other words, if a map contained these values:

/A
/A/B/C
/A/B/D
/A/B/E

, and the longest prefix would be requested as /A/B/D/E/F, then in a loop similar to the ones in equal_prefix_range_impl and filter_prefix it would test if keys of nodes that have values would match the beginning of the prefix string, so in the example above, it would return a vector of iterators pointing to /A and /A/B/D.

It would allow many useful operations for parent paths, which now can only be done via multiple calls with prefixes of different lengths.

A special "parent iterator" hiding the parent path vector and overloading -- would probably fit nicely in the interface.

Sorry if there is a way to achieve what I described and I missed it.

@Tessil
Copy link
Owner

Tessil commented Oct 24, 2020

It should be possible to adapt the longest_prefix method into a new one that return all the encountered prefixes instead of just the longest one.

It may take some time before I start working on it as I have been lacking the time recently. Any PR is welcome though.

@gh-andre
Copy link
Author

@Tessil Thanks for responding. I am test-driving some other trie libraries and, depending on how testing goes, may revisit hat-trie later on. I quite like how the interface is structured and how it is performance-focused.

@ecorm
Copy link
Contributor

ecorm commented Apr 29, 2023

I am test-driving some other trie libraries

@gh-andre I also need the feature you propose. If you don't mind me asking, which one did you end up using which supports this feature?

@gh-andre
Copy link
Author

@ecorm I ended up using Akamai Radix Tree. It allows searches, tree traversal and longest prefix searches. I did need to write a few wrappers around some of the components, but in general it worked out very well for me.

https://github.com/neufeldm/akamai-radix-tree

@ecorm
Copy link
Contributor

ecorm commented May 3, 2023

@gh-andre , @Tessil , submitted PR #52 to add this functionality.

@ecorm
Copy link
Contributor

ecorm commented May 3, 2023

@gh-andre BTW, I checked out Akamai Radix Tree and didn't like that I had to provide things like the desired max depth and the maximum edge length. Choosing a very large max depth is not feasible, because there's a reserve() in there that would allocate a huge buffer needlessly for small sets of inputs.

@Tessil
Copy link
Owner

Tessil commented May 4, 2023

@ecorm Thank you very much for the PR! I haven't had much time to implement this. I'll try to review the PR this weekend.

@gh-andre
Copy link
Author

gh-andre commented May 4, 2023

@ecorm Akamai Radix Tree may be a bit tricky indeed to work with. The maximum depth isn't a problem for many areas, such as maintaining IP addresses or region codes. It would present some challenge, as you describe, for arbitrary dictionaries.

It's been too long for me being away from this code to provide meaningful feedback for the changes, but it's good to know that this new functionality will be available in this library. Thank you for the heads-up and your work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants