(mut arr: Vec<(K, u32)>, j: usize)
| 364 | } |
| 365 | |
| 366 | fn take_j_smallest<K>(mut arr: Vec<(K, u32)>, j: usize) -> Vec<(K, u32)> { |
| 367 | if j == 0 { |
| 368 | return Vec::new(); |
| 369 | } |
| 370 | if j >= arr.len() { |
| 371 | return arr; |
| 372 | } |
| 373 | |
| 374 | // Find the j-th smallest value |
| 375 | let (_, &mut (_, threshold), _) = |
| 376 | arr.select_nth_unstable_by_key(j - 1, |(_, counter)| *counter); |
| 377 | |
| 378 | // Keep exactly j elements that are <= threshold |
| 379 | let mut remaining = j; |
| 380 | arr.retain(|&(_, val)| { |
| 381 | if remaining > 0 && val <= threshold { |
| 382 | remaining -= 1; |
| 383 | true // keep it |
| 384 | } else { |
| 385 | false // drop it |
| 386 | } |
| 387 | }); |
| 388 | |
| 389 | arr |
| 390 | } |
| 391 | |
| 392 | pub struct Values<'a, K: 'a, V: 'a> { |
| 393 | iter: dashmap::iter::Iter<'a, K, (V, u32), std::hash::RandomState, DashMap<K, (V, u32)>>, |
no test coverage detected