Median.h: Sort values on median retrieval instead live on adding
This commit is contained in:
@@ -30,17 +30,18 @@ namespace Stats {
|
||||
/** add the given scalar value to the median calculation */
|
||||
void add(const Scalar value) {
|
||||
|
||||
const auto idx = std::upper_bound( sorted.begin(), sorted.end(), value );
|
||||
sorted.insert( idx, value );
|
||||
|
||||
sorted.push_back(value);
|
||||
}
|
||||
|
||||
/** get the median of all added values */
|
||||
Scalar get() const {
|
||||
Scalar get() {
|
||||
|
||||
// sanity check
|
||||
Assert::isNot0(sorted.size(), "add elements first!");
|
||||
|
||||
std::sort(sorted.begin(), sorted.end());
|
||||
|
||||
if (sorted.size() % 2 == 1) { // odd
|
||||
|
||||
const int idx = sorted.size()/2;
|
||||
|
||||
Reference in New Issue
Block a user