ecnerwala's competitive programming library
#include "num/linear_fn.hpp"
| Coverage | Exec / Excl / Total | |
|---|---|---|
| Lines | 100.0% | 8 / 0 / 8 |
| Functions | 100.0% | 4 / 0 / 4 |
| Branches | 87.5% | 7 / 0 / 8 |
| Full report |
#pragma once
namespace wala {
// Linear function x -> a * x + b over num.
// operator* is composition: (f * g)(x) = f(g(x)).
// Default-constructs to the identity.
template <typename num> struct linear_fn {
num a = 1;
num b = 0;
num operator()(const num& x) const { return a * x + b; }
friend linear_fn operator*(const linear_fn& f, const linear_fn& g) {
return {f.a * g.a, f.a * g.b + f.b};
}
linear_fn& operator*=(const linear_fn& o) { return *this = *this * o; }
friend bool operator==(const linear_fn&, const linear_fn&) = default;
};
} // namespace wala
#line 2 "src/num/linear_fn.hpp"
namespace wala {
// Linear function x -> a * x + b over num.
// operator* is composition: (f * g)(x) = f(g(x)).
// Default-constructs to the identity.
template <typename num> struct linear_fn {
num a = 1;
num b = 0;
num operator()(const num& x) const { return a * x + b; }
friend linear_fn operator*(const linear_fn& f, const linear_fn& g) {
return {f.a * g.a, f.a * g.b + f.b};
}
linear_fn& operator*=(const linear_fn& o) { return *this = *this * o; }
friend bool operator==(const linear_fn&, const linear_fn&) = default;
};
} // namespace wala
// clang-format off
// @formatter:off
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpragmas"
#pragma GCC diagnostic ignored "-Wunknown-warning-option"
#pragma GCC diagnostic ignored "-Wmisleading-indentation"
#pragma GCC diagnostic ignored "-Wmultistatement-macros"
// src/num/linear_fn.hpp
namespace wala{
template<typename num>struct linear_fn{
num a=1;
num b=0;
num operator()(const num&x)const{return a*x+b;}
friend linear_fn operator*(const linear_fn&f,const linear_fn&g){
return{f.a*g.a,f.a*g.b+f.b};
}
linear_fn&operator*=(const linear_fn&o){return*this=*this*o;}
friend bool operator==(const linear_fn&,const linear_fn&)=default;
};
}
#pragma GCC diagnostic pop
// clang-format on
// @formatter:on
#pragma once
namespace wala {
// Linear function x -> a * x + b over num.
// operator* is composition: (f * g)(x) = f(g(x)).
// Default-constructs to the identity.
template <typename num> struct linear_fn {
num a = 1;
num b = 0;
num operator()(const num& x) const { return a * x + b; }
friend linear_fn operator*(const linear_fn& f, const linear_fn& g) {
return {f.a * g.a, f.a * g.b + f.b};
}
linear_fn& operator*=(const linear_fn& o) { return *this = *this * o; }
friend bool operator==(const linear_fn&, const linear_fn&) = default;
};
} // namespace wala