(index) Backport bugfix from term-positions branch

The ordering of TermIdsList is assumed to be unchanged by the surrounding code, but the constructor sorts the dang list to be able to do contains() by binary search.  This is no bueno.

This is gonna be a merge conflict in the future, but it's too big of a bug to leave for another month.
This commit is contained in:
Viktor Lofgren 2024-08-09 21:17:02 +02:00
parent ac67b6b5da
commit 2f38c95886

View File

@ -3,7 +3,6 @@ package nu.marginalia.index.results.model.ids;
import it.unimi.dsi.fastutil.longs.LongArrayList;
import java.util.Arrays;
import java.util.Objects;
import java.util.stream.LongStream;
public final class TermIdList {
@ -29,6 +28,24 @@ public final class TermIdList {
return array;
}
public long at(int i) {
return array[i];
}
public boolean contains(long id) {
// array is typically small and unsorted, so linear search is fine
for (int i = 0; i < array.length; i++) {
if (array[i] == id) {
return true;
}
}
return false;
}
public int indexOf(long id) {
return Arrays.binarySearch(array, id);
}
@Override
public boolean equals(Object obj) {
if (obj == this) return true;