Struct StaticArq

Source
pub struct StaticArq<T: ArqSpec> { /* private fields */ }
Expand description

Colloquially known as a “segtree” in the sport programming literature, it represents a sequence of elements a_i (0 <= i < size) from a monoid (S, +) on which we want to support fast range operations:

  • update(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

This compact representation is based on a [blog post by Al.Cash] (http://codeforces.com/blog/entry/18051). All nodes have 0 or 2 children. Hence, trees whose size is not a power of two will have multiple roots.

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.

Implementations§

Source§

impl<T: ArqSpec> StaticArq<T>

Source

pub fn new(init_val: &[T::S]) -> Self

Initializes a static balanced binary tree on top of the given sequence.

Source

pub fn update(&mut self, l: usize, r: usize, f: &T::F)

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 r >= size. Note that l > r is valid, meaning an empty range.

Source

pub fn query(&mut self, l: usize, r: usize) -> T::S

Returns the aggregate range query on all entries from l to r, inclusive.

§Panics

Panics if r >= size. Note that l > r is valid, meaning an empty range.

Auto Trait Implementations§

§

impl<T> Freeze for StaticArq<T>

§

impl<T> RefUnwindSafe for StaticArq<T>
where <T as ArqSpec>::S: RefUnwindSafe, <T as ArqSpec>::F: RefUnwindSafe,

§

impl<T> Send for StaticArq<T>
where <T as ArqSpec>::S: Send, <T as ArqSpec>::F: Send,

§

impl<T> Sync for StaticArq<T>
where <T as ArqSpec>::S: Sync, <T as ArqSpec>::F: Sync,

§

impl<T> Unpin for StaticArq<T>
where <T as ArqSpec>::S: Unpin, <T as ArqSpec>::F: Unpin,

§

impl<T> UnwindSafe for StaticArq<T>
where <T as ArqSpec>::S: UnwindSafe, <T as ArqSpec>::F: 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> 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> 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, 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.