calculate stats for separate inserts and deletes

This commit is contained in:
jacekpoz 2024-06-05 17:35:27 +02:00
parent b341d9d1cb
commit 8e1aeff405
Signed by: poz
SSH key fingerprint: SHA256:JyLeVWE4bF3tDnFeUpUaJsPsNlJyBldDGV/dIKSLyN8
2 changed files with 12 additions and 2 deletions

View file

@ -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());
}

View file

@ -244,6 +244,10 @@ impl BinarySearchTree {
self.stats += stats;
ret
}
pub fn reset_stats(&mut self) {
self.stats = Stats::default();
}
}
impl Display for BinarySearchTree {