13 #ifndef STXXL_ALGO_ADAPTOR_HEADER
14 #define STXXL_ALGO_ADAPTOR_HEADER
16 #include <stxxl/bits/mng/mng.h>
17 #include <stxxl/bits/mng/adaptor.h>
20 __STXXL_BEGIN_NAMESPACE
22 template <
unsigned _blk_sz,
typename _run_type,
class __pos_type =
int_type>
23 struct RunsToBIDArrayAdaptor :
public TwoToOneDimArrayAdaptorBase<_run_type *, BID<_blk_sz>, __pos_type>
25 typedef RunsToBIDArrayAdaptor<_blk_sz, _run_type, __pos_type> _Self;
28 enum { block_size = _blk_sz };
30 unsigned_type dim_size;
32 typedef TwoToOneDimArrayAdaptorBase<_run_type *, BID<_blk_sz>, __pos_type> _Parent;
36 RunsToBIDArrayAdaptor(_run_type ** a, __pos_type p, unsigned_type d)
37 : TwoToOneDimArrayAdaptorBase<_run_type *,
BID<_blk_sz>, __pos_type>(a, p), dim_size(d)
39 RunsToBIDArrayAdaptor(
const _Self & a)
40 : TwoToOneDimArrayAdaptorBase<_run_type *,
BID<_blk_sz>, __pos_type>(a), dim_size(a.dim_size)
43 const _Self & operator = (
const _Self & a)
47 dim_size = a.dim_size;
51 data_type & operator * ()
53 CHECK_RUN_BOUNDS(pos);
54 return (
BID<_blk_sz>&)((*(array[(pos) % dim_size]))[(pos) / dim_size].bid);
57 const data_type * operator -> ()
const
59 CHECK_RUN_BOUNDS(pos);
60 return &((*(array[(pos) % dim_size])[(pos) / dim_size].bid));
64 data_type & operator [] (__pos_type n)
const
68 return (
BID<_blk_sz>&)((*(array[(n) % dim_size]))[(n) / dim_size].bid);
72 BLOCK_ADAPTOR_OPERATORS(RunsToBIDArrayAdaptor)
74 template <
unsigned _blk_sz, typename _run_type, class __pos_type = int_type>
75 struct RunsToBIDArrayAdaptor2
76 : public TwoToOneDimArrayAdaptorBase<_run_type *,
BID<_blk_sz>, __pos_type>
78 typedef RunsToBIDArrayAdaptor2<_blk_sz, _run_type, __pos_type> _Self;
81 typedef TwoToOneDimArrayAdaptorBase<_run_type *, BID<_blk_sz>, __pos_type> ParentClass_;
83 using ParentClass_::pos;
84 using ParentClass_::array;
87 { block_size = _blk_sz };
91 RunsToBIDArrayAdaptor2(_run_type ** a, __pos_type p, int_type _w, int_type _h)
92 : TwoToOneDimArrayAdaptorBase<_run_type *,
BID<_blk_sz>, __pos_type>(a, p),
93 w(_w), h(_h), K(_w * _h)
96 RunsToBIDArrayAdaptor2(
const _Self & a)
97 : TwoToOneDimArrayAdaptorBase<_run_type *,
BID<_blk_sz>, __pos_type>(a),
98 w(a.w), h(a.h), K(a.K)
101 const _Self & operator = (
const _Self & a)
111 data_type & operator * ()
113 register __pos_type i = pos - K;
115 return (
BID<_blk_sz>&)((*(array[(pos) % w]))[(pos) / w].bid);
117 register __pos_type _w = w;
119 return (
BID<_blk_sz>&)((*(array[(i) % _w]))[h + (i / _w)].bid);
122 const data_type * operator -> ()
const
124 register __pos_type i = pos - K;
126 return &((*(array[(pos) % w])[(pos) / w].bid));
129 register __pos_type _w = w;
131 return &((*(array[(i) % _w])[h + (i / _w)].bid));
135 data_type & operator [] (__pos_type n)
const
138 register __pos_type i = n - K;
140 return (
BID<_blk_sz>&)((*(array[(n) % w]))[(n) / w].bid);
143 register __pos_type _w = w;
145 return (
BID<_blk_sz>&)((*(array[(i) % _w]))[h + (i / _w)].bid);
149 BLOCK_ADAPTOR_OPERATORS(RunsToBIDArrayAdaptor2)
152 template <typename trigger_iterator_type,
unsigned _BlkSz>
153 struct trigger_entry_iterator
155 typedef trigger_entry_iterator<trigger_iterator_type, _BlkSz> _Self;
158 trigger_iterator_type value;
161 typedef bid_type value_type;
162 typedef std::random_access_iterator_tag iterator_category;
163 typedef int_type difference_type;
164 typedef value_type * pointer;
165 typedef value_type & reference;
167 enum { block_size = _BlkSz };
169 trigger_entry_iterator(
const _Self & a) : value(a.value) { }
170 trigger_entry_iterator(trigger_iterator_type v) : value(v) { }
172 bid_type & operator * ()
176 bid_type * operator -> ()
const
178 return &(value->bid);
180 const bid_type & operator [] (int_type n)
const
182 return (value + n)->bid;
184 bid_type & operator [] (int_type n)
186 return (value + n)->bid;
189 _Self & operator ++ ()
194 _Self operator ++ (
int)
200 _Self & operator -- ()
205 _Self operator -- (
int)
211 bool operator == (
const _Self & a)
const
213 return value == a.value;
215 bool operator != (
const _Self & a)
const
217 return value != a.value;
219 _Self operator += (int_type n)
224 _Self operator -= (int_type n)
229 int_type operator - (
const _Self & a)
const
231 return value - a.value;
233 int_type operator + (
const _Self & a)
const
235 return value + a.value;
239 __STXXL_END_NAMESPACE
241 #endif // !STXXL_ALGO_ADAPTOR_HEADER