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

Add iterators, incremental search, and collectable labels #27

Closed shanecelis closed 4 months ago

shanecelis commented 4 months ago

This library remains a constant companion. I've reworked my previous pull request significantly. I'll include my write up from the CHANGELOG that explains the changes as well as I'm able.


let a: Vec<Vec<u8>> = trie.predictive_search("ech").take(10).collect();
let a: Vec<Vec<u8>> = trie.predictive_search("ech").collect();
let b: Vec<String> = trie.predictive_search("ech").collect();
let b: Vec<String> = trie.predictive_search("").take(100).collect();

Of these changes perhaps the postfix_search is superfluous and could be omitted. (It's used internally but maybe shouldn't be exposed.)

The biggest change is that searches from crate::Trie do not return a Vec but an iterator and is certainly a breaking change. However, I think the benefits are worth it.

Happy to hear your thoughts on the changes. Thanks again for this very useful library.

Oh, and this also makes Trie clone-able provided the other two PRs to louds-rs and fids-rs are accepted.