Commit 89161e1d authored by bianucci's avatar bianucci

Add operator< and fix const-ness of move() method in grid_key_dx.

Adding operator< so that grid_key_dx objects can be stored also in ordered data structures like std::set.
Adding const modifier to move() method, since it should be const.
parent 07274cc8
......@@ -143,7 +143,7 @@ public:
invert_assign(t...);
}
__device__ __host__ inline grid_key_dx<dim,index_type> move(int i, int m)
__device__ __host__ inline grid_key_dx<dim,index_type> move(int i, int m) const
{
grid_key_dx<dim,index_type> tmp = *this;
......@@ -336,6 +336,38 @@ public:
return !this->operator==(key_t);
}
/*! \brief Check order of two keys
*
* \param key_t key to check
*
* \return true if this is lexicographically less than other key
*
*/
template<unsigned int dim_t> bool operator<(const grid_key_dx<dim_t> & key_t) const
{
if (dim < dim_t)
{
return true;
}
// Check the two key index by index
for (size_t i = dim-1 ; i >= 0; --i)
{
if (k[i] < key_t.k[i])
{
return true;
}
else if (k[i] > key_t.k[i])
{
return false;
}
}
// identical key
return false;
}
/*! \brief set the Key from a list of numbers
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment