froleyks

dynamic_connectivity.hpp

Dec 5th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #pragma once
  2.  
  3. #include "edge_list.hpp"
  4. #include <atomic>
  5.  
  6. class DynamicConnectivity {
  7. public:
  8.   using Node = long;
  9.  
  10.   DynamicConnectivity();
  11.   explicit DynamicConnectivity(long num_nodes);
  12.  
  13.   // should contain #pragma omp parallel for
  14.   void addEdges(const EdgeList &edges);
  15.  
  16.   bool connected(Node a, Node b) const;
  17.  
  18.   // Must return -1 for roots.
  19.   Node parentOf(Node n) const;
  20.   void printUF();
  21.  
  22. private:
  23.   std::atomic<Node> *union_find;
  24.   std::atomic<uint> *component_size;
  25.  
  26.   Node find_representative(Node a) const;
  27. };
Add Comment
Please, Sign In to add comment