OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
MemMemoryWise.hpp
1 /*
2  * MemMemoryWise.hpp
3  *
4  * Created on: Mar 22, 2015
5  * Last modified: June 25, 2015
6  * Authors: Pietro Incardona, Yaroslav Zaluzhnyi
7  */
8 
9 #ifndef CELLISTMEM_HPP_
10 #define CELLISTMEM_HPP_
11 
12 #include "NN/CellList/CellList.hpp"
13 
33 template<typename local_index = size_t>
34 class Mem_mw
35 {
38 
41  std::unordered_map<local_index,base> cl_base;
42 
44  typename std::remove_reference<decltype(std::declval<openfpm::vector<local_index>>().get(0))>::type invalid;
45 
46 public:
47 
49  typedef local_index loc_index;
50 
59  inline void init_to_zero(local_index slot, local_index tot_n_cell)
60  {
61  clear();
62  }
63 
71  inline Mem_mw & operator=(const Mem_mw & cell)
72  {
73  cl_base = cell.cl_base;
74  return *this;
75  }
76 
83  inline void addCell(local_index cell_id, typename base::value_type ele)
84  {
85  //add another neighbor element
86 
87  cl_base[cell_id].add(ele);
88  }
89 
96  inline void add(local_index cell_id, typename base::value_type ele)
97  {
98  this->addCell(cell_id,ele);
99  }
100 
107  inline void remove(local_index cell, local_index ele)
108  {
109  cl_base[cell].remove(ele);
110  }
111 
119  inline size_t getNelements(const local_index cell_id) const
120  {
121  auto it = cl_base.find(cell_id);
122  if (it == cl_base.end())
123  return 0;
124 
125  return it->second.size();
126  }
127 
128  inline auto get(local_index cell, local_index ele) -> decltype(cl_base[0].get(0)) &
129  {
130  auto it = cl_base.find(cell);
131  if (it == cl_base.end())
132  return invalid;
133 
134  return it->second.get(ele);
135  }
136 
137 
138  inline auto get(local_index cell, local_index ele) const -> decltype(cl_base.find(cell)->second.get(0)) &
139  {
140  auto it = cl_base.find(cell);
141  if (it == cl_base.end())
142  return invalid;
143 
144  return it->second.get(ele);
145  }
146 
147  inline void swap(Mem_mw & cl)
148  {
149  cl_base.swap(cl.cl_base);
150  }
151 
152  inline void swap(Mem_mw && cell)
153  {
154  cl_base.swap(cell.cl_base);
155  }
156 
157  inline void clear()
158  {
159  cl_base.clear();
160  }
161 
162  inline const local_index & getStartId(size_t part_id) const
163  {
164  auto it = cl_base.find(part_id);
165  if (it == cl_base.end())
166  return *(&invalid);
167 
168  return it->second.get(0);
169  }
170 
171  inline const local_index & getStopId(size_t part_id) const
172  {
173  auto it = cl_base.find(part_id);
174  if (it == cl_base.end())
175  return *(&invalid);
176 
177  return *(&it->second.last() + 1);
178  }
179 
180  inline const local_index & get_lin(const local_index * part_id) const
181  {
182  return *part_id;
183  }
184 
185 public:
186 
192  inline Mem_mw(size_t slot)
193  :invalid(0)
194  {
195  }
196 
202  inline void set_slot(size_t slot)
203  {}
204 
205 };
206 
207 
208 #endif /* CELLISTMEM_HPP_ */
void init_to_zero(local_index slot, local_index tot_n_cell)
Initialize the data structure to zeros.
Class for MEMORY-WISE cell list implementation.
Mem_mw & operator=(const Mem_mw &cell)
Copy two data-structure.
size_t getNelements(const local_index cell_id) const
Get the number of elements in the cell.
openfpm::vector< local_index > base
Base type storing information.
void add(local_index cell_id, typename base::value_type ele)
Add an element to the cell.
void set_slot(size_t slot)
Set the number of slots.
std::remove_reference< decltype(std::declval< openfpm::vector< local_index >>().get(0))>::type invalid
In case of invalid element return this.
Mem_mw(size_t slot)
constructor
local_index loc_index
expose the type of the local index
void addCell(local_index cell_id, typename base::value_type ele)
Add an element to the cell.
std::unordered_map< local_index, base > cl_base