Do a pseudo merge of events in the envelopes

This commit is contained in:
Paul Ferrand 2020-01-20 19:09:31 +01:00
parent f66aedfc4f
commit 65f172a02e
2 changed files with 26 additions and 8 deletions

View file

@ -65,15 +65,33 @@ void EventEnvelope<Type>::registerEvent(int timestamp, Type inputValue)
}
template <class Type>
void EventEnvelope<Type>::prepareEvents()
void EventEnvelope<Type>::prepareEvents(int blockLength)
{
if (resetEvents)
clear();
absl::c_sort(events, [](const auto& lhs, const auto& rhs) {
absl::c_stable_sort(events, [](const auto& lhs, const auto& rhs) {
return lhs.first < rhs.first;
});
auto eventIt = events.begin();
while (eventIt < events.end()) {
if (eventIt->first >= blockLength) {
eventIt->first = blockLength - 1;
eventIt->second = events.back().second;
++eventIt;
break;
}
auto nextEventIt = std::next(eventIt);
while (nextEventIt < events.end() && eventIt->first == nextEventIt->first ) {
eventIt->second = nextEventIt->second;
++nextEventIt;
}
++eventIt;
}
events.resize(std::distance(events.begin(), eventIt));
resetEvents = true;
}
@ -93,15 +111,15 @@ void EventEnvelope<Type>::reset(Type value)
}
template <class Type>
void EventEnvelope<Type>::getBlock(absl::Span<Type>)
void EventEnvelope<Type>::getBlock(absl::Span<Type> output)
{
prepareEvents();
prepareEvents(output.size());
}
template <class Type>
void EventEnvelope<Type>::getQuantizedBlock(absl::Span<Type>, Type)
void EventEnvelope<Type>::getQuantizedBlock(absl::Span<Type> output, Type)
{
prepareEvents();
prepareEvents(output.size());
}
template <class Type>

View file

@ -113,7 +113,7 @@ private:
static_assert(std::is_arithmetic<Type>::value, "Type should be arithmetic");
std::function<Type(Type)> function { [](Type input) { return input; } };
int maxCapacity { config::defaultSamplesPerBlock };
void prepareEvents();
void prepareEvents(int blockLength);
bool resetEvents { false };
LEAK_DETECTOR(EventEnvelope);
};