STXXL  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
adaptor.h
Go to the documentation of this file.
1 /***************************************************************************
2  * include/stxxl/bits/algo/adaptor.h
3  *
4  * Part of the STXXL. See http://stxxl.sourceforge.net
5  *
6  * Copyright (C) 2002 Roman Dementiev <[email protected]>
7  * Copyright (C) 2010 Andreas Beckmann <[email protected]>
8  *
9  * Distributed under the Boost Software License, Version 1.0.
10  * (See accompanying file LICENSE_1_0.txt or copy at
11  * http://www.boost.org/LICENSE_1_0.txt)
12  **************************************************************************/
13 
14 #ifndef STXXL_ALGO_ADAPTOR_HEADER
15 #define STXXL_ALGO_ADAPTOR_HEADER
16 
17 #include <stxxl/bits/mng/bid.h>
18 #include <stxxl/bits/mng/adaptor.h>
19 
20 
22 
23 template <unsigned _blk_sz, typename _run_type, class __pos_type = int_type>
24 struct runs2bid_array_adaptor : public two2one_dim_array_adapter_base<_run_type*, BID<_blk_sz>, __pos_type>
25 {
28 
29  enum { block_size = _blk_sz };
30 
32 
34  using _Parent::array;
35  using _Parent::pos;
36 
37  runs2bid_array_adaptor(_run_type** a, __pos_type p, unsigned_type d)
38  : two2one_dim_array_adapter_base<_run_type*, BID<_blk_sz>, __pos_type>(a, p), dim_size(d)
39  { }
41  : two2one_dim_array_adapter_base<_run_type*, BID<_blk_sz>, __pos_type>(a), dim_size(a.dim_size)
42  { }
43 
44  const _Self& operator = (const _Self& a)
45  {
46  array = a.array;
47  pos = a.pos;
48  dim_size = a.dim_size;
49  return *this;
50  }
51 
52  data_type& operator * ()
53  {
54  CHECK_RUN_BOUNDS(pos);
55  return (BID<_blk_sz>&)((*(array[(pos) % dim_size]))[(pos) / dim_size].bid);
56  }
57 
58  const data_type* operator -> () const
59  {
60  CHECK_RUN_BOUNDS(pos);
61  return &((*(array[(pos) % dim_size])[(pos) / dim_size].bid));
62  }
63 
64 
65  data_type& operator [] (__pos_type n) const
66  {
67  n += pos;
69  return (BID<_blk_sz>&)((*(array[(n) % dim_size]))[(n) / dim_size].bid);
70  }
71 };
72 
73 BLOCK_ADAPTOR_OPERATORS(runs2bid_array_adaptor)
74 
75 template <unsigned _blk_sz, typename _run_type, class __pos_type = int_type>
77  : public two2one_dim_array_adapter_base<_run_type*, BID<_blk_sz>, __pos_type>
78 {
81 
83 
84  using ParentClass_::pos;
85  using ParentClass_::array;
86 
87  enum
88  { block_size = _blk_sz };
89 
90  __pos_type w, h, K;
91 
92  runs2bid_array_adaptor2(_run_type** a, __pos_type p, int_type _w, int_type _h)
93  : two2one_dim_array_adapter_base<_run_type*, BID<_blk_sz>, __pos_type>(a, p),
94  w(_w), h(_h), K(_w * _h)
95  { }
96 
97  runs2bid_array_adaptor2(const _Self& a)
98  : two2one_dim_array_adapter_base<_run_type*, BID<_blk_sz>, __pos_type>(a),
99  w(a.w), h(a.h), K(a.K)
100  { }
101 
102  const _Self& operator = (const _Self& a)
103  {
104  array = a.array;
105  pos = a.pos;
106  w = a.w;
107  h = a.h;
108  K = a.K;
109  return *this;
110  }
111 
112  data_type& operator * ()
113  {
114  register __pos_type i = pos - K;
115  if (i < 0)
116  return (BID<_blk_sz>&)((*(array[(pos) % w]))[(pos) / w].bid);
117 
118  register __pos_type _w = w;
119  _w--;
120  return (BID<_blk_sz>&)((*(array[(i) % _w]))[h + (i / _w)].bid);
121  }
122 
123  const data_type* operator -> () const
124  {
125  register __pos_type i = pos - K;
126  if (i < 0)
127  return &((*(array[(pos) % w])[(pos) / w].bid));
128 
129 
130  register __pos_type _w = w;
131  _w--;
132  return &((*(array[(i) % _w])[h + (i / _w)].bid));
133  }
134 
135 
136  data_type& operator [] (__pos_type n) const
137  {
138  n += pos;
139  register __pos_type i = n - K;
140  if (i < 0)
141  return (BID<_blk_sz>&)((*(array[(n) % w]))[(n) / w].bid);
142 
143 
144  register __pos_type _w = w;
145  _w--;
146  return (BID<_blk_sz>&)((*(array[(i) % _w]))[h + (i / _w)].bid);
147  }
148 };
149 
150 BLOCK_ADAPTOR_OPERATORS(runs2bid_array_adaptor2)
151 
152 
153 template <typename trigger_iterator_type>
155 {
157  typedef typename std::iterator_traits<trigger_iterator_type>::value_type::bid_type bid_type;
158 
159  // STL typedefs
160  typedef bid_type value_type;
161  typedef std::random_access_iterator_tag iterator_category;
163  typedef value_type* pointer;
164  typedef value_type& reference;
165 
166  trigger_iterator_type value;
167 
168  trigger_entry_iterator(const _Self& a) : value(a.value) { }
169  trigger_entry_iterator(trigger_iterator_type v) : value(v) { }
170 
171  bid_type& operator * ()
172  {
173  return value->bid;
174  }
175  bid_type* operator -> () const
176  {
177  return &(value->bid);
178  }
179  const bid_type& operator [] (int_type n) const
180  {
181  return (value + n)->bid;
182  }
183  bid_type& operator [] (int_type n)
184  {
185  return (value + n)->bid;
186  }
187 
188  _Self& operator ++ ()
189  {
190  value++;
191  return *this;
192  }
193  _Self operator ++ (int)
194  {
195  _Self __tmp = *this;
196  value++;
197  return __tmp;
198  }
199  _Self& operator -- ()
200  {
201  value--;
202  return *this;
203  }
204  _Self operator -- (int)
205  {
206  _Self __tmp = *this;
207  value--;
208  return __tmp;
209  }
210  bool operator == (const _Self& a) const
211  {
212  return value == a.value;
213  }
214  bool operator != (const _Self& a) const
215  {
216  return value != a.value;
217  }
219  {
220  value += n;
221  return *this;
222  }
223  _Self operator -= (int_type n)
224  {
225  value -= n;
226  return *this;
227  }
228  int_type operator - (const _Self& a) const
229  {
230  return value - a.value;
231  }
232  int_type operator + (const _Self& a) const
233  {
234  return value + a.value;
235  }
236 };
237 
238 template <typename Iterator>
239 inline
240 trigger_entry_iterator<Iterator>
241 make_bid_iterator(Iterator iter)
242 {
244 }
245 
247 
248 #endif // !STXXL_ALGO_ADAPTOR_HEADER
value_type & reference
Definition: adaptor.h:164
two2one_dim_array_adapter_base< _run_type *, BID< _blk_sz >, __pos_type > ParentClass_
Definition: adaptor.h:82
bid_type value_type
Definition: adaptor.h:160
trigger_entry_iterator< Iterator > make_bid_iterator(Iterator iter)
Definition: adaptor.h:241
runs2bid_array_adaptor(const _Self &a)
Definition: adaptor.h:40
std::random_access_iterator_tag iterator_category
Definition: adaptor.h:161
runs2bid_array_adaptor< _blk_sz, _run_type, __pos_type > _Self
Definition: adaptor.h:26
one_dim_array_type * array
Definition: adaptor.h:213
uint_pair & operator++()
prefix increment operator (directly manipulates the integer parts)
Definition: uint_types.h:166
trigger_entry_iterator(trigger_iterator_type v)
Definition: adaptor.h:169
unsigned_type dim_size
Definition: adaptor.h:31
value_type * pointer
Definition: adaptor.h:163
uint_pair & operator+=(const uint_pair &b)
addition operator (uses 64-bit arithmetic)
Definition: uint_types.h:186
bool operator!=(const uint_pair &b) const
inequality checking operator
Definition: uint_types.h:201
choose_int_types< my_pointer_size >::int_type int_type
Definition: types.h:66
Block identifier class.
Definition: bid.h:42
BID< _blk_sz > data_type
Definition: adaptor.h:80
int_type difference_type
Definition: adaptor.h:162
#define STXXL_BEGIN_NAMESPACE
Definition: namespace.h:16
uint_pair & operator--()
prefix decrement operator (directly manipulates the integer parts)
Definition: uint_types.h:176
runs2bid_array_adaptor(_run_type **a, __pos_type p, unsigned_type d)
Definition: adaptor.h:37
trigger_iterator_type value
Definition: adaptor.h:166
#define BLOCK_ADAPTOR_OPERATORS(two_to_one_dim_array_adaptor_base)
Definition: adaptor.h:236
two2one_dim_array_adapter_base< _run_type *, BID< _blk_sz >, __pos_type > _Parent
Definition: adaptor.h:33
BID< _blk_sz > data_type
Definition: adaptor.h:27
choose_int_types< my_pointer_size >::unsigned_type unsigned_type
Definition: types.h:67
#define CHECK_RUN_BOUNDS(pos)
trigger_entry_iterator< trigger_iterator_type > _Self
Definition: adaptor.h:156
std::iterator_traits< trigger_iterator_type >::value_type::bid_type bid_type
Definition: adaptor.h:157
Definition: adaptor.h:154
bool operator==(const uint_pair &b) const
equality checking operator
Definition: uint_types.h:195
runs2bid_array_adaptor2(const _Self &a)
Definition: adaptor.h:97
#define STXXL_END_NAMESPACE
Definition: namespace.h:17
runs2bid_array_adaptor2< _blk_sz, _run_type, __pos_type > _Self
Definition: adaptor.h:79
runs2bid_array_adaptor2(_run_type **a, __pos_type p, int_type _w, int_type _h)
Definition: adaptor.h:92
trigger_entry_iterator(const _Self &a)
Definition: adaptor.h:168