Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Optimise unordered set differencing
  • Loading branch information
nyalldawson committed Jul 16, 2018
1 parent e46b00d commit 9e03a7e
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions src/analysis/processing/qgsalgorithmdbscanclustering.cpp
Expand Up @@ -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 &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
{
std::unique_ptr< QgsProcessingFeatureSource > source( parameterAsSource( parameters, QStringLiteral( "INPUT" ), context ) );
Expand Down Expand Up @@ -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 )
{
Expand Down

0 comments on commit 9e03a7e

Please sign in to comment.