1
0
mirror of https://github.com/CovidBraceletPrj/CovidBracelet.git synced 2024-10-14 18:09:19 +02:00

Contacts: optimize iterator init if periods overlap

This commit is contained in:
H1ghBre4k3r 2021-07-30 00:17:00 +02:00 committed by Patrick Rathje
parent ea492e11f9
commit f7587911d2

View File

@ -56,19 +56,30 @@ int register_record(record_t* record) {
int get_number_of_infected_for_multiple_intervals(infected_for_period_key_ctx_t* ctx, int count) {
record_iterator_t iterator;
for (int i = 0; i < count; i++) {
int rc = ens_records_iterator_init_timerange(&iterator, &ctx[i].search_start, &ctx[i].search_end);
int i = 0;
while (i < count) {
// determine start and end of iterator
int start = i;
int end = i;
while (end + 1 < count && ctx[end + 1].search_start <= ctx[end].search_end) {
end++;
}
// init iterator with start and end
int rc = ens_records_iterator_init_timerange(&iterator, &ctx[start].search_start, &ctx[end].search_end);
if (rc) {
continue;
goto end;
}
while (!iterator.finished) {
if (memcmp(&iterator.current.rolling_proximity_identifier, &ctx[i].interval_identifier,
sizeof(iterator.current.rolling_proximity_identifier)) == 0) {
ctx[i].infected++;
break;
for (int j = start; j <= end; j++) {
if (memcmp(&iterator.current.rolling_proximity_identifier, &ctx[j].interval_identifier,
sizeof(iterator.current.rolling_proximity_identifier)) == 0) {
ctx[j].infected++;
}
}
ens_records_iterator_next(&iterator);
}
end:
i = end + 1;
}
return 0;
}