mirror of
https://github.com/MarginaliaSearch/MarginaliaSearch.git
synced 2025-02-23 21: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 int size;
|
||||
private final int capacity;
|
||||
|
||||
|
||||
public DictionaryDataBank(int start_idx, int sz) {
|
||||
this.start_idx = start_idx;
|
||||
this.capacity = sz;
|
||||
|
||||
keys = ByteBuffer.allocateDirect(8*sz).asLongBuffer();
|
||||
keys = ByteBuffer.allocateDirect(8*capacity).asLongBuffer();
|
||||
size = 0;
|
||||
}
|
||||
|
||||
@ -92,6 +94,9 @@ public class DictionaryData {
|
||||
}
|
||||
|
||||
public int add(long newKey) {
|
||||
if (size >= capacity)
|
||||
return -1;
|
||||
|
||||
keys.put(size, newKey);
|
||||
|
||||
return start_idx + size++;
|
||||
|
@ -66,8 +66,7 @@ public class DictionaryHashMap {
|
||||
logger.debug("Buffer size sanity checked passed");
|
||||
}
|
||||
|
||||
|
||||
dictionaryData = new DictionaryData(Math.min(1<<30, Math.max(32, (int)(sizeMemory/4))));
|
||||
dictionaryData = new DictionaryData((int)Math.min(1<<27, Math.max(32L, sizeMemory/4)));
|
||||
|
||||
initializeBuffers();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user