From 2d1a0c4568fcb6a1e0c57c526329e4665dfbddc7 Mon Sep 17 00:00:00 2001 From: Vitaly Lysenkov Date: Fri, 19 Mar 2021 14:14:28 +0100 Subject: [PATCH 1/3] Optimize RadiusResultSet::copy Perform std::partial_sort instead of full std::sort in RadiusResultSet if not all items need to be returned. --- src/cpp/flann/util/result_set.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cpp/flann/util/result_set.h b/src/cpp/flann/util/result_set.h index 90e5643c..1e7cc382 100644 --- a/src/cpp/flann/util/result_set.h +++ b/src/cpp/flann/util/result_set.h @@ -492,7 +492,12 @@ class RadiusResultSet : public ResultSet if (sorted) { // std::sort_heap(dist_index_.begin(), dist_index_.end()); // sort seems faster here, even though dist_index_ is a heap - std::sort(dist_index_.begin(), dist_index_.end()); + std::partial_sort( + dist_index_.begin(), + num_elements Date: Tue, 30 Mar 2021 16:19:03 +0200 Subject: [PATCH 2/3] Update result_set.h Branched between sort and partial_sort; used the more explicit dist_index_.size() instead of size(). --- src/cpp/flann/util/result_set.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/cpp/flann/util/result_set.h b/src/cpp/flann/util/result_set.h index 1e7cc382..fe2ed12a 100644 --- a/src/cpp/flann/util/result_set.h +++ b/src/cpp/flann/util/result_set.h @@ -492,15 +492,14 @@ class RadiusResultSet : public ResultSet if (sorted) { // std::sort_heap(dist_index_.begin(), dist_index_.end()); // sort seems faster here, even though dist_index_ is a heap - std::partial_sort( - dist_index_.begin(), - num_elements Date: Tue, 30 Mar 2021 16:21:19 +0200 Subject: [PATCH 3/3] Update result_set.h Fix formatting. --- src/cpp/flann/util/result_set.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cpp/flann/util/result_set.h b/src/cpp/flann/util/result_set.h index fe2ed12a..3e42d7c0 100644 --- a/src/cpp/flann/util/result_set.h +++ b/src/cpp/flann/util/result_set.h @@ -492,12 +492,12 @@ class RadiusResultSet : public ResultSet if (sorted) { // std::sort_heap(dist_index_.begin(), dist_index_.end()); // sort seems faster here, even though dist_index_ is a heap - if (num_elements