chunkedseq
container library for large in-memory data sets
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
trivbootchunkedseq.hpp
Go to the documentation of this file.
1 
13 #include "cachedmeasure.hpp"
14 #include "bootchunkedseq.hpp"
15 
16 #ifndef _PASL_DATA_TRIVBOOTCHUNKEDSEQ_H_
17 #define _PASL_DATA_TRIVBOOTCHUNKEDSEQ_H_
18 
19 namespace pasl {
20 namespace data {
21 namespace chunkedseq {
22 namespace bootchunkedseq {
23 
24 /***********************************************************************/
25 
26 // basic instantiation of bootchunkedseq
27 template <class Item, int Chunk_capacity=32>
28 class triv {
29 private:
30 
31  class top_item_type {
32  public:
33  Item value;
34  top_item_type() { }
35  top_item_type(const Item& value)
36  : value(value) { }
37  size_t get_cached() const {
38  return 1;
39  }
40  };
41 
42  class sized_cached_measure {
43  public:
44 
45  using size_type = size_t;
46  using value_type = top_item_type*;
48  using measured_type = typename algebra_type::value_type;
49 
50  class measure_type {
51  public:
52 
53  measured_type operator()(const value_type& v) const {
54  return v->get_cached();
55  }
56 
57  measured_type operator()(const value_type* lo, const value_type* hi) const {
58  measured_type m = algebra_type::identity();
59  for (auto p = lo; p < hi; p++)
60  m = algebra_type::combine(m, operator()(*p));
61  return m;
62  }
63 
64  };
65 
66  static void swap(measured_type& x, measured_type y) {
67  std::swap(x, y);
68  }
69 
70  };
71 
72  using measure_type = typename sized_cached_measure::measure_type;
73 
75 
76  measure_type meas_fct;
77  seq_type seq;
78 
79 public:
80 
81  using size_type = size_t;
82 
83  using value_type = Item;
85  using const_reference = const value_type&;
86  using pointer = value_type*;
87  using const_pointer = const value_type*;
88 
90 
91  bool empty() const {
92  return seq.empty();
93  }
94 
95  size_type size() const {
96  return seq.get_cached();
97  }
98 
100  top_item_type& x = seq.front();
101  return x.value;
102  }
103 
105  top_item_type& x = seq.back();
106  return x.value;
107  }
108 
109  void push_front(const value_type& v) {
110  seq.push_front(meas_fct, new top_item_type(v));
111  }
112 
113  void push_back(const value_type& v) {
114  seq.push_back(meas_fct, new top_item_type(v));
115  }
116 
118  top_item_type x = seq.pop_front();
119  value_type v = x.value;
120  delete x;
121  return v;
122  }
123 
125  top_item_type x = seq.pop_back();
126  value_type v = x.value;
127  delete x;
128  return v;
129  }
130 
131  void split(size_type n, self_type& other) {
132  if (n == 0)
133  return;
134  size_type index = n - 1;
135  size_type sz = size();
136  assert(index < sz);
137  top_item_type* v;
138  seq.split(index, v, other.seq);
139  assert(size() == index);
140  seq.push_back(meas_fct, v);
141  }
142 
143  void concat(self_type& other) {
144  seq.concat(other.seq);
145  }
146 
147  template <class Body>
148  void for_each(const Body& f) const {
149  seq.for_each([&] (top_item_type* v) {
150  f(v->value);
151  });
152  }
153 
154 };
155 
156 /***********************************************************************/
157 
158 } // end namespace
159 } // end namespace
160 } // end namespace
161 } // end namespace
162 
163 #endif
void split(size_type n, self_type &other)
bootchunkseq< bootchunkseq_deque_config< Item, cachedmeasure::trivial< Item, size_t >, Capacity >> cdeque
Representation of a chunk.
Definition: algebra.hpp:18
Definitions of a few cached-measurement policies.
static value_type combine(value_type x, value_type y)
Definition: algebra.hpp:74
measured_type operator()(const value_type *lo, const value_type *hi) const
bytes_8 Item
Definition: do_fifo.cpp:107