15 #ifndef STXXL_MNG_ADAPTOR_HEADER
16 #define STXXL_MNG_ADAPTOR_HEADER
30 template <
unsigned_type modulo>
43 offset = pos % modulo;
60 this->offset = offset;
61 pos = block * modulo + offset;
139 #define STXXL_ADAPTOR_ARITHMETICS(pos) \
140 bool operator == (const _Self& a) const \
142 return (a.pos == pos); \
144 bool operator != (const _Self& a) const \
146 return (a.pos != pos); \
148 bool operator < (const _Self& a) const \
150 return (pos < a.pos); \
152 bool operator > (const _Self& a) const \
154 return (pos > a.pos); \
156 bool operator <= (const _Self& a) const \
158 return (pos <= a.pos); \
160 bool operator >= (const _Self& a) const \
162 return (pos >= a.pos); \
164 _Self operator + (pos_type off) const \
166 return _Self(array, pos + off); \
168 _Self operator - (pos_type off) const \
170 return _Self(array, pos - off); \
172 _Self& operator ++ () \
177 _Self operator ++ (int) \
183 _Self& operator -- () \
188 _Self operator -- (int) \
194 pos_type operator - (const _Self& a) const \
196 return pos - a.pos; \
198 _Self& operator -= (pos_type off) \
203 _Self& operator += (pos_type off) \
209 template <
class one_dim_array_type,
class data_type,
class pos_type>
211 :
public std::iterator<std::random_access_iterator_tag, data_type, unsigned_type>
227 : array(a.array), pos(a.pos)
236 #define BLOCK_ADAPTOR_OPERATORS(two_to_one_dim_array_adaptor_base) \
238 template <unsigned _blk_sz, typename _run_type, class __pos_type> \
239 inline two_to_one_dim_array_adaptor_base<_blk_sz, _run_type, __pos_type>& operator ++ ( \
240 two_to_one_dim_array_adaptor_base<_blk_sz, _run_type, __pos_type>& a) \
246 template <unsigned _blk_sz, typename _run_type, class __pos_type> \
247 inline two_to_one_dim_array_adaptor_base<_blk_sz, _run_type, __pos_type> operator ++ ( \
248 two_to_one_dim_array_adaptor_base<_blk_sz, _run_type, __pos_type>& a, int) \
250 two_to_one_dim_array_adaptor_base<_blk_sz, _run_type, __pos_type> tmp = a; \
255 template <unsigned _blk_sz, typename _run_type, class __pos_type> \
256 inline two_to_one_dim_array_adaptor_base<_blk_sz, _run_type, __pos_type>& operator -- ( \
257 two_to_one_dim_array_adaptor_base<_blk_sz, _run_type, __pos_type>& a) \
263 template <unsigned _blk_sz, typename _run_type, class __pos_type> \
264 inline two_to_one_dim_array_adaptor_base<_blk_sz, _run_type, __pos_type> operator -- ( \
265 two_to_one_dim_array_adaptor_base<_blk_sz, _run_type, __pos_type>& a, int) \
267 two_to_one_dim_array_adaptor_base<_blk_sz, _run_type, __pos_type> tmp = a; \
272 template <unsigned _blk_sz, typename _run_type, class __pos_type> \
273 inline two_to_one_dim_array_adaptor_base<_blk_sz, _run_type, __pos_type>& operator -= ( \
274 two_to_one_dim_array_adaptor_base<_blk_sz, _run_type, __pos_type>& a, \
275 typename two_to_one_dim_array_adaptor_base<_blk_sz, _run_type, __pos_type>::_pos_type off) \
281 template <unsigned _blk_sz, typename _run_type, class __pos_type> \
282 inline two_to_one_dim_array_adaptor_base<_blk_sz, _run_type, __pos_type>& operator += ( \
283 two_to_one_dim_array_adaptor_base<_blk_sz, _run_type, __pos_type>& a, \
284 typename two_to_one_dim_array_adaptor_base<_blk_sz, _run_type, __pos_type>::_pos_type off) \
290 template <unsigned _blk_sz, typename _run_type, class __pos_type> \
291 inline two_to_one_dim_array_adaptor_base<_blk_sz, _run_type, __pos_type> operator + ( \
292 const two_to_one_dim_array_adaptor_base<_blk_sz, _run_type, __pos_type>& a, \
293 typename two_to_one_dim_array_adaptor_base<_blk_sz, _run_type, __pos_type>::_pos_type off) \
295 return two_to_one_dim_array_adaptor_base<_blk_sz, _run_type, __pos_type>(a.array, a.pos + off); \
298 template <unsigned _blk_sz, typename _run_type, class __pos_type> \
299 inline two_to_one_dim_array_adaptor_base<_blk_sz, _run_type, __pos_type> operator + ( \
300 typename two_to_one_dim_array_adaptor_base<_blk_sz, _run_type, __pos_type>::_pos_type off, \
301 const two_to_one_dim_array_adaptor_base<_blk_sz, _run_type, __pos_type>& a) \
303 return two_to_one_dim_array_adaptor_base<_blk_sz, _run_type, __pos_type>(a.array, a.pos + off); \
306 template <unsigned _blk_sz, typename _run_type, class __pos_type> \
307 inline two_to_one_dim_array_adaptor_base<_blk_sz, _run_type, __pos_type> operator - ( \
308 const two_to_one_dim_array_adaptor_base<_blk_sz, _run_type, __pos_type>& a, \
309 typename two_to_one_dim_array_adaptor_base<_blk_sz, _run_type, __pos_type>::_pos_type off) \
311 return two_to_one_dim_array_adaptor_base<_blk_sz, _run_type, __pos_type>(a.array, a.pos - off); \
317 template <
class one_dim_array_type,
class data_type,
318 unsigned dim_size,
class pos_type = blocked_index<dim_size> >
319 struct two2one_dim_array_row_adapter :
320 public two2one_dim_array_adapter_base<one_dim_array_type, data_type, pos_type>
322 typedef two2one_dim_array_row_adapter<one_dim_array_type,
323 data_type, dim_size, pos_type> _Self;
325 typedef two2one_dim_array_adapter_base<one_dim_array_type,
326 data_type, pos_type> _Parent;
327 using _Parent::array;
330 two2one_dim_array_row_adapter()
332 two2one_dim_array_row_adapter(one_dim_array_type* a, pos_type p)
333 : two2one_dim_array_adapter_base<one_dim_array_type, data_type, pos_type>(a, p)
335 two2one_dim_array_row_adapter(
const two2one_dim_array_row_adapter& a)
336 : two2one_dim_array_adapter_base<one_dim_array_type, data_type, pos_type>(a)
339 data_type& operator * ()
341 return array[(pos).get_block()][(pos).get_offset()];
344 data_type* operator -> ()
const
346 return &(array[(pos).get_block()][(pos).get_offset()]);
349 data_type& operator [] (pos_type n)
352 return array[(n) / dim_size][(n) % dim_size];
355 const data_type& operator [] (pos_type n)
const
358 return array[(n) / dim_size][(n) % dim_size];
363 template <
class one_dim_array_type,
class data_type,
364 unsigned dim_size,
class pos_type = blocked_index<dim_size> >
365 struct two2one_dim_array_column_adapter
366 :
public two2one_dim_array_adapter_base<one_dim_array_type, data_type, pos_type>
368 typedef two2one_dim_array_column_adapter<one_dim_array_type,
369 data_type, dim_size, pos_type> _Self;
371 using two2one_dim_array_adapter_base<one_dim_array_type, data_type, pos_type>::pos;
372 using two2one_dim_array_adapter_base<one_dim_array_type, data_type, pos_type>::array;
374 two2one_dim_array_column_adapter(one_dim_array_type* a, pos_type p)
375 : two2one_dim_array_adapter_base<one_dim_array_type, data_type, pos_type>(a, p)
377 two2one_dim_array_column_adapter(
const _Self& a)
378 : two2one_dim_array_adapter_base<one_dim_array_type, data_type, pos_type>(a)
381 data_type& operator * ()
383 return array[(pos).get_offset()][(pos).get_block()];
386 data_type* operator -> ()
const
388 return &(array[(pos).get_offset()][(pos).get_block()]);
391 const data_type& operator [] (pos_type n)
const
394 return array[(n) % dim_size][(n) / dim_size];
397 data_type& operator [] (pos_type n)
400 return array[(n) % dim_size][(n) / dim_size];
407 template <
typename array_type,
typename value_type,
unsigned_type modulo>
421 offset = pos % modulo;
422 base = arrays + pos / modulo;
423 base_element = base->elem;
435 this->arrays = arrays;
441 this->arrays = arrays;
455 if (offset == modulo)
459 base_element = base->elem;
480 base_element = base->elem;
518 return pos - subtrahend.
pos;
523 return pos == aoai.
pos;
528 return pos != aoai.
pos;
533 return pos < aoai.
pos;
538 return pos <= aoai.
pos;
543 return pos > aoai.
pos;
548 return pos >= aoai.
pos;
551 const value_type& operator * ()
const
553 return base_element[offset];
556 value_type& operator * ()
558 return base_element[offset];
561 const value_type& operator -> ()
const
563 return &(base_element[offset]);
566 value_type& operator -> ()
568 return &(base_element[offset]);
573 return arrays[index / modulo][index % modulo];
578 return arrays[index / modulo][index % modulo];
584 template <
typename BlockType,
bool can_use_trivial_po
inter>
589 template <
typename BlockType>
605 template <
typename BlockType>
616 return blocks[0].elem + offset;
622 template <
typename BlockType>
628 template <
typename BlockType>
634 return iter_gen(blocks, offset);
641 #endif // !STXXL_MNG_ADAPTOR_HEADER
const unsigned_type & get_offset() const
two2one_dim_array_adapter_base(const two2one_dim_array_adapter_base &a)
void set(unsigned_type pos)
blocked_index(unsigned_type pos)
blocked_index(unsigned_type block, unsigned_type offset)
one_dim_array_type * array
value_type * base_element
const unsigned_type & get_block() const
block_type::value_type value_type
helper::element_iterator_generator< BlockType, BlockType::has_only_data >::iterator element_iterator
uint_pair & operator++()
prefix increment operator (directly manipulates the integer parts)
element_iterator_traits< BlockType >::element_iterator make_element_iterator(BlockType *blocks, unsigned_type offset)
uint_pair & operator+=(const uint_pair &b)
addition operator (uses 64-bit arithmetic)
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
array_of_sequences_iterator(array_type *arrays, unsigned_type pos)
uint_pair & operator--()
prefix decrement operator (directly manipulates the integer parts)
two2one_dim_array_adapter_base(one_dim_array_type *a, pos_type p)
array_of_sequences_iterator< block_type, value_type, block_type::size > iterator
two2one_dim_array_adapter_base< one_dim_array_type, data_type, pos_type > _Self
block_type::value_type value_type
void set(unsigned_type pos)
#define STXXL_ADAPTOR_ARITHMETICS(pos)
choose_int_types< my_pointer_size >::unsigned_type unsigned_type
array_of_sequences_iterator()
array_of_sequences_iterator(array_type *arrays)
bool operator==(const uint_pair &b) const
equality checking operator
#define STXXL_END_NAMESPACE
two2one_dim_array_adapter_base()