diff --git a/src/algorithm/neighbour/cover_tree.rs b/src/algorithm/neighbour/cover_tree.rs index e329220..53ae286 100644 --- a/src/algorithm/neighbour/cover_tree.rs +++ b/src/algorithm/neighbour/cover_tree.rs @@ -179,7 +179,10 @@ impl> CoverTree } } } - + + if neighbors.len() > k { + neighbors.sort_by(|a, b| a.1.partial_cmp(&b.1).unwrap()); + } Ok(neighbors.into_iter().take(k).collect()) }