OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
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
33template<typename local_index = size_t>
34class 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
46public:
47
48 typedef void toKernel_type;
49
51 typedef local_index local_index_type;
52
61 inline void init_to_zero(local_index slot, local_index tot_n_cell)
62 {
63 clear();
64 }
65
73 inline Mem_mw & operator=(const Mem_mw & cell)
74 {
75 cl_base = cell.cl_base;
76 return *this;
77 }
78
85 inline void addCell(local_index cell_id, typename base::value_type ele)
86 {
87 //add another neighbor element
88
89 cl_base[cell_id].add(ele);
90 }
91
98 inline void add(local_index cell_id, typename base::value_type ele)
99 {
100 this->addCell(cell_id,ele);
101 }
102
109 inline void remove(local_index cell, local_index ele)
110 {
111 cl_base[cell].remove(ele);
112 }
113
121 inline size_t getNelements(const local_index cell_id) const
122 {
123 auto it = cl_base.find(cell_id);
124 if (it == cl_base.end())
125 return 0;
126
127 return it->second.size();
128 }
129
130 inline auto get(local_index cell, local_index ele) -> decltype(cl_base[0].get(0)) &
131 {
132 auto it = cl_base.find(cell);
133 if (it == cl_base.end())
134 return invalid;
135
136 return it->second.get(ele);
137 }
138
139
140 inline auto get(local_index cell, local_index ele) const -> decltype(cl_base.find(cell)->second.get(0)) &
141 {
142 auto it = cl_base.find(cell);
143 if (it == cl_base.end())
144 return invalid;
145
146 return it->second.get(ele);
147 }
148
149 inline void swap(Mem_mw & cl)
150 {
151 cl_base.swap(cl.cl_base);
152 }
153
154 inline void swap(Mem_mw && cell)
155 {
156 cl_base.swap(cell.cl_base);
157 }
158
159 inline void clear()
160 {
161 cl_base.clear();
162 }
163
164 inline const local_index & getStartId(size_t part_id) const
165 {
166 auto it = cl_base.find(part_id);
167 if (it == cl_base.end())
168 return *(&invalid);
169
170 return it->second.get(0);
171 }
172
173 inline const local_index & getStopId(size_t part_id) const
174 {
175 auto it = cl_base.find(part_id);
176 if (it == cl_base.end())
177 return *(&invalid);
178
179 return *(&it->second.last() + 1);
180 }
181
182 inline const local_index & get_lin(const local_index * part_id) const
183 {
184 return *part_id;
185 }
186
187public:
188
194 inline Mem_mw(size_t slot)
195 :invalid(0)
196 {
197 }
198
204 inline void set_slot(size_t slot)
205 {}
206
207};
208
209
210#endif /* CELLISTMEM_HPP_ */
Class for MEMORY-WISE cell list implementation.
void init_to_zero(local_index slot, local_index tot_n_cell)
Initialize the data structure to zeros.
Mem_mw(size_t slot)
constructor
void addCell(local_index cell_id, typename base::value_type ele)
Add an element to the cell.
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.
Mem_mw & operator=(const Mem_mw &cell)
Copy two data-structure.
openfpm::vector< local_index > base
Base type storing information.
void remove(local_index cell, local_index ele)
Remove an element from the cell.
std::unordered_map< local_index, base > cl_base
std::remove_reference< decltype(std::declval< openfpm::vector< local_index > >().get(0))>::type invalid
In case of invalid element return this.
size_t getNelements(const local_index cell_id) const
Get the number of elements in the cell.
local_index local_index_type
expose the type of the local index
Implementation of 1-D std::vector like structure.