1use std::ops::{BitOr, BitOrAssign};
2use crate::*;
3use crate::iter::TimeUnion;
4
5impl<TW> BitOr<TW> for TimeValue
9 where TW: TimeConvex<TimePoint=TimeValue>
10{
11 type Output = TimeSet<TimeValue>;
12 #[inline] fn bitor(self, tw: TW) -> Self::Output { TimeInterval::singleton(self).bitor(tw) }
13}
14
15impl<TW> BitOr<TW> for Timestamp
16 where TW: TimeConvex<TimePoint=Timestamp>
17{
18 type Output = TimeSet<Timestamp>;
19 #[inline] fn bitor(self, tw: TW) -> Self::Output { TimeInterval::singleton(self).bitor(tw) }
20}
21
22impl<T:TimePoint,TW> BitOr<TW> for TimeInterval<T>
26 where TW: TimeConvex<TimePoint=T>
27{
28 type Output = TimeSet<T>;
29 #[inline] fn bitor(self, tw: TW) -> Self::Output { (&self).bitor(tw) }
30}
31
32impl<T:TimePoint,TW> BitOr<TW> for &TimeInterval<T>
33 where TW: TimeConvex<TimePoint=T>
34{
35 type Output = TimeSet<T>;
36
37 fn bitor(self, tw: TW) -> Self::Output
38 {
39 if self.is_empty() {
40 TimeSet::from(tw)
41
42 } else if tw.is_empty() {
43 (*self).into()
44
45 } else if tw.upper_bound() < self.lower.just_before() {
46 TimeSet(vec![tw.into(), *self])
47
48 } else if self.upper < tw.lower_bound().just_before() {
49 TimeSet(vec![*self, tw.into()])
50
51 } else {
52 TimeSet(vec![
53 TimeInterval {
54 lower: self.lower.min(tw.lower_bound()),
55 upper: self.upper.max(tw.upper_bound())
56 }
57 ])
58 }
59 }
60}
61
62impl<T:TimePoint,TW> BitOrAssign<TW> for TimeSet<T>
65 where TW: TimeConvex<TimePoint=T>
66{
67 fn bitor_assign(&mut self, tw: TW) {
68 *self = self.clone().bitor(tw)
70 }
71}
72
73
74impl<T:TimePoint> BitOrAssign<Self> for TimeSet<T>
75{
76 fn bitor_assign(&mut self, tw: Self) {
77 *self = self.clone().bitor(tw)
79 }
80}
81
82impl<T:TimePoint> BitOrAssign<&Self> for TimeSet<T>
83{
84 fn bitor_assign(&mut self, tw: &Self) {
85 *self = self.clone().bitor(tw)
87 }
88}
89
90impl<T:TimePoint> BitOr<Self> for TimeSet<T>
91{
92 type Output = Self;
93 #[inline] fn bitor(self, tw: Self) -> Self::Output { (&self).bitor(tw) }
94}
95
96impl<T:TimePoint> BitOr<&Self> for TimeSet<T>
97{
98 type Output = Self;
99 #[inline] fn bitor(self, tw: &Self) -> Self::Output { (&self).bitor(tw) }
100}
101
102impl<T:TimePoint, TW> BitOr<TW> for TimeSet<T>
103where TW: TimeConvex<TimePoint=T>
104{
105 type Output = Self;
106 #[inline] fn bitor(self, tw: TW) -> Self::Output { (&self).bitor(tw) }
107}
108
109
110impl<T:TimePoint> BitOr<TimeSet<T>> for &TimeSet<T>
111{
112 type Output = TimeSet<T>;
113
114 #[inline]
115 fn bitor(self, tw: TimeSet<T>) -> Self::Output {
116 self.into_iter().union(tw.into_iter()).collect()
117 }
118}
119
120impl<T:TimePoint> BitOr<Self> for &TimeSet<T>
121{
122 type Output = TimeSet<T>;
123
124 #[inline]
125 fn bitor(self, tw: &TimeSet<T>) -> Self::Output {
126 self.into_iter().union(tw.into_iter()).collect()
127 }
128}
129
130
131
132impl<T:TimePoint, TW> BitOr<TW> for &TimeSet<T>
133where TW: TimeConvex<TimePoint=T>
134{
135 type Output = TimeSet<T>;
136
137 #[inline]
138 fn bitor(self, tw: TW) -> Self::Output {
139 self.into_iter().union(tw.into()).collect()
140 }
141}
142