aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/queryeval/flow.h
diff options
context:
space:
mode:
Diffstat (limited to 'searchlib/src/vespa/searchlib/queryeval/flow.h')
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/flow.h36
1 files changed, 35 insertions, 1 deletions
diff --git a/searchlib/src/vespa/searchlib/queryeval/flow.h b/searchlib/src/vespa/searchlib/queryeval/flow.h
index cfbb28b190f..f31122166d9 100644
--- a/searchlib/src/vespa/searchlib/queryeval/flow.h
+++ b/searchlib/src/vespa/searchlib/queryeval/flow.h
@@ -4,7 +4,7 @@
#include <vespa/vespalib/util/small_vector.h>
#include <cstddef>
#include <algorithm>
-#include <cmath>
+#include <functional>
// Model how boolean result decisions flow through intermediate nodes
// of different types based on relative estimates for sub-expressions
@@ -280,4 +280,38 @@ public:
}
};
+using FlowCalc = std::function<double(double)>;
+
+template <typename FLOW>
+FlowCalc flow_calc(bool strict, double non_strict_rate) {
+ FLOW flow = strict ? FLOW(true) : FLOW(non_strict_rate);
+ return [flow](double est) mutable noexcept {
+ double next_flow = flow.flow();
+ flow.add(est);
+ return next_flow;
+ };
+}
+
+inline FlowCalc first_flow_calc(bool strict, double flow) {
+ if (strict) {
+ flow = 1.0;
+ }
+ bool first = true;
+ return [flow,first](double est) mutable noexcept {
+ double next_flow = flow;
+ if (first) {
+ flow *= est;
+ first = false;
+ }
+ return next_flow;
+ };
+}
+
+inline FlowCalc full_flow_calc(bool strict, double flow) {
+ if (strict) {
+ flow = 1.0;
+ }
+ return [flow](double) noexcept { return flow; };
+}
+
}