1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use Hash;
pub use HashSet;
/// Calculate changes between two sets.
///
/// Returns a struct containing:
/// - `added`, containing elements that exist in new set but not in old.
/// - `removed`, containig elements that exist in old set but not in new.
/// - `unchaned`, containing elements that exists in both old and new sets.
///
/// ```
/// use orphanage::setops::{HashSet, changes};
///
/// let old: HashSet<u32> = [1, 2].into_iter().collect();
/// let new: HashSet<u32> = [2, 3].into_iter().collect();
///
/// let diff = changes(&old, &new);
///
/// let mut added: Vec<u32> = diff.added.into_iter().copied().collect();
/// added.sort_unstable();
/// let mut removed: Vec<u32> = diff.removed.into_iter().copied().collect();
/// removed.sort_unstable();
/// let mut unchanged: Vec<u32> = diff.unchanged.into_iter().copied().collect();
/// unchanged.sort_unstable();
///
/// assert_eq!(&added, &[3]);
/// assert_eq!(&removed, &[1]);
/// assert_eq!(&unchanged, &[2]);
/// ```
// vim: set ft=rust et sw=2 ts=2 sts=2 cinoptions=2 tw=79 :