Only sort in CoverTree::find function if there are more than k points
Sorting only needs to be done if the list of KNN candidates is greater than length k.
This commit is contained in:
@@ -180,7 +180,9 @@ impl<T: Debug + PartialEq, F: RealNumber, D: Distance<T, F>> CoverTree<T, F, D>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
neighbors.sort_by(|a, b| a.1.partial_cmp(&b.1).unwrap());
|
if neighbors.len() > k {
|
||||||
|
neighbors.sort_by(|a, b| a.1.partial_cmp(&b.1).unwrap());
|
||||||
|
}
|
||||||
Ok(neighbors.into_iter().take(k).collect())
|
Ok(neighbors.into_iter().take(k).collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user