Skip to content

Commit

Permalink
interval_set: optimize intersect_of for identical spans
Browse files Browse the repository at this point in the history
Optimize comparisons for identical spans of intervals.
When this patch is combined with the previous map insert
optimization, a benchmark using 400000 identical
intervals shows a 7 times performance improvement in
comparison to without the patches.

Signed-off-by: Zac Medico <[email protected]>
  • Loading branch information
zmedico committed Aug 30, 2017
1 parent 32bc043 commit b6a0356
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/include/interval_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,17 @@ class interval_set {
{ pa++; continue; }
if (pb->first + pb->second <= pa->first)
{ pb++; continue; }

if (*pa == *pb) {
do {
mi = m.insert(mi, *pa);
_size += pa->second;
++pa;
++pb;
} while (pa != a.m.end() && pb != b.m.end() && *pa == *pb);
continue;
}

T start = MAX(pa->first, pb->first);
T en = MIN(pa->first+pa->second, pb->first+pb->second);
assert(en > start);
Expand Down

0 comments on commit b6a0356

Please sign in to comment.