8 #include <initializer_list> 11 #include "../../types.hpp" 15 namespace wavepackets {
46 template<
class UINT, dim_t D>
50 friend struct std::hash<waveblocks::wavepackets::shapes::TinyMultiIndex<UINT,D> >;
51 friend struct std::equal_to<waveblocks::wavepackets::shapes::TinyMultiIndex<UINT,D> >;
63 if (l > std::numeric_limits<int>::max())
64 return std::numeric_limits<int>::max();
84 return BITS_PER_ENTRY*index_;
89 return (UINT(1)<<BITS_PER_ENTRY)-1;
92 inline int get()
const 94 return (values_ >> offset()) & mask();
97 inline void set(
int value)
99 assert (value >= 0 && UINT(value) <= mask());
101 values_ &= ~(mask() << offset());
102 values_ |= (UINT(value) & mask()) << offset();
106 Entry(UINT &values, std::size_t index) : values_(values), index_(index) {}
122 value =
get() + value;
129 value =
get() - value;
136 value =
get() * value;
143 value =
get() / value;
150 value =
get() % value;
166 : values_(that.values_)
171 for (
dim_t d = 0; d < D; d++)
172 operator[](d) = that[d];
178 for (
typename std::initializer_list<int>::iterator it = list.begin(); it != list.end() && axis < D; it++) {
179 if (*it >
limit(axis))
180 throw std::range_error(
"this multi-index implementation is unable to store a larger value than " +
std::to_string(
limit(axis)));
195 return (values_ >> BITS_PER_ENTRY*((D-1)-index)) & ( (UINT(1)<<
BITS_PER_ENTRY)-1 );
200 return Entry(values_, (D-1)-index);
205 return values_ == that.
values_;
210 return values_ != that.
values_;
213 operator std::array<int,D>()
const 215 std::array<int,D> copy;
216 for (
dim_t d = 0; d < D; d++) {
223 template<
class UINT, dim_t D>
224 std::ostream &operator<<(std::ostream &out, const TinyMultiIndex<UINT, D> &index)
227 for (
dim_t i = 0; i < D-1; i++)
228 std::cout << index[i] <<
", ";
230 std::cout << index[D-1];
246 template<
class UINT, waveblocks::dim_t D>
247 struct less<
waveblocks::wavepackets::shapes::TinyMultiIndex<UINT,D> >
257 bool operator()(
const MultiIndex &first,
const MultiIndex &second)
const 269 template<
class UINT, waveblocks::dim_t D>
270 struct hash<
waveblocks::wavepackets::shapes::TinyMultiIndex<UINT,D> >
288 template<
class UINT, waveblocks::dim_t D>
289 struct equal_to<
waveblocks::wavepackets::shapes::TinyMultiIndex<UINT,D> >
299 bool operator()(
const MultiIndex &first,
const MultiIndex &second)
const Definition: tiny_multi_index.hpp:74
std::string to_string(T in)
Definition: to_string.hpp:10
Definition: coefficients_file_parser.cpp:10
TinyMultiIndex()
Definition: tiny_multi_index.hpp:161
int get() const
Definition: tiny_multi_index.hpp:92
static const std::size_t BITS_PER_ENTRY
Definition: tiny_multi_index.hpp:72
bool operator()(const MultiIndex &first, const MultiIndex &second) const
Definition: tiny_multi_index.hpp:299
bool result_type
Definition: tiny_multi_index.hpp:255
Entry & operator+=(int value)
Definition: tiny_multi_index.hpp:120
waveblocks::wavepackets::shapes::TinyMultiIndex< UINT, D > MultiIndex
Definition: tiny_multi_index.hpp:250
MultiIndex second_argument_type
Definition: tiny_multi_index.hpp:254
UINT mask() const
Definition: tiny_multi_index.hpp:87
Definition: stdarray2stream.hpp:7
bool operator!=(const TinyMultiIndex &that) const
Definition: tiny_multi_index.hpp:208
UINT & values_
Definition: tiny_multi_index.hpp:77
Entry operator[](dim_t index)
Definition: tiny_multi_index.hpp:198
waveblocks::wavepackets::shapes::TinyMultiIndex< UINT, D > MultiIndex
Definition: tiny_multi_index.hpp:273
UINT offset() const
Definition: tiny_multi_index.hpp:82
bool operator()(const MultiIndex &first, const MultiIndex &second) const
Definition: tiny_multi_index.hpp:257
std::size_t index_
Definition: tiny_multi_index.hpp:80
TinyMultiIndex(const TinyMultiIndex &that)
Definition: tiny_multi_index.hpp:165
Entry & operator/=(int value)
Definition: tiny_multi_index.hpp:141
TinyMultiIndex(const std::array< int, D > &that)
Definition: tiny_multi_index.hpp:169
Entry & operator=(int value)
Definition: tiny_multi_index.hpp:108
Entry(UINT &values, std::size_t index)
Definition: tiny_multi_index.hpp:106
MultiIndex second_argument_type
Definition: tiny_multi_index.hpp:296
Entry & operator*=(int value)
Definition: tiny_multi_index.hpp:134
TinyMultiIndex(std::initializer_list< int > list)
Definition: tiny_multi_index.hpp:175
bool operator==(const TinyMultiIndex &that) const
Definition: tiny_multi_index.hpp:203
Entry & operator%=(int value)
Definition: tiny_multi_index.hpp:148
MultiIndex first_argument_type
Definition: tiny_multi_index.hpp:295
Entry & operator-=(int value)
Definition: tiny_multi_index.hpp:127
TinyMultiIndex & operator=(const TinyMultiIndex &that)
Definition: tiny_multi_index.hpp:186
MultiIndex first_argument_type
Definition: tiny_multi_index.hpp:253
static int limit(dim_t axis)
Definition: tiny_multi_index.hpp:58
std::size_t operator()(const MultiIndex &index) const
Definition: tiny_multi_index.hpp:276
Entry & operator=(const Entry &entry)
Definition: tiny_multi_index.hpp:114
int operator[](dim_t index) const
Definition: tiny_multi_index.hpp:193
int dim_t
Definition: types.hpp:16
Represents a multi-index using a single integer.
Definition: tiny_multi_index.hpp:47
waveblocks::wavepackets::shapes::TinyMultiIndex< UINT, D > MultiIndex
Definition: tiny_multi_index.hpp:292
UINT values_
Definition: tiny_multi_index.hpp:70
bool result_type
Definition: tiny_multi_index.hpp:297