OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
space_key.hpp
1/*
2 * space_key.hpp
3 *
4 * Created on: Mar 6, 2015
5 * Author: Pietro Incardona
6 */
7
8#ifndef SPACE_KEY_HPP_
9#define SPACE_KEY_HPP_
10
11
21template<unsigned int dim, typename T>
23{
24public:
25
28 {}
29
31 space_key_dx(T (& k)[dim])
32 {
33 for (int i = 0 ; i < dim ; i++)
34 this->k[i] = k[i];
35 }
36
38 space_key_dx(const T (& k)[dim])
39 {
40 for (int i = 0 ; i < dim ; i++)
41 this->k[i] = k[i];
42 }
43
45 space_key_dx(const T v,const T...t)
46 {
47 k[dim-1] = v;
48 invert_assign(t...);
49 }
50
53 inline void zero()
54 {
55 for (int i = 0 ; i < dim ; i++)
56 {
57 k[i] = 0;
58 }
59 }
60
63 inline void invalid()
64 {
65 for (int i = 0 ; i < dim ; i++)
66 {
67 k[i] = -1;
68 }
69 }
70
71 /* \brief Check if two key are the same
72 *
73 * \param key_t key to check
74 *
75 * \return true if the two key are identical
76 *
77 */
78
79 template<unsigned int dim_t> bool operator==(space_key_dx<dim_t,T> & key_t)
80 {
81 if (dim != dim_t)
82 {
83 return false;
84 }
85
86 // Check the two key index by index
87
88 for (int i = 0 ; i < dim ; i++)
89 {
90 if (k[i] != key_t.k[i])
91 {
92 return false;
93 }
94 }
95
96 // identical key
97 return true;
98 }
99
101 template<typename a, typename ...T>void set(a v, T...t)
102 {
103 k[dim-1] = v;
104 invert_assign(t...);
105 }
106
114 mem_id value(size_t i) const
115 {
116 return k[i];
117 }
118
127 mem_id get(size_t i) const
128 {
129 return k[i];
130 }
131
140 void set_d(size_t i, mem_id id)
141 {
142#ifdef DEBUG
143
144 if (i >= dim)
145 std::cerr << "grid_key_dx error: " << __FILE__ << " " << __LINE__ << " try to access dimension " << i << " on a grid_key_dx of size " << dim << "\n";
146
147#endif
148 k[i] = id;
149 }
150
152 mem_id k[dim];
153
154private:
155
161 template<typename a, typename ...T>void invert_assign(a v,T...t)
162 {
163 k[sizeof...(T)] = v;
164 invert_assign(t...);
165 }
166
167 template<typename a, typename ...T>void invert_assign(a v)
168 {
169 k[0] = v;
170 }
171
172 void invert_assign()
173 {
174 }
175
176};
177
178
179#endif /* SPACE_KEY_HPP_ */
grid_key_dx is the key to access any element in the grid
Definition space_key.hpp:23
void set_d(size_t i, mem_id id)
Set the i index.
space_key_dx()
Constructor.
Definition space_key.hpp:27
void invalid()
Set to invalid the key.
Definition space_key.hpp:63
void invert_assign(a v, T...t)
Recursively invert the assignment.
space_key_dx(T(&k)[dim])
Constructor from buffer.
Definition space_key.hpp:31
mem_id get(size_t i) const
Get the i index.
space_key_dx(const T(&k)[dim])
Constructor from buffer.
Definition space_key.hpp:38
void set(a v, T...t)
set the grid key from a list of numbers
mem_id k[dim]
structure that store all the index
void zero()
Set to zero the key.
Definition space_key.hpp:53
space_key_dx(const T v, const T...t)
Construct a grid key from a list of numbers.
Definition space_key.hpp:45
mem_id value(size_t i) const
Get the i index.