chunkedseq
container library for large in-memory data sets
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
measure.hpp
Go to the documentation of this file.
1 
13 #include <assert.h>
14 #include <utility>
15 
16 #ifndef _PASL_DATA_MEASURE_H_
17 #define _PASL_DATA_MEASURE_H_
18 
19 namespace pasl {
20 namespace data {
21 namespace measure {
22 
23 /***********************************************************************/
24 
25 /*---------------------------------------------------------------------*/
27 template <class Item, class Measured>
28 class trivial {
29 public:
30 
31  using value_type = Item;
32  using measured_type = Measured;
33 
35  return measured_type();
36  }
37 
38  measured_type operator()(const value_type* lo, const value_type* hi) const {
39  return measured_type();
40  }
41 
42 };
44 
45 /*---------------------------------------------------------------------*/
47 template <class Item, class Measured, int Item_weight=1>
48 class uniform {
49 public:
50 
51  using value_type = Item;
52  using measured_type = Measured;
53  const int item_weight = Item_weight;
54 
56  return measured_type(item_weight);
57  }
58 
59  measured_type operator()(const value_type* lo, const value_type* hi) const {
60  return measured_type(hi - lo);
61  }
62 };
64 
65 /*---------------------------------------------------------------------*/
67 template <class Item, class Weight, class Client_weight_fct>
68 class weight {
69 public:
70 
71  using value_type = Item;
72  using measured_type = Weight;
73  using client_weight_fct_type = Client_weight_fct;
74 
75 private:
76 
77  client_weight_fct_type client_weight_fct;
78 
79  // for debugging purposes
80  bool initialized;
81 
82 public:
83 
84  weight() : initialized(false) { }
85 
87  : client_weight_fct(env), initialized(true) { }
88 
90  return client_weight_fct(v);
91  }
92 
93  measured_type operator()(const value_type* lo, const value_type* hi) const {
94  measured_type m = 0;
95  for (auto p = lo; p < hi; p++)
96  m += operator()(*p);
97  return m;
98  }
99 
101  assert(initialized);
102  return client_weight_fct;
103  }
104 
106  client_weight_fct = wf;
107  initialized = true;
108  }
109 
110 };
112 
113 /*---------------------------------------------------------------------*/
115 template <class Measured1, class Measured2>
117 public:
118  Measured1 value1;
119  Measured2 value2;
121  measured_pair(const Measured1& value1, const Measured2& value2)
122  : value1(value1), value2(value2) { }
123 };
124 
125 template <class Measured1, class Measured2>
128  return m;
129 }
131 
132 /*---------------------------------------------------------------------*/
134 template <class Item, class Measure1, class Measure2>
135 class combiner {
136 public:
137 
138  using measure1_type = Measure1;
139  using measure2_type = Measure2;
140 
141  using value_type = Item;
143 
146 
147  combiner() { }
148 
149  combiner(const measure1_type meas1)
150  : meas1(meas1) { }
151 
152  combiner(const measure2_type meas2)
153  : meas2(meas2) { }
154 
155  combiner(const measure1_type meas1, const measure2_type meas2)
156  : meas1(meas1), meas2(meas2) { }
157 
159  return make_measured_pair(meas1(v), meas2(v));
160  }
161 
162  measured_type operator()(const value_type* lo, const value_type* hi) const {
163  return make_measured_pair(meas1(lo, hi), meas2(lo, hi));
164  }
165 
166 };
168 
169 /***********************************************************************/
170 
171 } // end namespace
172 } // end namespace
173 } // end namespace
174 
175 #endif
measured_type operator()(const value_type *lo, const value_type *hi) const
Definition: measure.hpp:59
weight(const client_weight_fct_type &env)
Definition: measure.hpp:86
measured_type operator()(const value_type *lo, const value_type *hi) const
Definition: measure.hpp:93
measured_type operator()(const value_type *lo, const value_type *hi) const
Definition: measure.hpp:162
combiner(const measure2_type meas2)
Definition: measure.hpp:152
Client_weight_fct client_weight_fct_type
Definition: measure.hpp:73
combiner(const measure1_type meas1, const measure2_type meas2)
Definition: measure.hpp:155
measured_type operator()(const value_type &v) const
Definition: measure.hpp:89
client_weight_fct_type get_env() const
Definition: measure.hpp:100
measured_type operator()(const value_type &v) const
Definition: measure.hpp:34
Definition: algebra.hpp:18
void set_env(client_weight_fct_type wf)
Definition: measure.hpp:105
measured_type operator()(const value_type &v) const
Definition: measure.hpp:158
measured_pair< Measured1, Measured2 > make_measured_pair(Measured1 m1, Measured2 m2)
Definition: measure.hpp:126
measured_type operator()(const value_type *lo, const value_type *hi) const
Definition: measure.hpp:38
combiner(const measure1_type meas1)
Definition: measure.hpp:149
measured_type operator()(const value_type &v) const
Definition: measure.hpp:55
measured_pair(const Measured1 &value1, const Measured2 &value2)
Definition: measure.hpp:121
bytes_8 Item
Definition: do_fifo.cpp:107