Two groups of methods that I think are missing:
- When one considers sets one generally want to be able to compare them from the view point of inclusion. While it’s currently possible to compare sets using
is_disjoint
,is_subset
andis_superset
, those methods cover too restricted cases (you cannot know if a set is a proper superset for example, except by additionally checking if both sets are unequal). More generally I think it would be nice to have a enum representing the different kind of set relations and a trait comparing two sets:
pub enum SetComparison {
Equal,
ProperSubset,
ProperSuperset,
Disjoint,
Overlapping, // the intersection and both set differences contain elements
}
pub trait SetRel: Eq {
fn set_cmp(&self, other: &Self) -> SetComparison;
}
Notice that this allows plenty of more specific comparison relations (for example to be a non-proper subset is simply to return either Equal
or ProperSubset
). Of course such a trait can be implemented externally but as such it may not benefit from the best implementation.
- As Java shows it, there exists interesting additional methods for
BTreeSet
( respectivelyBTreeMap
) : the capacity to retrieve not precisely a given element (respectively a given key-value pair) but the closest (strictly) smaller/bigger element (respectively key-value pair) if any. Even better: one may want to have partial views that represent left/right/inner “intervals”. Once again this may be implemented externally but not as efficiently as if one can access the inner details of such types.