Skip to content

Commit 1bbaecd

Browse files
committed
Enhance LazySegtree Debug implementation with debug_struct and more fields
1 parent 032ef62 commit 1bbaecd

File tree

1 file changed

+29
-15
lines changed

1 file changed

+29
-15
lines changed

src/lazysegtree.rs

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,8 @@ where
322322
}
323323
}
324324

325-
// TODO is it useful?
326325
use std::{
327-
fmt::{Debug, Error, Formatter, Write},
326+
fmt::{Debug, Error, Formatter},
328327
ops::{Bound, RangeBounds},
329328
};
330329
impl<F> Debug for LazySegtree<F>
@@ -334,19 +333,34 @@ where
334333
<F::M as Monoid>::S: Debug,
335334
{
336335
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
337-
for i in 0..self.log {
338-
for j in 0..1 << i {
339-
f.write_fmt(format_args!(
340-
"{:?}[{:?}]\t",
341-
self.d[(1 << i) + j],
342-
self.lz[(1 << i) + j]
343-
))?;
344-
}
345-
f.write_char('\n')?;
346-
}
347-
for i in 0..self.size {
348-
f.write_fmt(format_args!("{:?}\t", self.d[self.size + i]))?;
349-
}
336+
f.debug_struct("LazySegtree")
337+
.field("n", &self.n)
338+
.field("size", &self.size)
339+
.field("log", &self.log)
340+
.field(
341+
"d",
342+
&(0..self.log)
343+
.map(|i| {
344+
(0..1 << i)
345+
.map(|j| self.d[(1 << i) + j].clone())
346+
.collect::<Vec<_>>()
347+
})
348+
.chain(vec![(0..self.size)
349+
.map(|i| self.d[self.size + i].clone())
350+
.collect::<Vec<_>>()])
351+
.collect::<Vec<_>>(),
352+
)
353+
.field(
354+
"lz",
355+
&(0..self.log)
356+
.map(|i| {
357+
(0..1 << i)
358+
.map(|j| self.lz[(1 << i) + j].clone())
359+
.collect::<Vec<_>>()
360+
})
361+
.collect::<Vec<_>>(),
362+
)
363+
.finish()?;
350364
Ok(())
351365
}
352366
}

0 commit comments

Comments
 (0)