chunkedseq
container library for large in-memory data sets
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
chunkedseq.hpp
Go to the documentation of this file.
1 
13 #include <cstddef>
14 
15 #include "fixedcapacity.hpp"
16 #include "chunk.hpp"
17 #include "cachedmeasure.hpp"
18 #include "chunkedseqbase.hpp"
19 #include "bootchunkedseq.hpp"
20 #include "ftree.hpp"
21 
22 #ifndef _PASL_DATA_CHUNKEDSEQ_H_
23 #define _PASL_DATA_CHUNKEDSEQ_H_
24 
25 namespace pasl {
26 namespace data {
27 namespace chunkedseq {
28 
29 /***********************************************************************/
30 
31 /*---------------------------------------------------------------------*/
32 /* Place to put configuration classes for defining various
33  * instantiations of the chunked-sequence functor
34  */
35 
36 template <
37  class Item,
38  int Chunk_capacity = 512,
39  class Client_cache = cachedmeasure::trivial<Item, size_t>,
40  template <
41  class Chunk_item,
42  int Capacity,
43  class Item_alloc
44  >
46  template <
47  class Top_item_base,
48  int ___Chunk_capacity,
49  class ___Cached_measure,
50  class Top_item_deleter,
51  class Top_item_copier,
52  template <
53  class ___Item,
54  int ___Capacity,
55  class ___Item_alloc
56  >
57  class ___Chunk_struct,
58  class Size_access
59  >
60  class Middle_sequence = bootchunkedseq::cdeque,
61  class Item_alloc = std::allocator<Item>
62 >
64 public:
65 
66  using size_type = typename Client_cache::size_type;
67  using difference_type = ptrdiff_t; // later: check if this is ok
68 
69  using value_type = Item;
71 
72  static constexpr size_type chunk_capacity = size_type(Chunk_capacity);
73 
74  using item_allocator_type = Item_alloc;
75 
76  using item_queue_type = Chunk_struct<value_type, Chunk_capacity, item_allocator_type>;
77 
78  using client_algebra_type = typename Client_cache::algebra_type;
82 
83  using chunk_cache_type = Client_cache;
84  using chunk_measured_type = typename chunk_cache_type::measured_type;
85 #ifdef DISABLE_RANDOM_ACCESS_ITERATOR
87 #else
89 #endif
90 #ifndef ENABLE_FINGER_SEARCH
94 #else
96 #endif
99 
101  public:
102 
103  using size_type = typename Client_cache::size_type;
104  using value_type = const chunk_type*;
107 
108  class measure_type {
109  public:
110 
111  using client_measure_type = typename Client_cache::measure_type;
113 
114  private:
115 
116  client_measure_type client_meas;
117 
118  public:
119 
121 
122  measure_type(const client_measure_type& client_meas)
123  : client_meas(client_meas) { }
124 
127  m.value1 = size_type(1);
128  m.value2 = client_meas(v);
129  return m;
130  }
131 
134  for (auto p = lo; p < hi; p++)
135  m = algebra_type::combine(m, operator()(*p));
136  return m;
137  }
138 
141  m.value1 = p->size();
142  m.value2 = p->get_cached();
143  return m;
144  }
145 
146  measured_type operator()(const value_type* lo, const value_type* hi) const {
148  for (auto p = lo; p < hi; p++)
149  m = algebra_type::combine(m, operator()(*p));
150  return m;
151  }
152 
154  return client_meas;
155  }
156 
158  this->client_meas = client_meas;
159  }
160 
161  };
162 
163  static void swap(measured_type& x, measured_type& y) {
164  std::swap(x.value1, y.value1);
165  std::swap(x.value2, y.value2);
166  }
167 
168  };
169 
171 
172  class size_access {
173  public:
175 
176  static constexpr bool enable_index_optimization = true;
177 
179  return m.value1;
180  }
182  return m.value1;
183  }
185  return m.value2;
186  }
188  return m.value2;
189  }
190  };
191 
192 #ifdef DEBUG_MIDDLE_SEQUENCE
193  // use chunk as middle sequence; for the purpose of testing the chunkedseq functor in isolation.
194  static constexpr int middle_capacity = 1<<23;
196  using middle_annotation_type = annotation::annotation_builder<>;
197  using middle_type = chunk<chunk_pointer_queue_type, middle_cache_type,
198  middle_annotation_type, Pointer_deleter, Pointer_deep_copier, size_access>;
199 #else
200  static constexpr int middle_chunk_capacity = 32; // 32 64 128;
201  using middle_type = Middle_sequence<chunk_type, middle_chunk_capacity, middle_cache_type,
202  Pointer_deleter, Pointer_deep_copier, fixedcapacity::heap_allocated::ringbuffer_ptr, size_access>;
203 #endif
204 
206 
207 };
208 
209 /*---------------------------------------------------------------------*/
210 /* Instantiations for the bootstrapped chunked sequence */
211 
212 namespace bootstrapped {
213 
214 // Application of chunked deque to a configuration
215 
216 template <
217  class Item,
218  int Chunk_capacity=512,
220  template <
221  class Chunk_item,
222  int Capacity,
223  class Chunk_item_alloc = std::allocator<Item>
224  >
226  class Item_alloc = std::allocator<Item>
227 >
229 
230 // Application of chunked stack to a configuration
231 
232 template <
233  class Item,
234  int Chunk_capacity = 512,
236  class Item_alloc = std::allocator<Item>
237 >
239 
240 } // end namespace bootstrapped
241 
242 /*---------------------------------------------------------------------*/
243 /* Instantiations for the finger tree */
244 
245 namespace ftree {
246 
247 // Application of a chunked finger tree to a configuration
248 
249 template <
250  class Item,
251  int Chunk_capacity = 512,
253  template <
254  class Chunk_item,
255  int Capacity,
256  class Chunk_item_alloc = std::allocator<Item>
257  >
259  class Item_alloc = std::allocator<Item>
260 >
262 
263 
264 // Application of chunked finger tree to a configuration
265 
266 template <
267  class Item,
268  int Chunk_capacity = 512,
270  class Item_alloc = std::allocator<Item>
271 >
273 
274 } // end namespace ftree
275 
276 /***********************************************************************/
277 
278 } // end namespace
279 } // end namespace
280 } // end namespace
281 
282 #endif
algebra::combiner< size_algebra_type, client_algebra_type > middle_algebra_type
Definition: chunkedseq.hpp:80
typename middle_cache_type::measure_type middle_measure_type
Definition: chunkedseq.hpp:170
measured_type operator()(const client_value_type *lo, const client_value_type *hi) const
Definition: chunkedseq.hpp:132
static value_type identity()
Definition: algebra.hpp:120
base::ringbuffer_ptr< base::heap_allocator< Item, Capacity+1 >> ringbuffer_ptr
Segment descriptor.
Definition: segment.hpp:34
bootchunkseq< bootchunkseq_deque_config< Item, cachedmeasure::trivial< Item, size_t >, Capacity >> cdeque
static client_measured_type cclient(middle_measured_type m)
Definition: chunkedseq.hpp:187
Fixed-capacity array along with cached measurement of array contents.
Definition: chunk.hpp:93
typename Client_cache::size_type size_type
Definition: chunkedseq.hpp:66
static value_type combine(value_type x, value_type y)
Definition: algebra.hpp:125
Middle_sequence< chunk_type, middle_chunk_capacity, middle_cache_type, Pointer_deleter, Pointer_deep_copier, fixedcapacity::heap_allocated::ringbuffer_ptr, size_access > middle_type
Definition: chunkedseq.hpp:202
Chunk_struct< value_type, Chunk_capacity, item_allocator_type > item_queue_type
Definition: chunkedseq.hpp:76
Representation of a chunk.
typename chunk_cache_type::measured_type chunk_measured_type
Definition: chunkedseq.hpp:84
Hinze & Patterson's 2-3 finger tree.
typename middle_algebra_type::value_type middle_measured_type
Definition: chunkedseq.hpp:81
base::ringbuffer_ptrx< base::heap_allocator< Item, Capacity+1 >> ringbuffer_ptrx
Definition: algebra.hpp:18
Fixed capacity vectors.
size_type size() const
Definition: chunk.hpp:245
[int_group_under_addition_and_negation]
Definition: algebra.hpp:105
Definitions of a few cached-measurement policies.
measure::measured_pair< value1_type, value2_type > value_type
Definition: algebra.hpp:114
typename queue_type::value_type value_type
Definition: chunk.hpp:101
static void swap(measured_type &x, measured_type &y)
Definition: chunkedseq.hpp:163
chunk< item_queue_type, chunk_cache_type, annotation_type > chunk_type
Definition: chunkedseq.hpp:98
static size_type csize(middle_measured_type m)
Definition: chunkedseq.hpp:181
Chunked-sequence functor.
measured_type operator()(const value_type *lo, const value_type *hi) const
Definition: chunkedseq.hpp:146
measured_type get_cached() const
Definition: chunk.hpp:254
static size_type & size(middle_measured_type &m)
Definition: chunkedseq.hpp:178
Representation of a chunk.
static client_measured_type & client(middle_measured_type &m)
Definition: chunkedseq.hpp:184
typename Client_cache::algebra_type client_algebra_type
Definition: chunkedseq.hpp:78
bytes_8 Item
Definition: do_fifo.cpp:107