Fixed search of indices on tiny charts in statistics.

This commit is contained in:
23rd 2023-11-23 00:07:08 +03:00 committed by John Preston
parent 909f3bf011
commit 856f39c123
2 changed files with 3 additions and 2 deletions

View File

@ -99,6 +99,7 @@ int StatisticalChart::findStartIndex(float64 v) const {
}
int StatisticalChart::findEndIndex(int left, float64 v) const {
const auto wasLeft = left;
const auto n = int(xPercentage.size());
if (v == 1.) {
return n - 1;
@ -120,7 +121,7 @@ int StatisticalChart::findEndIndex(int left, float64 v) const {
left = middle + 1;
}
}
return right;
return std::max(wasLeft, right);
}

View File

@ -50,7 +50,7 @@ void SegmentTree::build(int v, int from, int size) {
int SegmentTree::rMaxQ(int from, int to) {
if (_array.size() < kMinArraySize) {
auto max = std::numeric_limits<int>::min();
auto max = 0;
from = std::max(from, 0);
to = std::min(to, int(_array.size() - 1));
for (auto i = from; i <= to; i++) {