1use crate::{map::Key, RangeBounds, SegmentMap, SegmentSet};
4
5pub mod difference;
6pub mod intersection;
7pub mod symmetric_difference;
8pub mod union;
9
10impl<T: Ord> SegmentSet<T> {
11 pub fn is_disjoint(&self, other: &Self) -> bool {
15 self.iter_intersection(other).next().is_none()
16 }
17
18 pub fn is_subset(&self, other: &Self) -> bool {
23 self.iter_difference(other).next().is_none()
24 }
25
26 pub fn is_superset(&self, other: &Self) -> bool {
27 other.is_subset(self)
28 }
29
30 pub fn subset<R: RangeBounds<T>>(&self, range: R) -> SegmentSet<T>
33 where
34 T: Clone + Ord,
35 {
36 SegmentSet {
37 map: SegmentMap {
38 map: self
39 .map
40 .iter_subset(range)
41 .map(|(r, _)| (Key(r), ()))
42 .collect(),
43 store: alloc::vec::Vec::new(),
44 },
45 }
46 }
47
48 pub fn complement(&self) -> SegmentSet<&T>
50 where
51 T: Ord,
52 {
53 self.map.complement()
54 }
55}
56
57impl<'a, T: Ord + Clone> core::ops::Not for &'a SegmentSet<T> {
59 type Output = SegmentSet<&'a T>;
60
61 fn not(self) -> Self::Output {
63 self.complement()
64 }
65}
66
67impl<T: Ord + Clone> core::ops::Not for SegmentSet<T> {
68 type Output = SegmentSet<T>;
69
70 fn not(self) -> Self::Output {
71 self.complement().cloned()
72 }
73}