From 1bbaecd3c36605811f747cfc9806fcc59f3fd9f0 Mon Sep 17 00:00:00 2001 From: NotLeonian <75620009+NotLeonian@users.noreply.github.com> Date: Sun, 13 Apr 2025 22:30:34 +0900 Subject: [PATCH] Enhance LazySegtree Debug implementation with debug_struct and more fields --- src/lazysegtree.rs | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/src/lazysegtree.rs b/src/lazysegtree.rs index 793d03c..9d4a540 100644 --- a/src/lazysegtree.rs +++ b/src/lazysegtree.rs @@ -322,9 +322,8 @@ where } } -// TODO is it useful? use std::{ - fmt::{Debug, Error, Formatter, Write}, + fmt::{Debug, Error, Formatter}, ops::{Bound, RangeBounds}, }; impl Debug for LazySegtree @@ -334,19 +333,34 @@ where ::S: Debug, { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { - for i in 0..self.log { - for j in 0..1 << i { - f.write_fmt(format_args!( - "{:?}[{:?}]\t", - self.d[(1 << i) + j], - self.lz[(1 << i) + j] - ))?; - } - f.write_char('\n')?; - } - for i in 0..self.size { - f.write_fmt(format_args!("{:?}\t", self.d[self.size + i]))?; - } + f.debug_struct("LazySegtree") + .field("n", &self.n) + .field("size", &self.size) + .field("log", &self.log) + .field( + "d", + &(0..self.log) + .map(|i| { + (0..1 << i) + .map(|j| self.d[(1 << i) + j].clone()) + .collect::>() + }) + .chain(vec![(0..self.size) + .map(|i| self.d[self.size + i].clone()) + .collect::>()]) + .collect::>(), + ) + .field( + "lz", + &(0..self.log) + .map(|i| { + (0..1 << i) + .map(|j| self.lz[(1 << i) + j].clone()) + .collect::>() + }) + .collect::>(), + ) + .finish()?; Ok(()) } }