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(
rtree: &RTree<GeoPoint>,
candidates: RoaringBitmap,
mut candidates: RoaringBitmap,
point: [f64; 2],
) -> Box<dyn Iterator<Item = RoaringBitmap>> {
let results = rtree
.nearest_neighbor_iter(&point)
.filter_map(move |point| candidates.contains(point.data).then(|| point.data))
.map(|id| iter::once(id).collect::<RoaringBitmap>())
.collect::<Vec<_>>();
let mut results = Vec::new();
for point in rtree.nearest_neighbor_iter(&point) {
if candidates.remove(point.data) {
results.push(std::iter::once(point.data).collect());
if candidates.is_empty() {
break;
}
}
}
Box::new(results.into_iter())
}