summarylogtreecommitdiffstats
path: root/backport_0.9.6_algorithm_median.patch
diff options
context:
space:
mode:
Diffstat (limited to 'backport_0.9.6_algorithm_median.patch')
-rw-r--r--backport_0.9.6_algorithm_median.patch29
1 files changed, 29 insertions, 0 deletions
diff --git a/backport_0.9.6_algorithm_median.patch b/backport_0.9.6_algorithm_median.patch
new file mode 100644
index 000000000000..f05fec0d07c3
--- /dev/null
+++ b/backport_0.9.6_algorithm_median.patch
@@ -0,0 +1,29 @@
+--- a/rak/algorithm.h 2016-11-04 21:58:44.000000000 +0000
++++ b/rak/algorithm.h 2017-03-10 21:16:32.039264146 +0000
+@@ -176,6 +176,26 @@ inline int popcount_wrapper(T t) {
+ #endif
+ }
+
++// Get the median of an unordered set of numbers of arbitrary
++// type by modifing the underlying dataset
++template <typename T = double, typename _InputIter>
++T median(_InputIter __first, _InputIter __last) {
++ T __med;
++
++ unsigned int __size = __last - __first;
++ unsigned int __middle = __size / 2;
++ _InputIter __target1 = __first + __middle;
++ std::nth_element(__first, __target1, __last);
++ __med = *__target1;
++
++ if (__size % 2 == 0) {
++ _InputIter __target2 = std::max_element(__first, __target1);
++ __med = (__med + *__target2) / 2.0;
++ }
++
++ return __med;
++}
++
+ }
+
+ #endif