4#ifndef APPROXIMATING_FUNCTION_H_
5#define APPROXIMATING_FUNCTION_H_
9template<
typename X,
typename Y>
11 const X& x1,
const X& x2,
12 const Y& y1,
const Y& y2) {
13 Y return_val =
static_cast<Y
>((
x - x1) * (y2 - y1) / (x2 - x1) + y1);
17template <
typename KeyT,
typename ValT>
24template <
typename KeyT,
typename ValT>
28 int* dest_lower_bound,
29 int* dest_upper_bound) {
31 *dest_lower_bound = *dest_upper_bound = -1;
34 if (k < array[0].key) {
35 *dest_lower_bound = *dest_upper_bound = 0;
39 for (
int i = 0; i < n - 1; ++i) {
43 if (curr.
key <= k && k <= next.
key) {
44 *dest_lower_bound = i;
45 *dest_upper_bound = i+1;
49 *dest_lower_bound = n - 1;
50 *dest_upper_bound = n - 1;
53template <
typename KeyT,
typename ValT>
64 if (low_idx == high_idx) {
65 return array[low_idx].
val;
ValT Interp(const KeyT &k, const InterpData< KeyT, ValT > *array, const int n)
void SelectInterpPoints(const KeyT &k, const InterpData< KeyT, ValT > *array, const int n, int *dest_lower_bound, int *dest_upper_bound)
const Y MapT(const X &x, const X &x1, const X &x2, const Y &y1, const Y &y2)
InterpData(const KeyT &k, const ValT &v)