Line

Struct Line 

Source
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>

Source

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> Borrow<Query<T>> for Line<T>

Source§

fn borrow(&self) -> &Query<T>

Immutably borrows from an owned value. Read more
Source§

impl<T> Borrow<Slope<T>> for Line<T>

Source§

fn borrow(&self) -> &Slope<T>

Immutably borrows from an owned value. Read more
Source§

impl<T: Clone> Clone for Line<T>

Source§

fn clone(&self) -> Line<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Line<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Default> Default for Line<T>

Source§

fn default() -> Line<T>

Returns the “default value” for a type. Read more
Source§

impl<T> Ord for Line<T>
where T: Ord,

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T> PartialEq for Line<T>
where T: PartialEq,

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> PartialOrd for Line<T>
where T: PartialOrd,

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AsTotalOrd for T
where T: PartialOrd,

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PartialOrdExt for T
where T: PartialOrd,

Source§

fn chmin(&mut self, other: T)

Source§

fn chmax(&mut self, other: T)

Source§

fn minmax(self, other: T) -> (T, T)

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.