Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[core] Skip duplicated IDs when querying point annotations #6655

Merged
merged 1 commit into from
Oct 12, 2016

Conversation

brunoabinader
Copy link
Member

Extracted out of #3563.

/cc @ivovandongen

@brunoabinader brunoabinader added bug Core The cross-platform C++ core, aka mbgl labels Oct 11, 2016
@mention-bot
Copy link

@brunoabinader, thanks for your PR! By analyzing the history of the files in this pull request, we identified @1ec5, @jfirebaugh and @kkaefer to be potential reviewers.

@@ -755,7 +755,10 @@ AnnotationIDs Map::queryPointAnnotations(const ScreenBox& box) {
for (auto &feature : features) {
assert(feature.id);
assert(*feature.id <= std::numeric_limits<AnnotationID>::max());
ids.push_back(static_cast<AnnotationID>(feature.id->get<uint64_t>()));
AnnotationID id = static_cast<AnnotationID>(feature.id->get<uint64_t>());
if (std::find(ids.begin(), ids.end(), id) == ids.end()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an O(n²) algorithm. Better use a set to do deduplication.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now using AnnotationIDs as a typedef for std::set<AnnotationID>. This involves updating platform code that uses Map::queryPointAnnotations().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now using AnnotationIDs as a typedef for std::set.

It turned out that platform code logic depended on particularities of std::vector e.g. ability to reassign member values via std::remove_if that would end up adding more code complexity by converting it to an approach in which std::set is compatible with.

Thus, I'm keeping AnnotationIDs as a std::vector. I'm using std::set internally when issuing the query and later moving those values to a std::vector, preserving linear complexity.

@brunoabinader brunoabinader force-pushed the filter-query-point-annotations branch 6 times, most recently from 325b48f to 862c198 Compare October 12, 2016 04:39
@brunoabinader brunoabinader merged commit 436a22e into master Oct 12, 2016
@brunoabinader brunoabinader deleted the filter-query-point-annotations branch October 12, 2016 15:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Core The cross-platform C++ core, aka mbgl
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants