15 #ifndef STXXL_MNG_ADAPTOR_HEADER
16 #define STXXL_MNG_ADAPTOR_HEADER
28 template <
unsigned_type modulo>
41 offset = pos % modulo;
58 this->offset = offset;
59 pos = block * modulo + offset;
137 #define STXXL_ADAPTOR_ARITHMETICS(pos) \
138 bool operator == (const self_type& a) const \
140 return (a.pos == pos); \
142 bool operator != (const self_type& a) const \
144 return (a.pos != pos); \
146 bool operator < (const self_type& a) const \
148 return (pos < a.pos); \
150 bool operator > (const self_type& a) const \
152 return (pos > a.pos); \
154 bool operator <= (const self_type& a) const \
156 return (pos <= a.pos); \
158 bool operator >= (const self_type& a) const \
160 return (pos >= a.pos); \
162 self_type operator + (pos_type off) const \
164 return self_type(array, pos + off); \
166 self_type operator - (pos_type off) const \
168 return self_type(array, pos - off); \
170 self_type& operator ++ () \
175 self_type operator ++ (int) \
177 self_type tmp = *this; \
181 self_type& operator -- () \
186 self_type operator -- (int) \
188 self_type tmp = *this; \
192 pos_type operator - (const self_type& a) const \
194 return pos - a.pos; \
196 self_type& operator -= (pos_type off) \
201 self_type& operator += (pos_type off) \
207 template <
class OneDimArrayType,
class DataType,
class PosType>
209 :
public std::iterator<std::random_access_iterator_tag, DataType, unsigned_type>
228 : array(a.array), pos(a.pos)
236 #define BLOCK_ADAPTOR_OPERATORS(two_to_one_dim_array_adaptor_base) \
238 template <unsigned BlockSize, typename RunType, class PosType> \
239 inline two_to_one_dim_array_adaptor_base<BlockSize, RunType, PosType>& operator ++ ( \
240 two_to_one_dim_array_adaptor_base<BlockSize, RunType, PosType>& a) \
246 template <unsigned BlockSize, typename RunType, class PosType> \
247 inline two_to_one_dim_array_adaptor_base<BlockSize, RunType, PosType> operator ++ ( \
248 two_to_one_dim_array_adaptor_base<BlockSize, RunType, PosType>& a, int) \
250 two_to_one_dim_array_adaptor_base<BlockSize, RunType, PosType> tmp = a; \
255 template <unsigned BlockSize, typename RunType, class PosType> \
256 inline two_to_one_dim_array_adaptor_base<BlockSize, RunType, PosType>& operator -- ( \
257 two_to_one_dim_array_adaptor_base<BlockSize, RunType, PosType>& a) \
263 template <unsigned BlockSize, typename RunType, class PosType> \
264 inline two_to_one_dim_array_adaptor_base<BlockSize, RunType, PosType> operator -- ( \
265 two_to_one_dim_array_adaptor_base<BlockSize, RunType, PosType>& a, int) \
267 two_to_one_dim_array_adaptor_base<BlockSize, RunType, PosType> tmp = a; \
272 template <unsigned BlockSize, typename RunType, class PosType> \
273 inline two_to_one_dim_array_adaptor_base<BlockSize, RunType, PosType>& operator -= ( \
274 two_to_one_dim_array_adaptor_base<BlockSize, RunType, PosType>& a, \
275 typename two_to_one_dim_array_adaptor_base<BlockSize, RunType, PosType>::_pos_type off) \
281 template <unsigned BlockSize, typename RunType, class PosType> \
282 inline two_to_one_dim_array_adaptor_base<BlockSize, RunType, PosType>& operator += ( \
283 two_to_one_dim_array_adaptor_base<BlockSize, RunType, PosType>& a, \
284 typename two_to_one_dim_array_adaptor_base<BlockSize, RunType, PosType>::_pos_type off) \
290 template <unsigned BlockSize, typename RunType, class PosType> \
291 inline two_to_one_dim_array_adaptor_base<BlockSize, RunType, PosType> operator + ( \
292 const two_to_one_dim_array_adaptor_base<BlockSize, RunType, PosType>& a, \
293 typename two_to_one_dim_array_adaptor_base<BlockSize, RunType, PosType>::_pos_type off) \
295 return two_to_one_dim_array_adaptor_base<BlockSize, RunType, PosType>(a.array, a.pos + off); \
298 template <unsigned BlockSize, typename RunType, class PosType> \
299 inline two_to_one_dim_array_adaptor_base<BlockSize, RunType, PosType> operator + ( \
300 typename two_to_one_dim_array_adaptor_base<BlockSize, RunType, PosType>::_pos_type off, \
301 const two_to_one_dim_array_adaptor_base<BlockSize, RunType, PosType>& a) \
303 return two_to_one_dim_array_adaptor_base<BlockSize, RunType, PosType>(a.array, a.pos + off); \
306 template <unsigned BlockSize, typename RunType, class PosType> \
307 inline two_to_one_dim_array_adaptor_base<BlockSize, RunType, PosType> operator - ( \
308 const two_to_one_dim_array_adaptor_base<BlockSize, RunType, PosType>& a, \
309 typename two_to_one_dim_array_adaptor_base<BlockSize, RunType, PosType>::_pos_type off) \
311 return two_to_one_dim_array_adaptor_base<BlockSize, RunType, PosType>(a.array, a.pos - off); \
316 template <
class OneDimArrayType,
class DataType,
317 unsigned DimSize,
class PosType = blocked_index<DimSize> >
318 struct two2one_dim_array_row_adapter
319 :
public two2one_dim_array_adapter_base<OneDimArrayType, DataType, PosType>
321 typedef OneDimArrayType one_dim_array_type;
322 typedef DataType data_type;
323 typedef DimSize dim_type;
324 typedef PosType pos_type;
326 typedef two2one_dim_array_row_adapter<one_dim_array_type,
327 data_type, dim_size, pos_type> self_type;
329 typedef two2one_dim_array_adapter_base<one_dim_array_type,
330 data_type, pos_type> base_type;
331 using base_type::array;
332 using base_type::pos;
334 two2one_dim_array_row_adapter()
336 two2one_dim_array_row_adapter(one_dim_array_type* a, pos_type p)
337 : two2one_dim_array_adapter_base<one_dim_array_type, data_type, pos_type>(a, p)
339 two2one_dim_array_row_adapter(
const two2one_dim_array_row_adapter& a)
340 : two2one_dim_array_adapter_base<one_dim_array_type, data_type, pos_type>(a)
343 data_type& operator * ()
345 return array[(pos).get_block()][(pos).get_offset()];
348 data_type* operator -> ()
const
350 return &(array[(pos).get_block()][(pos).get_offset()]);
353 data_type& operator [] (pos_type n)
356 return array[(n) / dim_size][(n) % dim_size];
359 const data_type& operator [] (pos_type n)
const
362 return array[(n) / dim_size][(n) % dim_size];
367 template <
class OneDimArrayType,
class DataType,
368 unsigned DimSize,
class PosType = blocked_index<DimSize> >
369 struct two2one_dim_array_column_adapter
370 :
public two2one_dim_array_adapter_base<OneDimArrayType, DataType, PosType>
372 typedef two2one_dim_array_column_adapter<one_dim_array_type,
373 data_type, dim_size, pos_type> self_type;
375 using two2one_dim_array_adapter_base<one_dim_array_type, data_type, pos_type>::pos;
376 using two2one_dim_array_adapter_base<one_dim_array_type, data_type, pos_type>::array;
378 two2one_dim_array_column_adapter(one_dim_array_type* a, pos_type p)
379 : two2one_dim_array_adapter_base<one_dim_array_type, data_type, pos_type>(a, p)
381 two2one_dim_array_column_adapter(
const self_type& a)
382 : two2one_dim_array_adapter_base<one_dim_array_type, data_type, pos_type>(a)
385 data_type& operator * ()
387 return array[(pos).get_offset()][(pos).get_block()];
390 data_type* operator -> ()
const
392 return &(array[(pos).get_offset()][(pos).get_block()]);
395 const data_type& operator [] (pos_type n)
const
398 return array[(n) % dim_size][(n) / dim_size];
401 data_type& operator [] (pos_type n)
404 return array[(n) % dim_size][(n) / dim_size];
410 template <
typename ArrayType,
typename ValueType,
unsigned_type modulo>
412 :
public std::iterator<std::random_access_iterator_tag, ValueType, unsigned_type>
430 offset = pos % modulo;
431 base = arrays + pos / modulo;
432 base_element = base->elem;
444 this->arrays = arrays;
450 this->arrays = arrays;
464 if (offset == modulo)
468 base_element = base->elem;
489 base_element = base->elem;
527 return pos - subtrahend.
pos;
532 return pos == aoai.
pos;
537 return pos != aoai.
pos;
542 return pos < aoai.
pos;
547 return pos <= aoai.
pos;
552 return pos > aoai.
pos;
557 return pos >= aoai.
pos;
562 return base_element[offset];
567 return base_element[offset];
572 return &(base_element[offset]);
577 return &(base_element[offset]);
582 return arrays[index / modulo][index % modulo];
587 return arrays[index / modulo][index % modulo];
593 template <
typename BlockType,
typename SizeType,
bool CanUseTrivialPo
inter>
598 template <
typename BlockType,
typename SizeType>
616 template <
typename BlockType,
typename SizeType>
629 return blocks[0].elem + offset;
635 template <
typename BlockType,
typename SizeType>
639 BlockType, SizeType, BlockType::has_only_data
643 template <
typename BlockType,
typename SizeType>
649 BlockType, SizeType, BlockType::has_only_data
651 return iter_gen(blocks, offset);
658 #endif // !STXXL_MNG_ADAPTOR_HEADER
const unsigned_type & get_offset() const
array_of_sequences_iterator< block_type, value_type, block_type::size > iterator
blocked_index(unsigned_type pos)
blocked_index(unsigned_type block, unsigned_type offset)
block_type::value_type value_type
const unsigned_type & get_block() const
uint_pair & operator++()
prefix increment operator (directly manipulates the integer parts)
two2one_dim_array_adapter_base(const two2one_dim_array_adapter_base &a)
block_type::value_type value_type
uint_pair & operator+=(const uint_pair &b)
addition operator (uses 64-bit arithmetic)
two2one_dim_array_adapter_base(one_dim_array_type *a, pos_type p)
bool operator!=(const uint_pair &b) const
inequality checking operator
bool operator<=(const uint_pair &b) const
less-or-equal comparison operator
bool operator>(const uint_pair &b) const
greater comparison operator
bool operator>=(const uint_pair &b) const
greater-or-equal comparison operator
bool operator<(const uint_pair &b) const
less-than comparison operator
#define STXXL_BEGIN_NAMESPACE
two2one_dim_array_adapter_base()
array_of_sequences_iterator(array_type *arrays, unsigned_type pos)
uint_pair & operator--()
prefix decrement operator (directly manipulates the integer parts)
void set(unsigned_type pos)
array_of_sequences_iterator(array_type *arrays)
two2one_dim_array_adapter_base< one_dim_array_type, data_type, pos_type > self_type
value_type * base_element
element_iterator_traits< BlockType, SizeType >::element_iterator make_element_iterator(BlockType *blocks, SizeType offset)
array_of_sequences_iterator()
OneDimArrayType one_dim_array_type
void set(unsigned_type pos)
#define STXXL_ADAPTOR_ARITHMETICS(pos)
choose_int_types< my_pointer_size >::unsigned_type unsigned_type
one_dim_array_type * array
bool operator==(const uint_pair &b) const
equality checking operator
#define STXXL_END_NAMESPACE
helper::element_iterator_generator< BlockType, SizeType, BlockType::has_only_data >::iterator element_iterator