increment counters appropriately after increasing value size to integer

pull/62/head
Zlatin Balevsky 2021-06-05 05:29:54 +01:00
parent ea1f431323
commit 72c4998954
No known key found for this signature in database
GPG Key ID: A72832072D525E41
2 changed files with 32 additions and 4 deletions

View File

@ -162,7 +162,7 @@ public class BSkipSpan<K extends Comparable<? super K>, V> extends SkipSpan<K, V
byte[] valData;
for(int i=0;i<nKeys;i++) {
if((pageCounter[0] + 4) > BlockFile.PAGESIZE) {
if((pageCounter[0] + 6) > BlockFile.PAGESIZE) {
if(curNextPage[0] == 0) {
curNextPage[0] = bf.allocPage();
BlockFile.pageSeek(bf.file, curNextPage[0]);
@ -193,7 +193,7 @@ public class BSkipSpan<K extends Comparable<? super K>, V> extends SkipSpan<K, V
i--;
continue;
}
pageCounter[0] += 4;
pageCounter[0] += 6;
bf.file.writeShort(keyData.length);
bf.file.writeInt(valData.length);
curPage = bf.writeMultiPageData(keyData, curPage, pageCounter, curNextPage);
@ -289,7 +289,7 @@ public class BSkipSpan<K extends Comparable<? super K>, V> extends SkipSpan<K, V
// System.out.println("Span Load " + sz + " nKeys " + nKeys + " page " + curPage);
int fail = 0;
for(int i=0;i<this.nKeys;i++) {
if((pageCounter[0] + 4) > BlockFile.PAGESIZE) {
if((pageCounter[0] + 6) > BlockFile.PAGESIZE) {
BlockFile.pageSeek(this.bf.file, curNextPage[0]);
int magic = bf.file.readInt();
if (magic != BlockFile.MAGIC_CONT) {
@ -304,7 +304,7 @@ public class BSkipSpan<K extends Comparable<? super K>, V> extends SkipSpan<K, V
vsz = this.bf.file.readInt();
if (vsz > MAX_VALUE_SIZE)
throw new IOException("corrupt value");
pageCounter[0] +=4;
pageCounter[0] +=6;
byte[] k = new byte[ksz];
byte[] v = new byte[vsz];
int lastGood = curPage;

View File

@ -158,4 +158,32 @@ class SearchIndexTest {
assert index.search(["same"]).size() == 1
}
@Test
void testAddMany() {
initIndex([])
index.add("output-base.css")
index.add("amo-version.sh")
index.add("adding build1-5")
index.add("TODO")
index.add("ICENSE-EPL-v1.0.html")
index.add("jdk15.xml")
index.add("sud2zip")
index.with {
add("gradlew.bat")
add("osx launcher.jpeg")
add("get-m2.xml")
add("build.gradle")
add("adding README.md")
add("CONTRIBUTORS")
add("#i2p-notrelayed.html")
add("Docker.expt")
add("swt-debug.jar")
add("README.md")
add("gradlew")
add("nothing.o")
add("install.jar")
add("settings.gradle")
}
}
}