Stop iterating through the whole list of points

We stop when there is no possible candidates left
This commit is contained in:
Tamo 2021-09-13 12:42:06 +02:00 committed by Irevoire
parent cfc62a1c15
commit 91ce4d1721
No known key found for this signature in database
GPG Key ID: 7A6A970C96104F1B

View File

@ -104,14 +104,18 @@ impl Criterion for Geo<'_> {
fn geo_point( fn geo_point(
rtree: &RTree<GeoPoint>, rtree: &RTree<GeoPoint>,
candidates: RoaringBitmap, mut candidates: RoaringBitmap,
point: [f64; 2], point: [f64; 2],
) -> Box<dyn Iterator<Item = RoaringBitmap>> { ) -> Box<dyn Iterator<Item = RoaringBitmap>> {
let results = rtree let mut results = Vec::new();
.nearest_neighbor_iter(&point) for point in rtree.nearest_neighbor_iter(&point) {
.filter_map(move |point| candidates.contains(point.data).then(|| point.data)) if candidates.remove(point.data) {
.map(|id| iter::once(id).collect::<RoaringBitmap>()) results.push(std::iter::once(point.data).collect());
.collect::<Vec<_>>(); if candidates.is_empty() {
break;
}
}
}
Box::new(results.into_iter()) Box::new(results.into_iter())
} }