Expand description
Provides Trie iterators.
Here’s an example of how we can iterate over our Trie. We use the
FromIterator
trait to reconstruct our source key from the
vector of atoms which the iterator returns as the key.
NB: Because we stripped all of the whitespace out when we split our
key, we need to re-add it before we insert it. Until intersperse
is added to the std library, the simplest way to do this right now
is to use itertools.
Example 4
use std::iter::FromIterator;
use itertools::Itertools;
use trying::trie::TrieVec;
let mut trie = TrieVec::<&str, usize>::new();
let input = Itertools::intersperse("the quick brown fox".split_whitespace(), " ");
trie.insert_with_value(input.clone(), Some(4));
// Anything which implements IntoIterator<Item=&str> can now be used
// to interact with our Trie
for kv_pair in trie.into_iter() {
println!("kv_pair: {:?}", kv_pair);
assert_eq!("the quick brown fox", String::from_iter(kv_pair.key));
assert_eq!(kv_pair.value, Some(4));
}
Structs§
- KeyValue
- Iterator Item
- KeyValue
Ref - Iterator Item
- Trie
Into Iterator - Iterator over a Trie.
- Trie
RefInto Iterator - Iterator over a Trie.