Index: tools/llvm-exegesis/lib/Clustering.cpp =================================================================== --- tools/llvm-exegesis/lib/Clustering.cpp +++ tools/llvm-exegesis/lib/Clustering.cpp @@ -8,6 +8,8 @@ //===----------------------------------------------------------------------===// #include "Clustering.h" +#include "llvm/ADT/BitVector.h" + #include #include @@ -120,11 +122,17 @@ CurrentCluster.PointIndices.push_back(P); // Process P's neighbors. - std::unordered_set ToProcess(Neighbors.begin(), Neighbors.end()); + std::vector ToProcess; + ToProcess.reserve(NumPoints - 1); + std::copy(Neighbors.begin(), Neighbors.end(), + std::back_inserter(ToProcess)); + BitVector Added(NumPoints - 1); + for (size_t Q : Neighbors) + Added.set(Q); while (!ToProcess.empty()) { // Retrieve a point from the set. - const size_t Q = *ToProcess.begin(); - ToProcess.erase(Q); + size_t Q = ToProcess.back(); + ToProcess.pop_back(); if (ClusterIdForPoint_[Q].isNoise()) { // Change noise point to border point. @@ -132,17 +140,19 @@ CurrentCluster.PointIndices.push_back(Q); continue; } - if (!ClusterIdForPoint_[Q].isUndef()) { - continue; // Previously processed. - } + if (!ClusterIdForPoint_[Q].isUndef()) + continue; // Add Q to the current custer. ClusterIdForPoint_[Q] = CurrentCluster.Id; CurrentCluster.PointIndices.push_back(Q); // And extend to the neighbors of Q if the region is dense enough. - const auto Neighbors = rangeQuery(Q); - if (Neighbors.size() + 1 >= MinPts) { - ToProcess.insert(Neighbors.begin(), Neighbors.end()); - } + const std::vector Neighbors = rangeQuery(Q); + if (Neighbors.size() + 1 >= MinPts) + for (size_t P : Neighbors) + if (!Added.test(P)) { + ToProcess.push_back(P); + Added.set(P); + } } }