We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 032ef62 commit b4b228dCopy full SHA for b4b228d
src/fenwicktree.rs
@@ -1,3 +1,4 @@
1
+use std::fmt::{Debug, Error, Formatter};
2
use std::ops::{Bound, RangeBounds};
3
4
// Reference: https://en.wikipedia.org/wiki/Fenwick_tree
@@ -56,6 +57,20 @@ impl<T: Clone + std::ops::AddAssign<T>> FenwickTree<T> {
56
57
}
58
59
60
+impl<T: Clone + Debug + std::ops::AddAssign<T>> Debug for FenwickTree<T> {
61
+ fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
62
+ f.debug_struct("FenwickTree")
63
+ .field("n", &self.n)
64
+ .field(
65
+ "accum",
66
+ &(1..=self.n).map(|i| self.accum(i)).collect::<Vec<_>>(),
67
+ )
68
+ .field("e", &self.e)
69
+ .finish()?;
70
+ Ok(())
71
+ }
72
+}
73
+
74
#[cfg(test)]
75
mod tests {
76
use super::*;
0 commit comments