Skip to content

Commit

Permalink
Merge pull request #14 from mtth/master
Browse files Browse the repository at this point in the history
Share slot read buffers
  • Loading branch information
mbastian committed Nov 18, 2015
2 parents 76acab1 + 652afc3 commit 22eb677
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions paldb/src/main/java/com/linkedin/paldb/impl/StorageReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public class StorageReader implements Iterable<Map.Entry<byte[], byte[]>> {
private final boolean mMapData;
// Buffers
private final DataInputOutput sizeBuffer = new DataInputOutput(new byte[5]);
private final byte[][] slotBuffers;
private final byte[] slotBuffer;

StorageReader(Configuration configuration, File file)
throws IOException {
Expand Down Expand Up @@ -148,20 +148,22 @@ public class StorageReader implements Iterable<Map.Entry<byte[], byte[]>> {
keyCounts = new int[maxKeyLength + 1];
slots = new int[maxKeyLength + 1];
slotSizes = new int[maxKeyLength + 1];
slotBuffers = new byte[maxKeyLength + 1][];

int maxSlotSize = 0;
for (int i = 0; i < keyLengthCount; i++) {
int keyLength = dataInputStream.readInt();

keyCounts[keyLength] = dataInputStream.readInt();
slots[keyLength] = dataInputStream.readInt();
slotSizes[keyLength] = dataInputStream.readInt();
slotBuffers[keyLength] = new byte[slotSizes[keyLength]];

indexOffsets[keyLength] = dataInputStream.readInt();

dataOffsets[keyLength] = dataInputStream.readLong();

maxSlotSize = Math.max(maxSlotSize, slotSizes[keyLength]);
}

slotBuffer = new byte[maxSlotSize];

//Read serializers
try {
Serializers.deserialize(dataInputStream, config.getSerializers());
Expand Down Expand Up @@ -238,15 +240,14 @@ public byte[] get(byte[] key)
}
long hash = (long) HashUtils.hash(key);
int numSlots = slots[keyLength];
byte[] slotBuffer = slotBuffers[keyLength];
int slotSize = slotBuffer.length;
int slotSize = slotSizes[keyLength];
int indexOffset = indexOffsets[keyLength];
long dataOffset = dataOffsets[keyLength];

for (int probe = 0; probe < numSlots; probe++) {
int slot = (int) ((hash + probe) % numSlots);
indexBuffer.position(indexOffset + slot * slotSize);
indexBuffer.get(slotBuffer);
indexBuffer.get(slotBuffer, 0, slotSize);

long offset = LongPacker.unpackLong(slotBuffer, keyLength);
if (offset == 0) {
Expand Down

0 comments on commit 22eb677

Please sign in to comment.