laysakura / trie-rs

Memory efficient trie (prefix tree) library based on LOUDS
https://crates.io/crates/trie-rs
Apache License 2.0
90 stars 10 forks source link

Latency improvement for predictive_search #19

Closed ghost closed 1 year ago

ghost commented 1 year ago

Hi! Thanks for this neat library, I appreciate your work.

If you're open to contributions, this PR changes the implementation of predictive_search to perform an iterative preorder traversal of the trie, instead of recursive calls. In benchmarks on my machine that's about a 45% reduction in latency. Tests are passing. This is relevant to https://github.com/laysakura/trie-rs/issues/10 .

Relatedly: would you be open to a future PR that returns suggestions as an Iterator? The idea being you can do trie.predictive_suggestions("foo").take(k) to grab K suggestions rather than all of them (and potentially skip some of the work!).