(index) Optimize DocumentSpan.countIntersections

This commit is contained in:
Viktor Lofgren 2024-08-25 13:43:29 +02:00
parent efd56efc63
commit 5660f291af

View File

@ -22,24 +22,13 @@ public class DocumentSpan {
return 0; return 0;
} }
int sei = 0;
int start = startsEnds.getInt(sei++);
int end = startsEnds.getInt(sei++);
int cnt = 0; int cnt = 0;
for (int pi = 0; pi < positions.size(); pi++) { for (int pi = 0; pi < positions.size(); pi++) {
int position = positions.getInt(pi); for (int sei = 0; sei < startsEnds.size(); sei ++) {
if (position < start) { if (startsEnds.getInt(sei) > positions.getInt(pi)) {
continue; cnt += sei % 2;
break;
} }
if (position < end) {
cnt++;
} else if (sei + 2 < startsEnds.size()) {
start = startsEnds.getInt(sei++);
end = startsEnds.getInt(sei++);
} else {
return cnt;
} }
} }