January 2019
Intermediate to advanced
316 pages
8h 8m
English
To find the common elements of two sets, the intersection is a way of doing that. The definition also describes exactly that, which is why the naive implementation in Rust also follows that pattern, shown as follows:
pub fn intersection(self, other: TrieSet<K>) -> TrieSet<K> { let new = RefCell::new(TrieSet::new_empty()); if self.length < other.length { self.walk(|k| { if other.contains(k) { new.borrow_mut().insert(k) } }); } else { other.walk(|k| { if self.contains(k) { new.borrow_mut().insert(k) } }); } new.into_inner()}
As a last function, the difference is important, since it excludes common elements from the result set.