From 8e1aeff405e49c1a6275ba41fdc91edba5f7ac7a Mon Sep 17 00:00:00 2001 From: jacekpoz Date: Wed, 5 Jun 2024 17:35:27 +0200 Subject: [PATCH] calculate stats for separate inserts and deletes --- lab4/zad2/src/main.rs | 10 ++++++++-- libtree/src/lib.rs | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lab4/zad2/src/main.rs b/lab4/zad2/src/main.rs index 8774c1b..f7b103c 100644 --- a/lab4/zad2/src/main.rs +++ b/lab4/zad2/src/main.rs @@ -114,23 +114,29 @@ fn main() -> io::Result<()> { for i in gen_asc(n) { asc.insert(i); + asc_results_clone.get_mut(&n).unwrap().push(asc.stats.clone()); + asc.reset_stats(); asc_heights_clone.get_mut(&n).unwrap().push(asc.height()); } for i in gen_rand(n) { asc.delete(i); + asc_results_clone.get_mut(&n).unwrap().push(asc.stats.clone()); + asc.reset_stats(); asc_heights_clone.get_mut(&n).unwrap().push(asc.height()); } - asc_results_clone.get_mut(&n).unwrap().push(asc.stats.clone()); - let mut rand = BinarySearchTree::new(n as usize); for i in gen_rand(n) { rand.insert(i); + rand_results_clone.get_mut(&n).unwrap().push(rand.stats.clone()); + rand.reset_stats(); rand_heights_clone.get_mut(&n).unwrap().push(rand.height()); } for i in gen_rand(n) { rand.delete(i); + rand_results_clone.get_mut(&n).unwrap().push(rand.stats.clone()); + rand.reset_stats(); rand_heights_clone.get_mut(&n).unwrap().push(rand.height()); } diff --git a/libtree/src/lib.rs b/libtree/src/lib.rs index 8be2797..cfbe58a 100644 --- a/libtree/src/lib.rs +++ b/libtree/src/lib.rs @@ -244,6 +244,10 @@ impl BinarySearchTree { self.stats += stats; ret } + + pub fn reset_stats(&mut self) { + self.stats = Stats::default(); + } } impl Display for BinarySearchTree {