Skip to content

Commit

Permalink
Working implicit index impl
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmudd committed Dec 8, 2024
1 parent c924d03 commit 37f4c19
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
11 changes: 11 additions & 0 deletions jhdf/src/main/java/io/jhdf/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -456,4 +456,15 @@ private static void flattenInternal(Object data, List<Object> flat) {
flat.add(data);
}
}

public static int totalChunks(int[] datasetDimensions, int[] chunkDimensions) {
int chunks = 1;
for (int i = 0; i < datasetDimensions.length; i++) {
int chunksInDim = datasetDimensions[i] / chunkDimensions[i];
// If there is a partial chunk then we need to add one chunk in this dim
if(datasetDimensions[i] % chunkDimensions[i] != 0 ) chunksInDim++;
chunks *= chunksInDim;
}
return chunks;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,40 @@
*/
package io.jhdf.dataset.chunked.indexing;

import io.jhdf.Utils;
import io.jhdf.dataset.chunked.Chunk;
import io.jhdf.dataset.chunked.DatasetInfo;
import io.jhdf.object.message.DataLayoutMessage.ChunkedDataLayoutMessageV4;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class ImplicitChunkIndex implements ChunkIndex {

private final int unfilteredChunkSize;
private final int chunkSize;
private final int[] datasetDimensions;
private final int[] chunkDimensions;
private final long baseAddress;

public ImplicitChunkIndex(long baseAddress, DatasetInfo datasetInfo) {

this.baseAddress = baseAddress;
this.unfilteredChunkSize = datasetInfo.getChunkSizeInBytes();
this.chunkSize = datasetInfo.getChunkSizeInBytes();
this.datasetDimensions = datasetInfo.getDatasetDimensions();
this.chunkDimensions = datasetInfo.getChunkDimensions();
}

@Override
public Collection<Chunk> getAllChunks() {
return Collections.emptyList();
int totalChunks = Utils.totalChunks(datasetDimensions, chunkDimensions);
List<Chunk> chunks = new ArrayList<>(totalChunks);
for (int i = 0; i < totalChunks; i++) {
chunks.add(new ChunkImpl(baseAddress + i* chunkSize,
chunkSize,
Utils.chunkIndexToChunkOffset(i, chunkDimensions, datasetDimensions)));
}
return chunks;
}

}

0 comments on commit 37f4c19

Please sign in to comment.