Skip to content

Commit

Permalink
Start considering paging
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmudd committed Sep 14, 2024
1 parent a1b0de7 commit 4832dca
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.jhdf.exceptions.HdfException;
import io.jhdf.storage.HdfBackingStorage;

import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
Expand All @@ -40,7 +41,8 @@ public class FixedArrayIndex implements ChunkIndex {
private final int pageBits;
private final int maxNumberOfEntries;
private final long dataBlockAddress;

private final boolean paged;
private final int pages;
private final List<Chunk> chunks;

public FixedArrayIndex(HdfBackingStorage hdfBackingStorage, long address, DatasetInfo datasetInfo) {
Expand Down Expand Up @@ -71,6 +73,10 @@ public FixedArrayIndex(HdfBackingStorage hdfBackingStorage, long address, Datase
pageBits = bb.get();

maxNumberOfEntries = Utils.readBytesAsUnsignedInt(bb, hdfBackingStorage.getSizeOfLengths());
final int pageSize = BigInteger.valueOf(2).pow(pageBits).intValue();
paged = maxNumberOfEntries > pageSize;
pages = (int) Math.ceil((double) maxNumberOfEntries / pageSize);

dataBlockAddress = Utils.readBytesAsUnsignedLong(bb, hdfBackingStorage.getSizeOfOffsets());

chunks = new ArrayList<>(maxNumberOfEntries);
Expand All @@ -79,11 +85,11 @@ public FixedArrayIndex(HdfBackingStorage hdfBackingStorage, long address, Datase
bb.rewind();
ChecksumUtils.validateChecksum(bb);

// Building the object fills the chunks. Probably shoudld be changed
// Building the object fills the chunks. Probably should be changed
new FixedArrayDataBlock(this, hdfBackingStorage, dataBlockAddress);
}

private static class FixedArrayDataBlock {
private class FixedArrayDataBlock {

private FixedArrayDataBlock(FixedArrayIndex fixedArrayIndex, HdfBackingStorage hdfBackingStorage, long address) {

Expand Down Expand Up @@ -115,6 +121,14 @@ private FixedArrayDataBlock(FixedArrayIndex fixedArrayIndex, HdfBackingStorage h
throw new HdfException("Fixed array data block header address missmatch");
}

if(paged) {
// throw new HdfException("Paged");
// pageBits
int pageBitmapBytes = (int) Math.ceil((double) pages / 8);
// byte[] pageBitmap = new byte[pageBitmapBytes];
// bb.get(pageBitmapBytes);
bb.position(bb.position() + pageBitmapBytes + 1);
}
// TODO ignoring paging here might need to revisit

if (clientId == 0) { // Not filtered
Expand Down

0 comments on commit 4832dca

Please sign in to comment.