From 9e03a7e1d3254fbee0268611ff014967050877de Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Mon, 16 Jul 2018 11:10:02 +1000 Subject: [PATCH] Optimise unordered set differencing --- .../qgsalgorithmdbscanclustering.cpp | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/analysis/processing/qgsalgorithmdbscanclustering.cpp b/src/analysis/processing/qgsalgorithmdbscanclustering.cpp index 69ca6a67444..dcebb680c5e 100644 --- a/src/analysis/processing/qgsalgorithmdbscanclustering.cpp +++ b/src/analysis/processing/qgsalgorithmdbscanclustering.cpp @@ -102,16 +102,6 @@ struct KDBushDataHashById } }; -bool operator <( const QgsSpatialIndexKDBushData &data, const QgsFeatureId id ) -{ - return data.id < id; -}; - -bool operator <( const QgsFeatureId id, const QgsSpatialIndexKDBushData &data ) -{ - return id < data.id; -}; - QVariantMap QgsDbscanClusteringAlgorithm::processAlgorithm( const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) { std::unique_ptr< QgsProcessingFeatureSource > source( parameterAsSource( parameters, QStringLiteral( "INPUT" ), context ) ); @@ -287,10 +277,13 @@ void QgsDbscanClusteringAlgorithm::dbscan( const std::size_t minSize, if ( within2.size() >= minSize ) { // expand neighbourhood - std::set_difference( within2.begin(), - within2.end(), - visited.begin(), visited.end(), - std::inserter( within, within.end() ) ); + std::copy_if( within2.begin(), + within2.end(), + std::inserter( within, within.end() ), + [&visited]( const QgsSpatialIndexKDBushData & needle ) + { + return visited.find( needle.id ) == visited.end(); + } ); } if ( !borderPointsAreNoise || within2.size() >= minSize ) {