Open alexkirsz opened 2 years ago
do you mean longest_common_prefix
?
longest_common_prefix
returns the longest common prefix with a given key. I need to iterate over all common prefixes, not just the longest. Specifically, I need the same behavior as https://docs.rs/patricia_tree/latest/patricia_tree/map/struct.PatriciaMap.html#method.common_prefixes (see the example).
it's not super elegant, but it seems like this can be implemented efficiently with the subtrie
method. You just repeatedly call subtrie and get on progressively longer slices, and this has the effect of advancing the node in the tree. If you know you have strings, this might be a little faster by using the unicode representations to avoid unnecessary calls to get, although that's not obviously the case.
Could add a function like longest_common_prefix_with_value()
, it return the longest common prefix and the reference to the value associated with the longest common prefix at the same time ? If so, it can bring great convenience.
@erikbrinkman
Is there a way to iterate over all common prefixes with a particular key?
See https://docs.rs/patricia_tree/latest/patricia_tree/map/struct.PatriciaMap.html#method.common_prefixes