add immutable select k

This commit is contained in:
jacekpoz 2024-05-09 02:33:39 +02:00
parent 2d8f0a46f3
commit e791acc2fe
Signed by: poz
SSH key fingerprint: SHA256:JyLeVWE4bF3tDnFeUpUaJsPsNlJyBldDGV/dIKSLyN8

View file

@ -112,9 +112,13 @@ impl NormalSelect {
} }
} }
pub fn select_k(&mut self, list: &mut Vec<u64>, order_statistic: usize, k: usize) -> u64 { pub fn select_k_mut(&mut self, list: &mut Vec<u64>, order_statistic: usize, k: usize) -> u64 {
self._select(list, 0, list.len() - 1, order_statistic, k).1 self._select(list, 0, list.len() - 1, order_statistic, k).1
} }
pub fn select_k(&mut self, list: &Vec<u64>, order_statistic: usize, k: usize) -> u64 {
let mut list_clone = list.clone();
self._select(&mut list_clone, 0, list.len() - 1, order_statistic, k).1
}
} }
impl Select for NormalSelect { impl Select for NormalSelect {
@ -128,7 +132,7 @@ impl Select for NormalSelect {
} }
fn select_mut(&mut self, list: &mut Vec<u64>, order_statistic: usize) -> u64 { fn select_mut(&mut self, list: &mut Vec<u64>, order_statistic: usize) -> u64 {
self.select_k(list, order_statistic, 5) self.select_k_mut(list, order_statistic, 5)
} }
fn num_comp(&self) -> u64 { fn num_comp(&self) -> u64 {