pub trait LazyNode: Node {
// Required methods
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 Implementors for some example implementations.
Required Methods§
Sourcefn 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
)
Sourcefn 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)
.
Sourcefn 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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
impl<T> LazyNode for LazySetWrapper<T>where
T: Node,
impl<T> LazyNode for PersistentWrapper<T>where
T: LazyNode,
impl<T> LazyNode for Sum<T>
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
.