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
62
63
64
65
66
67
68
69
70
71
72
73
use crate::{map::Key, RangeBounds, SegmentMap, SegmentSet};
pub mod difference;
pub mod intersection;
pub mod symmetric_difference;
pub mod union;
impl<T: Ord> SegmentSet<T> {
pub fn is_disjoint(&self, other: &Self) -> bool {
self.iter_intersection(other).next().is_none()
}
pub fn is_subset(&self, other: &Self) -> bool {
self.iter_difference(other).next().is_none()
}
pub fn is_superset(&self, other: &Self) -> bool {
other.is_subset(self)
}
pub fn subset<R: RangeBounds<T>>(&self, range: R) -> SegmentSet<T>
where
T: Clone + Ord,
{
SegmentSet {
map: SegmentMap {
map: self
.map
.iter_subset(range)
.map(|(r, _)| (Key(r), ()))
.collect(),
store: alloc::vec::Vec::new(),
},
}
}
pub fn complement(&self) -> SegmentSet<&T>
where
T: Ord,
{
self.map.complement()
}
}
impl<'a, T: Ord + Clone> core::ops::Not for &'a SegmentSet<T> {
type Output = SegmentSet<&'a T>;
fn not(self) -> Self::Output {
self.complement()
}
}
impl<T: Ord + Clone> core::ops::Not for SegmentSet<T> {
type Output = SegmentSet<T>;
fn not(self) -> Self::Output {
self.complement().cloned()
}
}