sdleffler / qp-trie-rs

An idiomatic and fast QP-trie implementation in pure Rust.
Mozilla Public License 2.0
94 stars 24 forks source link

Question: Check if SubTrie root is in Trie #37

Closed LuckyTurtleDev closed 1 year ago

LuckyTurtleDev commented 1 year ago

Hi,

Can I check if the key of the root of a SubTrie is in inside The parent Trie.

For example I have insert the string moc.elpmaxe in a Trie<Vec<u8>,()> Now I a string moc.elpmaxe.bus. I now would like to check if at least one of moc, moc.elpmaxe or moc.elpmaxe.bus is inside the trie. So I have do something like this:

subtrie = trie.subtrie("moc")
subtrie.get(Vec::new())
subtrie = subtrie.trie.subtrie(".elpmaxe")
subtrie.get(....

Full source: https://github.com/LuckyTurtleDev/crab-hole/blob/82fb9af145f1bd5e7babf1b9b3f83a5837020a97/src/trie.rs#L21-L37

But this has not work. I am not sure if I had a bug in my implementation or if subtrie.get(Vec::new()) can not check if the subtrie root is in. So I would like to validate first if calling subtrie.get(Vec::new()) is the right procedure.

LuckyTurtleDev commented 1 year ago

My issue was that if search only for .elpmaxe inside the subtrei, but I looks like I need to include the prefix again, so I need to search for moc.elpmaxe inside the subtrie, even when it is the subtrie from moc.