mirror of
https://github.com/CovidBraceletPrj/CovidBracelet.git
synced 2024-12-05 00:55:43 +01:00
Contacts: optimize iterator init if periods overlap
This commit is contained in:
parent
ea492e11f9
commit
f7587911d2
@ -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) {
|
int get_number_of_infected_for_multiple_intervals(infected_for_period_key_ctx_t* ctx, int count) {
|
||||||
record_iterator_t iterator;
|
record_iterator_t iterator;
|
||||||
for (int i = 0; i < count; i++) {
|
int i = 0;
|
||||||
int rc = ens_records_iterator_init_timerange(&iterator, &ctx[i].search_start, &ctx[i].search_end);
|
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) {
|
if (rc) {
|
||||||
continue;
|
goto end;
|
||||||
}
|
}
|
||||||
while (!iterator.finished) {
|
while (!iterator.finished) {
|
||||||
if (memcmp(&iterator.current.rolling_proximity_identifier, &ctx[i].interval_identifier,
|
for (int j = start; j <= end; j++) {
|
||||||
sizeof(iterator.current.rolling_proximity_identifier)) == 0) {
|
if (memcmp(&iterator.current.rolling_proximity_identifier, &ctx[j].interval_identifier,
|
||||||
ctx[i].infected++;
|
sizeof(iterator.current.rolling_proximity_identifier)) == 0) {
|
||||||
break;
|
ctx[j].infected++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ens_records_iterator_next(&iterator);
|
ens_records_iterator_next(&iterator);
|
||||||
}
|
}
|
||||||
|
end:
|
||||||
|
i = end + 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user