mirror of
https://github.com/MarginaliaSearch/MarginaliaSearch.git
synced 2025-10-05 21:22:39 +02:00
(index) Add sanity assertions to SkipListReader
This commit is contained in:
@@ -115,6 +115,13 @@ public class LongQueryBuffer {
|
||||
return ++read < end;
|
||||
}
|
||||
|
||||
public boolean isAscending() {
|
||||
for (int i = read + 1; i < end; i++) {
|
||||
if (data.get(i-1) > data.get(i))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/** Retains the current value at the read pointer and advances the read and write pointers.
|
||||
* Returns true if there are more values to read.
|
||||
* <p></p> To enable "or" style criterias, the method swaps the current value with the value
|
||||
|
@@ -10,6 +10,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.lang.foreign.MemorySegment;
|
||||
import java.lang.foreign.ValueLayout;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class SkipListReader {
|
||||
@@ -64,6 +65,8 @@ public class SkipListReader {
|
||||
* a single page, and return true if additional computation is available.
|
||||
*/
|
||||
public boolean tryRetainData(@NotNull LongQueryBuffer data) {
|
||||
assert data.isAscending();
|
||||
|
||||
try (var page = pool.get(currentBlock)) {
|
||||
|
||||
int n = headerNumRecords(page, currentBlockOffset);
|
||||
@@ -108,6 +111,8 @@ public class SkipListReader {
|
||||
* exist in the skip list index.
|
||||
*/
|
||||
public void retainData(@NotNull LongQueryBuffer data) {
|
||||
assert data.isAscending();
|
||||
|
||||
while (data.hasMore()) {
|
||||
try (var page = pool.get(currentBlock)) {
|
||||
|
||||
@@ -198,6 +203,12 @@ public class SkipListReader {
|
||||
int pos = 0;
|
||||
long[] vals = new long[keys.length];
|
||||
|
||||
if (getClass().desiredAssertionStatus()) {
|
||||
for (int i = 1; i < keys.length; i++) {
|
||||
assert keys[i] >= keys[i-1] : "Not ascending: " + Arrays.toString(keys);
|
||||
}
|
||||
}
|
||||
|
||||
while (pos < keys.length) {
|
||||
try (var page = pool.get(currentBlock)) {
|
||||
MemorySegment ms = page.getMemorySegment();
|
||||
@@ -290,6 +301,8 @@ public class SkipListReader {
|
||||
* a single page, and return true if additional computation is available.
|
||||
*/
|
||||
public boolean tryRejectData(@NotNull LongQueryBuffer data) {
|
||||
assert data.isAscending();
|
||||
|
||||
try (var page = pool.get(currentBlock)) {
|
||||
|
||||
int n = headerNumRecords(page, currentBlockOffset);
|
||||
@@ -427,6 +440,7 @@ public class SkipListReader {
|
||||
public int getKeys(@NotNull LongQueryBuffer dest)
|
||||
{
|
||||
if (atEnd) return 0;
|
||||
assert dest.isAscending();
|
||||
|
||||
int totalCopied = 0;
|
||||
while (dest.fitsMore() && !atEnd) {
|
||||
|
Reference in New Issue
Block a user