diff --git a/code/libraries/array/java/nu/marginalia/array/page/LongQueryBuffer.java b/code/libraries/array/java/nu/marginalia/array/page/LongQueryBuffer.java index 35421f39b..6858bdb31 100644 --- a/code/libraries/array/java/nu/marginalia/array/page/LongQueryBuffer.java +++ b/code/libraries/array/java/nu/marginalia/array/page/LongQueryBuffer.java @@ -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. *

To enable "or" style criterias, the method swaps the current value with the value diff --git a/code/libraries/skiplist/java/nu/marginalia/skiplist/SkipListReader.java b/code/libraries/skiplist/java/nu/marginalia/skiplist/SkipListReader.java index 269722306..c1913da4a 100644 --- a/code/libraries/skiplist/java/nu/marginalia/skiplist/SkipListReader.java +++ b/code/libraries/skiplist/java/nu/marginalia/skiplist/SkipListReader.java @@ -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) {