OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
vector_dist_operators_list_ker.hpp
1 /*
2  * vector_dist_operators_list_ker.hpp
3  *
4  * Created on: Jun 7, 2019
5  * Author: i-bird
6  */
7 
8 #ifndef VECTOR_DIST_OPERATORS_LIST_KER_HPP_
9 #define VECTOR_DIST_OPERATORS_LIST_KER_HPP_
10 
11 template<typename T>
12 struct ref_wrap
13 {
14  bool is_sorted;
15  T & v;
16 
17  ref_wrap(T & v, bool is_sorted)
18  :v(v),is_sorted(is_sorted)
19  {}
20 
21  ref_wrap & operator=(const ref_wrap<T> & rw)
22  {
23  v = rw.v;
24  return *this;
25  }
26 };
27 
35 template<typename vector_dist_ker_type>
37 {
39 
40 public:
41 
48  void add(vector_dist_ker_type & v, bool is_sorted)
49  {
50  ref_wrap<vector_dist_ker_type> rw(v,is_sorted);
51 
52  vkers.add(rw);
53 
54  if (vkers.size() >= 64)
55  {
56  std::cout << __FILE__ << ":" << __LINE__ << " The array of tracked vector_dist_ker become suspiciously big, are there memory leak ? " << std::endl;
57  }
58  }
59 
66  void update(const vector_dist_ker_type & v)
67  {
68  for (size_t i = 0 ; i < vkers.size() ; i++)
69  {
70  if (vkers.get(i).is_sorted == false)
71  {vkers.get(i).v = v;}
72  }
73  }
74 
75  void update_sort(const vector_dist_ker_type & vs)
76  {
77  for (size_t i = 0 ; i < vkers.size() ; i++)
78  {
79  if (vkers.get(i).is_sorted == true)
80  {vkers.get(i).v = vs;}
81  }
82  }
83 
90  void remove(vector_dist_ker_type & v)
91  {
92  for (size_t i = 0 ; i < vkers.size() ; i++)
93  {
94  if (&vkers.get(i).v == &v)
95  {
96  vkers.remove(i);
97  break;
98  }
99  }
100  }
101 
107  size_t n_entry()
108  {
109  return vkers.size();
110  }
111 
117  bool check(const vector_dist_ker_type & v)
118  {
119  for (size_t i = 0 ; i < vkers.size() ; i++)
120  {
121  if (!(vkers.get(i).v == v))
122  {
123  return false;
124  }
125  }
126 
127  return true;
128  }
129 };
130 
131 #endif /* VECTOR_DIST_OPERATORS_LIST_KER_HPP_ */
void update(const vector_dist_ker_type &v)
Update the addresses of all vector_dist_kernels around.
void add(vector_dist_ker_type &v, bool is_sorted)
Add a new vector_dist_kernel to track.
size_t size()
Stub size.
Definition: map_vector.hpp:211
bool check(const vector_dist_ker_type &v)
Check that all the entries are aligned to the latest vector_dist_ker_type.
size_t n_entry()
Return the number of entries.
void remove(vector_dist_ker_type &v)
Remove one vector_dist_kernels entry.
This class contain a list of all tracked vector_dist_ker around.
Implementation of 1-D std::vector like structure.
Definition: map_vector.hpp:202