calculate stats for separate inserts and deletes
This commit is contained in:
parent
b341d9d1cb
commit
8e1aeff405
2 changed files with 12 additions and 2 deletions
|
@ -114,23 +114,29 @@ fn main() -> io::Result<()> {
|
||||||
|
|
||||||
for i in gen_asc(n) {
|
for i in gen_asc(n) {
|
||||||
asc.insert(i);
|
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());
|
asc_heights_clone.get_mut(&n).unwrap().push(asc.height());
|
||||||
}
|
}
|
||||||
for i in gen_rand(n) {
|
for i in gen_rand(n) {
|
||||||
asc.delete(i);
|
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_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);
|
let mut rand = BinarySearchTree::new(n as usize);
|
||||||
|
|
||||||
for i in gen_rand(n) {
|
for i in gen_rand(n) {
|
||||||
rand.insert(i);
|
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());
|
rand_heights_clone.get_mut(&n).unwrap().push(rand.height());
|
||||||
}
|
}
|
||||||
for i in gen_rand(n) {
|
for i in gen_rand(n) {
|
||||||
rand.delete(i);
|
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());
|
rand_heights_clone.get_mut(&n).unwrap().push(rand.height());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -244,6 +244,10 @@ impl BinarySearchTree {
|
||||||
self.stats += stats;
|
self.stats += stats;
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn reset_stats(&mut self) {
|
||||||
|
self.stats = Stats::default();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for BinarySearchTree {
|
impl Display for BinarySearchTree {
|
||||||
|
|
Loading…
Reference in a new issue