test: test selection
This commit is contained in:
@@ -196,8 +196,20 @@ fn encrypted_knn_classify(
|
|||||||
}
|
}
|
||||||
println!(); // New line after progress bar
|
println!(); // New line after progress bar
|
||||||
|
|
||||||
println!("📊 Sorting {} distances...", distances.len());
|
println!("📊 Finding {} smallest distances using selection...", k);
|
||||||
bitonic_sort_encrypted(&mut distances, true);
|
|
||||||
|
// Use selection instead of full sorting to match plain version behavior
|
||||||
|
for target_pos in 0..k.min(distances.len()) {
|
||||||
|
// Find minimum in remaining elements [target_pos..]
|
||||||
|
for i in (target_pos + 1)..distances.len() {
|
||||||
|
let should_swap = distances[i].distance.lt(&distances[target_pos].distance);
|
||||||
|
|
||||||
|
// Use split_at_mut to avoid borrowing issues
|
||||||
|
let (left, right) = distances.split_at_mut(i);
|
||||||
|
encrypted_conditional_swap(&mut left[target_pos], &mut right[0], &should_swap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
distances.truncate(k);
|
distances.truncate(k);
|
||||||
|
|
||||||
distances.iter().map(|n| n.index.clone()).collect()
|
distances.iter().map(|n| n.index.clone()).collect()
|
||||||
|
|||||||
Reference in New Issue
Block a user