host: if monotonic don't run monotonic algo

In some cases the input is already monotonic and we shouldn't
try to make it monotonic again.

Signed-off-by: Steven Koo <steven.koo@ni.com>
This commit is contained in:
Steven Koo 2022-09-08 09:33:37 -05:00 committed by skooNI
parent 5f1a0166bf
commit e7a067c068

View File

@ -94,31 +94,36 @@ meta_range_t::meta_range_t(double start, double stop, double step)
meta_range_t meta_range_t::as_monotonic() const
{
meta_range_t result;
for (const auto& range : *this) {
if (range.step() != 0.0) {
throw uhd::value_error("Cannot monotonize meta_range which contains non-continuous subranges");
try {
check_meta_range_monotonic(*this);
} catch (const uhd::value_error& e) {
meta_range_t result;
for (const auto& range : *this) {
if (range.step() != 0.0) {
throw uhd::value_error("Cannot monotonize meta_range which contains "
"non-continuous subranges");
}
result.push_back(range);
}
result.push_back(range);
}
std::sort(result.begin(), result.end(), [](const range_t& a, const range_t& b) {
return a.start() < b.start();
});
std::sort(result.begin(), result.end(), [](const range_t& a, const range_t& b) {
return a.start() < b.start();
});
// Merge overlapping
size_t i = 1;
while (i < result.size()) {
if (result[i - 1].stop() > result[i].start()) {
const auto new_stop = std::max(result[i - 1].stop(), result[i].stop());
result[i - 1] = range_t(result[i - 1].start(), new_stop, 0.0);
result.erase(result.begin() + i);
} else {
i++;
// Merge overlapping
size_t i = 1;
while (i < result.size()) {
if (result[i - 1].stop() > result[i].start()) {
const auto new_stop = std::max(result[i - 1].stop(), result[i].stop());
result[i - 1] = range_t(result[i - 1].start(), new_stop, 0.0);
result.erase(result.begin() + i);
} else {
i++;
}
}
return result;
}
return result;
return *this;
}
double meta_range_t::start(void) const