Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/fenwicktree.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::fmt::{Debug, Error, Formatter};
use std::ops::{Bound, RangeBounds};

// Reference: https://en.wikipedia.org/wiki/Fenwick_tree
Expand Down Expand Up @@ -56,6 +57,20 @@ impl<T: Clone + std::ops::AddAssign<T>> FenwickTree<T> {
}
}

impl<T: Clone + Debug + std::ops::AddAssign<T>> Debug for FenwickTree<T> {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
f.debug_struct("FenwickTree")
.field("n", &self.n)
.field(
"accum",
&(1..=self.n).map(|i| self.accum(i)).collect::<Vec<_>>(),
)
.field("e", &self.e)
.finish()?;
Ok(())
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down