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