pub fn classify<T: Ord + Clone, I: IntoIterator<Item = T>>(
list_of_sets: impl IntoIterator<Item = I>,
sort: bool,
) -> (Vec<BTreeSet<T>>, BTreeMap<T, BTreeSet<T>>)Expand description
Classifies the things present in any of the sets into the smallest list of
sets such that each one is either a subset of, or disjoint from, each of the
input sets (classify). Returns the classes and the class of each thing.
With sort, the classes are sorted by decreasing size and their sorted
things; otherwise they are in the order they were identified.
use std::collections::BTreeSet;
use fontoxide_misc::classify_tools::classify;
let (classes, mapping) = classify([vec![1, 2], vec![2, 4, 5]], true);
assert_eq!(classes, [BTreeSet::from([4, 5]), BTreeSet::from([1]), BTreeSet::from([2])]);
assert_eq!(mapping[&5], BTreeSet::from([4, 5]));