pub struct FenwickTree<T> { /* private fields */ }Expand description
Fenwick Tree (Binary Indexed Tree).
T is the numeric type stored in the tree. It must be Copy,
Default (the additive identity, typically 0), and support
+= and -.
Implementations§
Source§impl<T> FenwickTree<T>
impl<T> FenwickTree<T>
Sourcepub fn new(nums: &[T]) -> Self
pub fn new(nums: &[T]) -> Self
Build a Fenwick Tree from an initial slice of values.
Runs in O(n log n). For an O(n) build, build an empty tree
and call Self::update for each element.
Sourcepub fn update(&mut self, index: usize, delta: T)
pub fn update(&mut self, index: usize, delta: T)
Add delta to the element at index.
Panics if index >= self.size.
Trait Implementations§
Source§impl<T: Clone> Clone for FenwickTree<T>
impl<T: Clone> Clone for FenwickTree<T>
Source§fn clone(&self) -> FenwickTree<T>
fn clone(&self) -> FenwickTree<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<T> Freeze for FenwickTree<T>
impl<T> RefUnwindSafe for FenwickTree<T>where
T: RefUnwindSafe,
impl<T> Send for FenwickTree<T>where
T: Send,
impl<T> Sync for FenwickTree<T>where
T: Sync,
impl<T> Unpin for FenwickTree<T>where
T: Unpin,
impl<T> UnsafeUnpin for FenwickTree<T>
impl<T> UnwindSafe for FenwickTree<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more