CXXGraph  0.1.6
CXXGraph is a header only, that manages the Graphs and it's algorithm in C++
CoordinatedRecord.hpp
1 /***********************************************************/
2 /*** ______ ____ ______ _ ***/
3 /*** / ___\ \/ /\ \/ / ___|_ __ __ _ _ __ | |__ ***/
4 /*** | | \ / \ / | _| '__/ _` | '_ \| '_ \ ***/
5 /*** | |___ / \ / \ |_| | | | (_| | |_) | | | | ***/
6 /*** \____/_/\_\/_/\_\____|_| \__,_| .__/|_| |_| ***/
7 /*** |_| ***/
8 /***********************************************************/
9 /*** Header-Only C++ Library for Graph ***/
10 /*** Representation and Algorithms ***/
11 /***********************************************************/
12 /*** Author: ZigRazor ***/
13 /*** E-Mail: zigrazor@gmail.com ***/
14 /***********************************************************/
15 /*** Collaboration: ----------- ***/
16 /***********************************************************/
17 /*** License: AGPL v3.0 ***/
18 /***********************************************************/
19 
20 #ifndef __CXXGRAPH_PARTITIONING_COORDINATEDRECORD_H__
21 #define __CXXGRAPH_PARTITIONING_COORDINATEDRECORD_H__
22 
23 #pragma once
24 
25 #include "Utility/Typedef.hpp"
26 
27 namespace CXXGRAPH
28 {
29  namespace PARTITIONING
30  {
31 
32  template <typename T>
33  class CoordinatedRecord : public Record<T>
34  {
35  private:
36  PartitionMap<T> partitions;
37  std::mutex lock;
38  int degree;
39 
40  public:
43 
44  PartitionMap<T> &getPartitions();
45  void addPartition(int m);
46  bool hasReplicaInPartition(int m);
47  bool getLock();
48  bool releaseLock();
49  int getReplicas();
50  int getDegree();
51  void incrementDegree();
52 
53  void addAll(std::set<int> &set);
54  static std::set<int> intersection(CoordinatedRecord &x, CoordinatedRecord &y);
55  };
56  template <typename T>
57  CoordinatedRecord<T>::CoordinatedRecord() : partitions(), lock()
58  {
59  degree = 0;
60  }
61  template <typename T>
62  CoordinatedRecord<T>::~CoordinatedRecord()
63  {
64  }
65  template <typename T>
66  PartitionMap<T> &CoordinatedRecord<T>::getPartitions()
67  {
68  return partitions;
69  }
70  template <typename T>
71  void CoordinatedRecord<T>::addPartition(int m)
72  {
73  if (m == -1)
74  {
75  std::cout << "ERROR! record.addPartition(-1)" << std::endl;
76  exit(-1);
77  }
78  partitions.insert(m);
79  }
80  template <typename T>
81  bool CoordinatedRecord<T>::hasReplicaInPartition(int m)
82  {
83  return partitions.find(m) != partitions.end();
84  }
85  template <typename T>
86  bool CoordinatedRecord<T>::getLock()
87  {
88  return lock.try_lock();
89  }
90  template <typename T>
91  bool CoordinatedRecord<T>::releaseLock()
92  {
93  lock.unlock();
94  return true;
95  }
96  template <typename T>
97  int CoordinatedRecord<T>::getReplicas()
98  {
99  return partitions.size();
100  }
101  template <typename T>
102  int CoordinatedRecord<T>::getDegree()
103  {
104  return degree;
105  }
106  template <typename T>
107  void CoordinatedRecord<T>::incrementDegree()
108  {
109  degree++;
110  }
111  template <typename T>
112  void CoordinatedRecord<T>::addAll(std::set<int> &set)
113  {
114  partitions.insert(set.begin(), set.end());
115  }
116  template <typename T>
117  std::set<int> CoordinatedRecord<T>::intersection(CoordinatedRecord &x, CoordinatedRecord &y)
118  {
119  std::set<int> result;
120  set_intersection(x.partitions.begin(), x.partitions.end(), y.partitions.begin(), y.partitions.end(),
121  std::inserter(result, result.begin()));
122  return result;
123  }
124  }
125 }
126 
127 #endif // __CXXGRAPH_PARTITIONING_COORDINATEDRECORD_H__
Definition: CoordinatedRecord.hpp:34
Definition: Record.hpp:29