[go: up one dir, main page]

Menu

[8f591a]: / algo / adaptor.h  Maximize  Restore  History

Download this file

247 lines (203 with data), 5.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#ifndef ALGO_ADAPTOR_HEADER
#define ALGO_ADAPTOR_HEADER
/***************************************************************************
* adaptor.h
*
* Fri Oct 4 23:28:04 2002
* Copyright 2002 Roman Dementiev
* dementiev@mpi-sb.mpg.de
****************************************************************************/
#include "../mng/mng.h"
#include "../mng/adaptor.h"
#include "../common/utils.h"
__STXXL_BEGIN_NAMESPACE
template < unsigned _blk_sz, typename _run_type, class __pos_type = int >
struct RunsToBIDArrayAdaptor: public TwoToOneDimArrayAdaptorBase < _run_type *, BID < _blk_sz > , __pos_type >
{
typedef RunsToBIDArrayAdaptor < _blk_sz, _run_type,__pos_type > _Self;
typedef BID < _blk_sz > data_type;
enum { block_size = _blk_sz };
unsigned dim_size;
RunsToBIDArrayAdaptor (_run_type * *a, __pos_type p,
unsigned d):TwoToOneDimArrayAdaptorBase <
_run_type *, BID < _blk_sz >, __pos_type > (a, p), dim_size (d)
{
};
RunsToBIDArrayAdaptor (const _Self & a):TwoToOneDimArrayAdaptorBase <
_run_type *, BID < _blk_sz >, __pos_type > (a),
dim_size (a.dim_size)
{
};
const _Self & operator = (const _Self & a)
{
array = a.array;
pos = a.pos;
dim_size = a.dim_size;
return *this;
}
data_type & operator * ()
{
CHECK_RUN_BOUNDS (pos)
return (BID < _blk_sz >
&)((*(array[(pos) % dim_size]))[(pos) /
dim_size].
bid);
};
const data_type *operator -> () const
{
CHECK_RUN_BOUNDS (pos)
return
&((*(array[(pos) % dim_size])[(pos) / dim_size].bid));
};
data_type & operator [](__pos_type n) const
{
n += pos;
CHECK_RUN_BOUNDS (n)
return (BID < _blk_sz >
&) ((*(array[(n) % dim_size]))[(n) /
dim_size].bid);
};
};
BLOCK_ADAPTOR_OPERATORS(RunsToBIDArrayAdaptor)
template < unsigned
_blk_sz,typename _run_type, class __pos_type =
int >struct RunsToBIDArrayAdaptor2:public
TwoToOneDimArrayAdaptorBase < _run_type *, BID < _blk_sz >,
__pos_type >
{
typedef RunsToBIDArrayAdaptor2 < _blk_sz, _run_type,__pos_type > _Self;
typedef BID < _blk_sz > data_type;
enum
{ block_size = _blk_sz };
__pos_type w, h, K;
RunsToBIDArrayAdaptor2 (_run_type * *a, __pos_type p, int _w,
int _h):TwoToOneDimArrayAdaptorBase <
_run_type *, BID < _blk_sz >, __pos_type > (a, p), w (_w),
h (_h), K (_w * _h)
{
};
RunsToBIDArrayAdaptor2 (const _Self &
a):TwoToOneDimArrayAdaptorBase < _run_type *,
BID < _blk_sz >, __pos_type > (a), w (a.w), h (a.h),
K (a.K)
{
};
const _Self & operator = (const _Self & a)
{
array = a.array;
pos = a.pos;
w = a.w;
h = a.h;
K = a.K;
return *this;
}
data_type & operator * ()
{
register __pos_type i = pos - K;
if (i < 0)
return (BID < _blk_sz >
&)((*(array[(pos) % w]))[(pos) / w].bid);
register __pos_type _w = w;
_w--;
return (BID < _blk_sz >
&)((*(array[(i) % _w]))[h + (i / _w)].bid);
};
const data_type *operator -> () const
{
register __pos_type i = pos - K;
if (i < 0)
return &((*(array[(pos) % w])[(pos) / w].bid));
register __pos_type _w = w;
_w--;
return &((*(array[(i) % _w])[h + (i / _w)].bid));
};
data_type & operator [](__pos_type n) const
{
n += pos;
register __pos_type i = n - K;
if (i < 0)
return (BID < _blk_sz >
&) ((*(array[(n) % w]))[(n) / w].bid);
register __pos_type _w = w;
_w--;
return (BID < _blk_sz >
&) ((*(array[(i) % _w]))[h + (i / _w)].bid);
};
};
BLOCK_ADAPTOR_OPERATORS (RunsToBIDArrayAdaptor2)
template <typename trigger_iterator_type,unsigned _BlkSz>
struct trigger_entry_iterator
{
typedef trigger_entry_iterator<trigger_iterator_type,_BlkSz> _Self;
typedef BID<_BlkSz> bid_type;
trigger_iterator_type value;
enum { block_size = _BlkSz };
trigger_entry_iterator(const _Self & a):value(a.value) {};
trigger_entry_iterator(trigger_iterator_type v):value(v) {};
bid_type & operator * ()
{
return value->bid;
}
bid_type * operator -> () const
{
return &(value->bid);
}
const bid_type & operator [] (int n) const
{
return (value + n)->bid;
}
bid_type & operator [] (int n)
{
return (value + n)->bid;
}
_Self & operator ++()
{
value++;
return *this;
}
_Self operator ++(int)
{
_Self __tmp = *this;
value++;
return __tmp;
}
_Self & operator --()
{
value--;
return *this;
}
_Self operator --(int)
{
_Self __tmp = *this;
value--;
return __tmp;
}
bool operator == (const _Self &a) const
{
return value == a.value;
}
bool operator != (const _Self &a) const
{
return value != a.value;
}
_Self operator += (int n)
{
value += n;
return *this;
}
_Self operator -= (int n)
{
value -= n;
return *this;
}
int operator - (const _Self & a) const
{
return value - a.value;
}
int operator + (const _Self & a) const
{
return value + a.value;
}
};
__STXXL_END_NAMESPACE
#endif