chunkedseq
container library for large in-memory data sets
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
algebra.hpp
Go to the documentation of this file.
1 
13 #include "measure.hpp"
14 
15 #ifndef _PASL_DATA_ALGEBRA_H_
16 #define _PASL_DATA_ALGEBRA_H_
17 
18 namespace pasl {
19 namespace data {
20 namespace algebra {
21 
22 /***********************************************************************/
23 
24 /*---------------------------------------------------------------------*/
26 
32 class trivial {
33 public:
34 
35  using value_type = struct { };
36 
37  static constexpr bool has_inverse = true;
38 
39  static value_type identity() {
40  return value_type();
41  }
42 
44  return identity();
45  }
46 
48  return identity();
49  }
50 
51 };
53 
54 /*---------------------------------------------------------------------*/
56 
62 template <class Int>
64 public:
65 
66  using value_type = Int;
67 
68  static constexpr bool has_inverse = true;
69 
70  static value_type identity() {
71  return value_type(0);
72  }
73 
75  return x + y;
76  }
77 
79  return value_type(-1) * x;
80  }
81 
82 };
84 
85 /*---------------------------------------------------------------------*/
87 
104 template <class Algebra1, class Algebra2>
105 class combiner {
106 public:
107 
108  using algebra1_type = Algebra1;
109  using algebra2_type = Algebra2;
110 
113 
115 
116  static constexpr bool has_inverse =
117  algebra1_type::has_inverse
118  && algebra2_type::has_inverse;
119 
120  static value_type identity() {
121  return measure::make_measured_pair(algebra1_type::identity(),
122  algebra2_type::identity());
123  }
124 
126  return measure::make_measured_pair(algebra1_type::combine(x.value1, y.value1),
127  algebra2_type::combine(x.value2, y.value2));
128  }
129 
131  return measure::make_measured_pair(algebra1_type::inverse(x.value1),
132  algebra2_type::inverse(x.value2));
133  }
134 
135 };
137 
147 template <class Algebra>
149  typename Algebra::value_type y) {
150  assert(Algebra::has_inverse);
151  return combine(x, Algebra::inverse(y));
152 }
153 
154 /***********************************************************************/
155 
156 } // end namespace
157 } // end namespace
158 } // end namespace
159 
160 #endif
static value_type inverse(value_type)
Definition: algebra.hpp:47
static constexpr bool has_inverse
Definition: algebra.hpp:116
static value_type identity()
Definition: algebra.hpp:120
typename Algebra1::value_type value1_type
Definition: algebra.hpp:111
static value_type combine(value_type x, value_type y)
Definition: algebra.hpp:125
static constexpr bool has_inverse
Definition: algebra.hpp:37
Definition: algebra.hpp:18
[int_group_under_addition_and_negation]
Definition: algebra.hpp:105
static value_type inverse(value_type x)
Definition: algebra.hpp:130
static value_type combine(value_type, value_type)
Definition: algebra.hpp:43
Definitions of a few standard measure functors.
static value_type combine(value_type x, value_type y)
Definition: algebra.hpp:74
measured_pair< Measured1, Measured2 > make_measured_pair(Measured1 m1, Measured2 m2)
Definition: measure.hpp:126
static value_type identity()
Definition: algebra.hpp:39
typename Algebra2::value_type value2_type
Definition: algebra.hpp:112
Algebra::value_type subtract(typename Algebra::value_type x, typename Algebra::value_type y)
[combiner]
Definition: algebra.hpp:148