pub fn diff<C, T>(old: C, new: C) -> BagDelta<T>where
C: IntoIterator<Item = T> + TryIndex<T, Output = T>,Expand description
Computes which elements new gained and which old lost.
Returns an empty BagDelta when the two hold the same elements. Each
element of old is looked up in new exactly once, through the
collection’s own TryIndex implementation, so the cost is that of n
lookups: O(n) for a HashSet, O(n log n) for
a BTreeSet.
use delta_struct::bag::diff;
use std::collections::BTreeSet;
let old: BTreeSet<i32> = vec![1, 2, 3].into_iter().collect();
let new: BTreeSet<i32> = vec![3, 4, 5].into_iter().collect();
let delta = diff(old, new);
assert_eq!(delta.add, vec![4, 5]);
assert_eq!(delta.remove, vec![1, 2]);