fix normal select for different k
s and update plots
This commit is contained in:
parent
c9713418b3
commit
5e80cb7736
7 changed files with 10 additions and 10 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -28,7 +28,7 @@ impl NormalSelect {
|
|||
pub fn partition(&mut self, list: &mut Vec<u64>, lo: usize, hi: usize, pivot: u64) -> usize {
|
||||
use CompareResult::*;
|
||||
|
||||
let mut pivot_index = 0;
|
||||
let mut pivot_index = lo;
|
||||
|
||||
for i in lo..=hi {
|
||||
if self.compare(pivot, list[i]) == EQUAL {
|
||||
|
@ -73,12 +73,12 @@ impl NormalSelect {
|
|||
if self.should_print { println!("list: {:?}; lo: {lo}; hi: {hi}; ord_stat: {ord_stat}; k: {k}", list); }
|
||||
|
||||
let n = hi - lo + 1;
|
||||
let num_groups = if n % 5 == 0 { n / 5 } else { (n / 5) + 1 };
|
||||
let num_groups = if n % k == 0 { n / k } else { (n / k) + 1 };
|
||||
let mut medians: Vec<u64> = vec![0; num_groups];
|
||||
let mut index = 0;
|
||||
for i in (lo..=hi).step_by(5) {
|
||||
if i + 4 <= hi {
|
||||
self.insertion_sort(list, i, i + 4);
|
||||
for i in (lo..=hi).step_by(k) {
|
||||
if i + (k - 1) <= hi {
|
||||
self.insertion_sort(list, i, i + (k - 1));
|
||||
medians[index] = list[i + 2];
|
||||
index += 1;
|
||||
} else {
|
||||
|
@ -94,18 +94,18 @@ impl NormalSelect {
|
|||
println!("pivot_index: {pivot_index}; pivot: {pivot}");
|
||||
}
|
||||
let r = self.partition(list, lo, hi, pivot);
|
||||
let k = r - lo + 1;
|
||||
let i = r - lo + 1;
|
||||
if self.should_print {
|
||||
println!("r: {r}");
|
||||
println!("k: {k}");
|
||||
println!("i: {i}");
|
||||
}
|
||||
|
||||
if k == ord_stat {
|
||||
if i == ord_stat {
|
||||
if self.should_print { println!("k == ord_stat"); }
|
||||
return (r, list[r]);
|
||||
} else if k < ord_stat {
|
||||
} else if i < ord_stat {
|
||||
if self.should_print { println!("k < ord_stat"); }
|
||||
return self._select(list, r + 1, hi, ord_stat - k, k);
|
||||
return self._select(list, r + 1, hi, ord_stat - i, k);
|
||||
} else {
|
||||
if self.should_print { println!("k > ord_stat"); }
|
||||
return self._select(list, lo, r - 1, ord_stat, k);
|
||||
|
|
Loading…
Reference in a new issue