[−][src]Struct contest_algorithms::arq_tree::ArqTree
Colloquially known as a "segtree" in the sport programming literature, it represents a sequence of elements a_i (0 <= i < size) from a monoid (M, +) on which we want to support fast range operations:
- modify(l, r, f) replaces a_i (l <= i <= r) by f(a_i) for an endomorphism f
- query(l, r) returns the aggregate a_l + a_{l+1} + ... + a_r
Future work: ArqTree would lend itself naturally to Rust's ownership system. Initially, we should only have access to the root nodes: if size is a power of two, there is a unique root at index 1. arq.push(i) locks i and acquires access to its children. arq.pull(i) is called when the lock on i is released.
Methods
impl<T: ArqSpec> ArqTree<T> where
T::F: Clone,
[src]
T::F: Clone,
pub fn new(init_val: Vec<T::M>) -> Self
[src]
Initializes a static balanced tree on top of the given sequence.
pub fn modify(&mut self, l: usize, r: usize, f: &T::F)
[src]
Applies the endomorphism f to all entries from l to r, inclusive. If l == r, the updates are eager. Otherwise, they are lazy.
Panics
Panics if l or r is out of range.
pub fn query(&mut self, l: usize, r: usize) -> T::M
[src]
Returns the aggregate range query on all entries from l to r, inclusive.
Panics
Panics if l or r is out of range.
Auto Trait Implementations
impl<T> Send for ArqTree<T> where
<T as ArqSpec>::F: Send,
<T as ArqSpec>::M: Send,
<T as ArqSpec>::F: Send,
<T as ArqSpec>::M: Send,
impl<T> Unpin for ArqTree<T> where
<T as ArqSpec>::F: Unpin,
<T as ArqSpec>::M: Unpin,
<T as ArqSpec>::F: Unpin,
<T as ArqSpec>::M: Unpin,
impl<T> Sync for ArqTree<T> where
<T as ArqSpec>::F: Sync,
<T as ArqSpec>::M: Sync,
<T as ArqSpec>::F: Sync,
<T as ArqSpec>::M: Sync,
impl<T> UnwindSafe for ArqTree<T> where
<T as ArqSpec>::F: UnwindSafe,
<T as ArqSpec>::M: UnwindSafe,
<T as ArqSpec>::F: UnwindSafe,
<T as ArqSpec>::M: UnwindSafe,
impl<T> RefUnwindSafe for ArqTree<T> where
<T as ArqSpec>::F: RefUnwindSafe,
<T as ArqSpec>::M: RefUnwindSafe,
<T as ArqSpec>::F: RefUnwindSafe,
<T as ArqSpec>::M: RefUnwindSafe,
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,