From 37f05d1ff0bbca6b83580fe6de2813c3af397bfb Mon Sep 17 00:00:00 2001 From: raj_mathe Date: Thu, 14 Apr 2022 05:16:53 +0200 Subject: [PATCH] master > master: code-rust - debug logging auslagern --- code/rust/src/graphs/tarjan.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/code/rust/src/graphs/tarjan.rs b/code/rust/src/graphs/tarjan.rs index bc00161..06b5c01 100644 --- a/code/rust/src/graphs/tarjan.rs +++ b/code/rust/src/graphs/tarjan.rs @@ -67,10 +67,7 @@ fn tarjan_visit(gph: &Graph, v: &T, ctx: &mut Context) } } ctx.set_state(v, State::FINISHED); - if ctx.debug { - let info = ctx.get_info(&v); - log_debug!("node, index, component: ({}, {}, {})", info.node, info.index, info.root); - } + ctx.log_info(&v); if ctx.get_index(v) == ctx.get_root(v) { let mut component: Vec = Vec::new(); @@ -155,21 +152,27 @@ impl Context self.update_infos(u, info); } - fn get_info(self: &mut Self, u: &T) -> NodeInformation { + fn get_info(self: &Self, u: &T) -> NodeInformation { return *self.infos.get(u).unwrap(); } - fn get_state(self: &mut Self, u: &T) -> State { + fn get_state(self: &Self, u: &T) -> State { return self.get_info(u).state; } - fn get_root(self: &mut Self, u: &T) -> usize { + fn get_root(self: &Self, u: &T) -> usize { return self.get_info(u).root; } - fn get_index(self: &mut Self, u: &T) -> usize { + fn get_index(self: &Self, u: &T) -> usize { return self.get_info(u).index; } + + fn log_info(self: &Self, u: &T) { + if !self.debug { return; } + let info = self.get_info(&u); + log_debug!("node, index, component: ({}, {}, {})", info.node, info.index, info.root); + } } impl NodeInformation