One key requirement of the product team was the ability to run simple analytics on top of this set. As a first step, these analytics can be comprised of set operations and comparing their lengths in order to create simple indicators.
One thing that is important, however, is to also get the addresses back out. For that, the implementation this time provides an iterator implementation that consumes the trie and stores it as a Vec<T>, shown as follows:
// [...] trie set implementation
pub fn into_iter(self) -> SetIterator<K> {
let v: RefCell<Vec<Vec<K>>> = RefCell::new(vec![]);
self.walk(|n| v.borrow_mut().push(n.to_vec()));
SetIterator::new(v.into_inner(), 0)
}
}
pub struct SetIterator<K>
where
K: PartialEq + Clone + Ord,
{
data: Vec<Vec<K>>,
last_index: usize,
}
impl<K> SetIterator<K>
where
K: PartialEq + Clone + Ord,
{
fn new(data: Vec<Vec<K>>, start_at: usize...