2016-02-11 13:40:09 +00:00
|
|
|
#ifndef GRID_LEXICOGRAPHIC_H
|
|
|
|
#define GRID_LEXICOGRAPHIC_H
|
|
|
|
|
|
|
|
|
|
|
|
namespace Grid{
|
|
|
|
|
|
|
|
class Lexicographic {
|
|
|
|
public:
|
|
|
|
|
2018-02-24 22:25:39 +00:00
|
|
|
template<class coor_t>
|
2018-03-04 15:52:14 +00:00
|
|
|
static accelerator_inline void CoorFromIndex (coor_t& coor,int index,const coor_t &dims){
|
2016-02-11 13:40:09 +00:00
|
|
|
int nd= dims.size();
|
|
|
|
coor.resize(nd);
|
|
|
|
for(int d=0;d<nd;d++){
|
|
|
|
coor[d] = index % dims[d];
|
|
|
|
index = index / dims[d];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-24 22:25:39 +00:00
|
|
|
template<class coor_t>
|
2018-03-04 15:52:14 +00:00
|
|
|
static accelerator_inline void IndexFromCoor (const coor_t& coor,int &index,const coor_t &dims){
|
2016-02-11 13:40:09 +00:00
|
|
|
int nd=dims.size();
|
|
|
|
int stride=1;
|
|
|
|
index=0;
|
|
|
|
for(int d=0;d<nd;d++){
|
|
|
|
index = index+stride*coor[d];
|
|
|
|
stride=stride*dims[d];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-24 22:25:39 +00:00
|
|
|
template<class coor_t>
|
2018-03-04 15:52:14 +00:00
|
|
|
static accelerator_inline void IndexFromCoorReversed (const coor_t& coor,int &index,const coor_t &dims){
|
2017-10-30 00:03:15 +00:00
|
|
|
int nd=dims.size();
|
|
|
|
int stride=1;
|
|
|
|
index=0;
|
|
|
|
for(int d=nd-1;d>=0;d--){
|
|
|
|
index = index+stride*coor[d];
|
|
|
|
stride=stride*dims[d];
|
|
|
|
}
|
|
|
|
}
|
2018-02-24 22:25:39 +00:00
|
|
|
template<class coor_t>
|
2018-03-04 15:52:14 +00:00
|
|
|
static accelerator_inline void CoorFromIndexReversed (coor_t& coor,int index,const coor_t &dims){
|
2017-10-30 00:03:15 +00:00
|
|
|
int nd= dims.size();
|
|
|
|
coor.resize(nd);
|
|
|
|
for(int d=nd-1;d>=0;d--){
|
|
|
|
coor[d] = index % dims[d];
|
|
|
|
index = index / dims[d];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-02-11 13:40:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|