struct Line<T> {
a: Slope<T>,
b: T,
q: Query<T>,
}Fields§
§a: Slope<T>§b: T§q: Query<T>Implementations§
Source§impl<T> Line<T>
impl<T> Line<T>
Sourcefn new(a: T, b: T, q: T) -> Self
fn new(a: T, b: T, q: T) -> Self
Examples found in repository?
crates/competitive/src/data_structure/line_set.rs (line 166)
133 pub fn insert(&mut self, a: T, b: T) {
134 fn f<T>(la: T, lb: T, ra: T, rb: T) -> T
135 where
136 T: Copy + Ord + Sub<Output = T> + Div<Output = T>,
137 {
138 debug_assert!(la > ra);
139 (rb - lb) / (la - ra)
140 }
141 let left = self.map.range(..Slope(a)).next_back().cloned();
142 let mut right = self.map.range(Slope(a)..).next().cloned();
143 match (&left, &right) {
144 (_, Some(r)) if a == r.a.0 => {
145 if r.b <= b {
146 return;
147 }
148 self.map.remove(r);
149 right = self.map.range(Slope(a)..).next().cloned();
150 }
151 (Some(l), Some(r)) if f(l.a.0, l.b, a, b) >= f(a, b, r.a.0, r.b) => return,
152 _ => {}
153 }
154 loop {
155 let rq = if let Some(r) = right {
156 let rq = f(a, b, r.a.0, r.b);
157 if rq >= r.q.0 {
158 self.map.remove(&r);
159 right = self.map.range(Slope(a)..).next().cloned();
160 continue;
161 }
162 rq
163 } else {
164 Bounded::maximum()
165 };
166 self.map.insert(Line::new(a, b, rq));
167 break;
168 }
169 if let Some(mut l) = left {
170 self.map.remove(&l);
171 let mut lq = f(l.a.0, l.b, a, b);
172 loop {
173 if let Some(ll) = self.map.range(..Slope(a)).next_back().cloned() {
174 self.map.remove(&ll);
175 let llq = f(ll.a.0, ll.b, l.a.0, l.b);
176 if llq >= lq {
177 l = ll;
178 lq = f(l.a.0, l.b, a, b);
179 continue;
180 } else {
181 self.map.insert(Line::new(ll.a.0, ll.b, llq));
182 }
183 };
184 break;
185 }
186 self.map.insert(Line::new(l.a.0, l.b, lq));
187 }
188 }Trait Implementations§
Source§impl<T> Ord for Line<T>where
T: Ord,
impl<T> Ord for Line<T>where
T: Ord,
Source§impl<T> PartialOrd for Line<T>where
T: PartialOrd,
impl<T> PartialOrd for Line<T>where
T: PartialOrd,
impl<T> Eq for Line<T>where
T: Eq,
Auto Trait Implementations§
impl<T> Freeze for Line<T>where
T: Freeze,
impl<T> RefUnwindSafe for Line<T>where
T: RefUnwindSafe,
impl<T> Send for Line<T>where
T: Send,
impl<T> Sync for Line<T>where
T: Sync,
impl<T> Unpin for Line<T>where
T: Unpin,
impl<T> UnwindSafe for Line<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> AsTotalOrd for Twhere
T: PartialOrd,
impl<T> AsTotalOrd for Twhere
T: PartialOrd,
fn as_total_ord(&self) -> TotalOrd<&T>
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more