Trait FenwickTree

Source
pub trait FenwickTree {
    type Value: FenwickTreeValue;

    // Required methods
    fn query(&self, idx: usize) -> Result<Self::Value, TreeError>;
    fn update(
        &mut self,
        idx: usize,
        value: Self::Value,
    ) -> Result<(), TreeError>;

    // Provided method
    fn range_query(
        &self,
        from: usize,
        to: usize,
    ) -> Result<Self::Value, TreeError> { ... }
}
Expand description

Fenwick tree trait, API of that data structure

Required Associated Types§

Required Methods§

Source

fn query(&self, idx: usize) -> Result<Self::Value, TreeError>

Returns sum of values across all indexes lesser or equal than idx.

§Errors

This function will returns an error if idx is out of bounds. GrowingFenwick tree implementation never returns error.

Source

fn update(&mut self, idx: usize, value: Self::Value) -> Result<(), TreeError>

Add new value to the idx stored value, which is 0 by default.

§Errors

This function will return an error if idx is out of bounds. GrowingFenwick tree implementation never returns error.

Provided Methods§

Source

fn range_query(&self, from: usize, to: usize) -> Result<Self::Value, TreeError>

Returns sum of values across all indexes in between from and to indexes (including edges).

§Errors

This function will return an error if any index is out of bounds. GrowingFenwick tree implementation never return error.

Implementors§