mirror of
https://github.com/MarginaliaSearch/MarginaliaSearch.git
synced 2025-02-24 05:18:58 +00:00
Fix overflow bugs in DictionaryHashMap that only surfaced without small RAM
This commit is contained in:
parent
661577b456
commit
c71cc3d43a
@ -59,12 +59,14 @@ public class DictionaryData {
|
|||||||
private final LongBuffer keys;
|
private final LongBuffer keys;
|
||||||
|
|
||||||
private int size;
|
private int size;
|
||||||
|
private final int capacity;
|
||||||
|
|
||||||
|
|
||||||
public DictionaryDataBank(int start_idx, int sz) {
|
public DictionaryDataBank(int start_idx, int sz) {
|
||||||
this.start_idx = start_idx;
|
this.start_idx = start_idx;
|
||||||
|
this.capacity = sz;
|
||||||
|
|
||||||
keys = ByteBuffer.allocateDirect(8*sz).asLongBuffer();
|
keys = ByteBuffer.allocateDirect(8*capacity).asLongBuffer();
|
||||||
size = 0;
|
size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,10 +90,13 @@ public class DictionaryData {
|
|||||||
throw new IndexOutOfBoundsException(idx);
|
throw new IndexOutOfBoundsException(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
return keys.get(idx - start_idx) == other;
|
return keys.get(idx - start_idx) == other;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int add(long newKey) {
|
public int add(long newKey) {
|
||||||
|
if (size >= capacity)
|
||||||
|
return -1;
|
||||||
|
|
||||||
keys.put(size, newKey);
|
keys.put(size, newKey);
|
||||||
|
|
||||||
return start_idx + size++;
|
return start_idx + size++;
|
||||||
|
@ -66,8 +66,7 @@ public class DictionaryHashMap {
|
|||||||
logger.debug("Buffer size sanity checked passed");
|
logger.debug("Buffer size sanity checked passed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dictionaryData = new DictionaryData((int)Math.min(1<<27, Math.max(32L, sizeMemory/4)));
|
||||||
dictionaryData = new DictionaryData(Math.min(1<<30, Math.max(32, (int)(sizeMemory/4))));
|
|
||||||
|
|
||||||
initializeBuffers();
|
initializeBuffers();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user