[PATCH] D54442: [llvm-exegesis] Optimize ToProcess in dbScan

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 12 12:57:58 PST 2018


MaskRay updated this revision to Diff 173740.
MaskRay added a comment.

.


Repository:
  rL LLVM

https://reviews.llvm.org/D54442

Files:
  tools/llvm-exegesis/lib/Clustering.cpp


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 <string>
 #include <unordered_set>
 
@@ -120,29 +122,37 @@
     CurrentCluster.PointIndices.push_back(P);
 
     // Process P's neighbors.
-    std::unordered_set<size_t> ToProcess(Neighbors.begin(), Neighbors.end());
+    std::vector<size_t> ToProcess;
+    ToProcess.reserve(NumPoints);
+    std::copy(Neighbors.begin(), Neighbors.end(),
+              std::back_inserter(ToProcess));
+    BitVector Added(NumPoints);
+    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.
         ClusterIdForPoint_[Q] = CurrentCluster.Id;
         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<size_t> Neighbors = rangeQuery(Q);
+      if (Neighbors.size() + 1 >= MinPts)
+        for (size_t P : Neighbors)
+          if (!Added.test(P)) {
+            ToProcess.push_back(P);
+            Added.set(P);
+          }
     }
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54442.173740.patch
Type: text/x-patch
Size: 2082 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181112/7deefd15/attachment.bin>


More information about the llvm-commits mailing list