pub trait LazyNode: Node {
fn lazy_update(&mut self, i: usize, j: usize);
fn update_lazy_value(&mut self, new_value: &<Self as Node>::Value);
fn lazy_value(&self) -> Option<&<Self as Node>::Value>;
}
Expand description
Required trait by nodes of lazy segment trees. It’s defined as an interface for the operations needed on the lazy_value. It is recommended to implement it using an Option type. See Implementators for some example implementations
Required Methods
fn lazy_update(&mut self, i: usize, j: usize)
fn lazy_update(&mut self, i: usize, j: usize)
The following invariant must be met while implementing this method, if lazy_value is called immediately after this function then it must return None
. (See Option::take)
fn update_lazy_value(&mut self, new_value: &<Self as Node>::Value)
fn update_lazy_value(&mut self, new_value: &<Self as Node>::Value)
The following invariant must be met while implementing this method, if lazy_value is called immediately after this function then it must return Some(&value)
.
fn lazy_value(&self) -> Option<&<Self as Node>::Value>
fn lazy_value(&self) -> Option<&<Self as Node>::Value>
Must return a reference to the current lazy value only if it exists.
Implementors
impl<T> LazyNode for Max<T> where
T: Ord + Clone,
Implementation for maximum range query, the update sets each item in the range to the given value.
impl<T> LazyNode for Min<T> where
T: Ord + Clone,
Implementation for minimum range query, the update sets each item in the range to the given value.
impl<T> LazyNode for PersistentWrapper<T> where
T: LazyNode,
impl<T> LazyNode for Sum<T> where
T: Add<Output = T> + Mul<usize, Output = T> + Clone,
Implementation for sum range query node, the update adds the value to each item in the range.
It assumes that a*n
, where a: T and n: usize is well defined and a*n = a+...+a
with ‘n’ a.
For non-commutative operations, two things will be true lazy_value = lazy_value + new_value
.