(coded-sequence) Correct behavior of findIntersections

This commit is contained in:
Viktor Lofgren 2024-08-25 14:54:17 +02:00
parent fdf05cedae
commit 805cb5ad58
2 changed files with 12 additions and 7 deletions

View File

@ -87,6 +87,9 @@ public class SequenceOperations {
if (indexes[i] < positions[i].size()) {
values[i] = positions[i].getInt(indexes[i]++) + offsets[i];
// Update the maximum value, if necessary
max = Math.max(max, values[i]);
} else {
break;
}
@ -177,18 +180,22 @@ public class SequenceOperations {
minDist = Math.min(minDist, maxVal - minVal);
for (int i = 0;; i = (i + 1) % positions.length)
{
if (values[i] == minVal) {
for (;;) {
for (int i = 0; i < positions.length; i++) {
if (values[i] > minVal) {
continue;
}
if (indexes[i] < positions[i].size()) {
values[i] = positions[i].getInt(indexes[i]++) + offsets[i];
} else {
break;
return minDist;
}
if (values[i] > maxVal) {
maxVal = values[i];
}
if (values[i] > minVal) {
minVal = Integer.MAX_VALUE;
for (int val : values) {
@ -199,7 +206,5 @@ public class SequenceOperations {
minDist = Math.min(minDist, maxVal - minVal);
}
}
return minDist;
}
}

View File

@ -70,7 +70,7 @@ class SequenceOperationsTest {
GammaCodedSequence seq2 = GammaCodedSequence.generate(wa, 2, 5, 8, 10, 14);
GammaCodedSequence seq3 = GammaCodedSequence.generate(wa, 1, 5, 8, 9, 10);
assertEquals(IntList.of(8, 10), SequenceOperations.findIntersections(seq1.iterator(), seq2.iterator(), seq3.iterator()));
assertEquals(IntList.of(8, 10), SequenceOperations.findIntersections(seq1.values(), seq2.values(), seq3.values()));
}