Skip to content

Commit 7b06bdb

Browse files
committed
refactor!: block -> chunk, shard -> block
1 parent bae5c24 commit 7b06bdb

19 files changed

Lines changed: 285 additions & 285 deletions

src/main/java/org/janelia/saalfeldlab/n5/GsonKeyValueN5Reader.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ default JsonElement getAttributes(final String pathName) throws N5Exception {
9494
}
9595

9696
@Override
97-
default <T> DataBlock<T> readBlock(
97+
default <T> DataBlock<T> readChunk(
9898
final String pathName,
9999
final DatasetAttributes datasetAttributes,
100100
final long... gridPosition) throws N5Exception {
@@ -103,26 +103,26 @@ default <T> DataBlock<T> readBlock(
103103
try {
104104
final PositionValueAccess posKva = PositionValueAccess.fromKva(getKeyValueAccess(), getURI(), N5URI.normalizeGroupPath(pathName),
105105
convertedDatasetAttributes);
106-
return convertedDatasetAttributes.<T> getDatasetAccess().readBlock(posKva, gridPosition);
106+
return convertedDatasetAttributes.<T> getDatasetAccess().readChunk(posKva, gridPosition);
107107

108108
} catch (N5Exception.N5NoSuchKeyException e) {
109109
return null;
110110
}
111111
}
112112

113113
@Override
114-
default <T> List<DataBlock<T>> readBlocks(
114+
default <T> List<DataBlock<T>> readChunks(
115115
final String pathName,
116116
final DatasetAttributes datasetAttributes,
117117
final List<long[]> blockPositions) throws N5Exception {
118118

119119
DatasetAttributes convertedDatasetAttributes = getConvertedDatasetAttributes(datasetAttributes);
120120
final PositionValueAccess posKva = PositionValueAccess.fromKva(getKeyValueAccess(), getURI(), N5URI.normalizeGroupPath(pathName), convertedDatasetAttributes);
121-
return convertedDatasetAttributes.<T> getDatasetAccess().readBlocks(posKva, blockPositions);
121+
return convertedDatasetAttributes.<T> getDatasetAccess().readChunks(posKva, blockPositions);
122122
}
123123

124124
@Override
125-
default <T> DataBlock<T> readShard(
125+
default <T> DataBlock<T> readBlock(
126126
final String pathName,
127127
final DatasetAttributes datasetAttributes,
128128
final long... gridPosition) throws N5Exception {
@@ -132,7 +132,7 @@ default <T> DataBlock<T> readShard(
132132
try {
133133
final PositionValueAccess posKva = PositionValueAccess.fromKva(getKeyValueAccess(), getURI(), N5URI.normalizeGroupPath(pathName),
134134
convertedDatasetAttributes);
135-
return convertedDatasetAttributes.<T> getDatasetAccess().readShard(posKva, gridPosition, shardLevel);
135+
return convertedDatasetAttributes.<T> getDatasetAccess().readBlock(posKva, gridPosition, shardLevel);
136136

137137
} catch (N5Exception.N5NoSuchKeyException e) {
138138
return null;
@@ -172,7 +172,7 @@ default String absoluteAttributesPath(final String normalPath) {
172172
}
173173

174174
@Override
175-
default boolean shardExists(
175+
default boolean blockExists(
176176
final String pathName,
177177
final DatasetAttributes datasetAttributes,
178178
final long... gridPosition) throws N5Exception {

src/main/java/org/janelia/saalfeldlab/n5/GsonKeyValueN5Writer.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -257,52 +257,52 @@ default <T> void writeRegion(
257257
}
258258

259259
@Override
260-
default <T> void writeBlocks(
260+
default <T> void writeChunks(
261261
final String datasetPath,
262262
final DatasetAttributes datasetAttributes,
263263
final DataBlock<T>... dataBlocks) throws N5Exception {
264264

265265
DatasetAttributes convertedDatasetAttributes = getConvertedDatasetAttributes(datasetAttributes);
266266
try {
267267
final PositionValueAccess posKva = PositionValueAccess.fromKva(getKeyValueAccess(), getURI(), N5URI.normalizeGroupPath(datasetPath), convertedDatasetAttributes);
268-
convertedDatasetAttributes.<T>getDatasetAccess().writeBlocks(posKva, Arrays.asList(dataBlocks));
268+
convertedDatasetAttributes.<T>getDatasetAccess().writeChunks(posKva, Arrays.asList(dataBlocks));
269269
} catch (final UncheckedIOException e) {
270270
throw new N5IOException(
271-
"Failed to write blocks into dataset " + datasetPath, e);
271+
"Failed to write chunks into dataset " + datasetPath, e);
272272
}
273273
}
274274

275275
@Override
276-
default <T> void writeBlock(
276+
default <T> void writeChunk(
277277
final String path,
278278
final DatasetAttributes datasetAttributes,
279279
final DataBlock<T> dataBlock) throws N5Exception {
280280

281281
DatasetAttributes convertedDatasetAttributes = getConvertedDatasetAttributes(datasetAttributes);
282282
try {
283283
final PositionValueAccess posKva = PositionValueAccess.fromKva(getKeyValueAccess(), getURI(), N5URI.normalizeGroupPath(path), convertedDatasetAttributes);
284-
convertedDatasetAttributes.<T> getDatasetAccess().writeBlock(posKva, dataBlock);
284+
convertedDatasetAttributes.<T> getDatasetAccess().writeChunk(posKva, dataBlock);
285285
} catch (final UncheckedIOException e) {
286286
throw new N5IOException(
287-
"Failed to write block " + Arrays.toString(dataBlock.getGridPosition()) + " into dataset " + path,
287+
"Failed to write chunk " + Arrays.toString(dataBlock.getGridPosition()) + " into dataset " + path,
288288
e);
289289
}
290290
}
291291

292292
@Override
293-
default <T> void writeShard(
293+
default <T> void writeBlock(
294294
final String path,
295295
final DatasetAttributes datasetAttributes,
296-
final DataBlock<T> shard) throws N5Exception {
296+
final DataBlock<T> dataBlock) throws N5Exception {
297297

298298
final DatasetAttributes convertedDatasetAttributes = getConvertedDatasetAttributes(datasetAttributes);
299299
final int shardLevel = convertedDatasetAttributes.getNestedBlockGrid().numLevels() - 1;
300300
try {
301301
final PositionValueAccess posKva = PositionValueAccess.fromKva(getKeyValueAccess(), getURI(), N5URI.normalizeGroupPath(path), convertedDatasetAttributes);
302-
convertedDatasetAttributes.<T> getDatasetAccess().writeShard(posKva, shard, shardLevel);
302+
convertedDatasetAttributes.<T> getDatasetAccess().writeBlock(posKva, dataBlock, shardLevel);
303303
} catch (final UncheckedIOException e) {
304304
throw new N5IOException(
305-
"Failed to write block " + Arrays.toString(shard.getGridPosition()) + " into dataset " + path,
305+
"Failed to write block " + Arrays.toString(dataBlock.getGridPosition()) + " into dataset " + path,
306306
e);
307307
}
308308
}
@@ -320,22 +320,22 @@ default boolean remove(final String path) throws N5Exception {
320320
}
321321

322322
@Override
323-
default boolean deleteBlock(
323+
default boolean deleteChunk(
324324
final String path,
325325
final DatasetAttributes datasetAttributes,
326326
final long... gridPosition) throws N5Exception {
327327

328328
final PositionValueAccess posKva = PositionValueAccess.fromKva(getKeyValueAccess(), getURI(), N5URI.normalizeGroupPath(path), datasetAttributes);
329-
return datasetAttributes.getDatasetAccess().deleteBlock(posKva, gridPosition);
329+
return datasetAttributes.getDatasetAccess().deleteChunk(posKva, gridPosition);
330330
}
331331

332332
@Override
333-
default boolean deleteBlocks(
333+
default boolean deleteChunks(
334334
final String path,
335335
final DatasetAttributes datasetAttributes,
336336
final List<long[]> gridPositions) throws N5Exception {
337337

338338
final PositionValueAccess posKva = PositionValueAccess.fromKva(getKeyValueAccess(), getURI(), N5URI.normalizeGroupPath(path), datasetAttributes);
339-
return datasetAttributes.getDatasetAccess().deleteBlocks(posKva, gridPositions);
339+
return datasetAttributes.getDatasetAccess().deleteChunks(posKva, gridPositions);
340340
}
341341
}

src/main/java/org/janelia/saalfeldlab/n5/N5Reader.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ default DatasetAttributes getConvertedDatasetAttributes(final DatasetAttributes
298298

299299

300300
/**
301-
* Reads a {@link DataBlock}.
301+
* Reads a chunk as a {@link DataBlock}.
302302
*
303303
* @param <T>
304304
* the DataBlock data type
@@ -312,13 +312,13 @@ default DatasetAttributes getConvertedDatasetAttributes(final DatasetAttributes
312312
* @throws N5Exception
313313
* the exception
314314
*/
315-
<T> DataBlock<T> readBlock(
315+
<T> DataBlock<T> readChunk(
316316
final String pathName,
317317
final DatasetAttributes datasetAttributes,
318318
final long... gridPosition) throws N5Exception;
319319

320320
/**
321-
* Reads multiple {@link DataBlock}s.
321+
* Reads multiple chunks as {@link DataBlock}s.
322322
* <p>
323323
* Implementations may optimize / batch read operations when possible, e.g.
324324
* in the case that the datasets are sharded.
@@ -335,24 +335,24 @@ <T> DataBlock<T> readBlock(
335335
* @throws N5Exception
336336
* the exception
337337
*/
338-
default <T> List<DataBlock<T>> readBlocks(
338+
default <T> List<DataBlock<T>> readChunks(
339339
final String pathName,
340340
final DatasetAttributes datasetAttributes,
341341
final List<long[]> gridPositions) throws N5Exception {
342342

343343
DatasetAttributes convertedDatasetAttributes = getConvertedDatasetAttributes(datasetAttributes);
344344
final ArrayList<DataBlock<T>> blocks = new ArrayList<>();
345345
for( final long[] p : gridPositions )
346-
blocks.add(readBlock(pathName, convertedDatasetAttributes, p));
346+
blocks.add(readChunk(pathName, convertedDatasetAttributes, p));
347347

348348
return blocks;
349349
}
350350

351351
/**
352-
* Reads a shard as a {@link DataBlock}.
352+
* Reads a block, returning a {@link DataBlock}. Will be a chunk or shard (if the dataset is sharded).
353353
* <p>
354-
* A "shard" is the largest level of the datasets {@link org.janelia.saalfeldlab.n5.shard.Nesting.NestedGrid}
355-
* This method's behavior is identical to readBlock for un-sharded datasets.
354+
* A block is the highest (coarsest) level of the dataset's {@link org.janelia.saalfeldlab.n5.shard.Nesting.NestedGrid}
355+
* This method's behavior is identical to {@link #readChunk} for un-sharded datasets.
356356
*
357357
* @param <T>
358358
* the DataBlock data type
@@ -361,39 +361,40 @@ default <T> List<DataBlock<T>> readBlocks(
361361
* @param datasetAttributes
362362
* the dataset attributes
363363
* @param gridPosition
364-
* the position in the shard grid
364+
* the position in the block grid
365365
* @return the data block
366366
* @throws N5Exception
367367
* the exception
368368
*
369369
* @see DatasetAttributes#getNestedBlockGrid()
370370
*/
371-
<T> DataBlock<T> readShard(
371+
<T> DataBlock<T> readBlock(
372372
final String pathName,
373373
final DatasetAttributes datasetAttributes,
374374
final long... gridPosition) throws N5Exception;
375375

376376
/**
377-
* Checks if a shard (or block for non-sharded datasets) exists at the
378-
* given grid position without reading the data.
377+
* Checks if a block exists at the given grid position without reading the data.
379378
* <p>
380379
* This method only checks for the presence of the key value for the gridPosition, it does not
381-
* read or validate the contents.
380+
* read or validate the contents. As a result, this method refers to chunks in un-sharded datasets
381+
* or shards in sharded datasets.
382382
*
383383
* @param pathName
384384
* dataset path
385385
* @param datasetAttributes
386386
* the dataset attributes
387387
* @param gridPosition
388-
* the shard grid position (or block position for non-sharded datasets)
389-
* @return true if the shard (or block) file exists
388+
* the block grid position
389+
* @return true if the block file exists
390390
* @throws N5Exception
391391
* the exception
392392
*/
393-
boolean shardExists(
393+
boolean blockExists(
394394
final String pathName,
395395
final DatasetAttributes datasetAttributes,
396396
final long... gridPosition) throws N5Exception;
397+
397398
/**
398399
* Load a {@link DataBlock} as a {@link Serializable}. The offset is given
399400
* in
@@ -419,7 +420,7 @@ default <T> T readSerializedBlock(
419420
final long... gridPosition) throws N5Exception, ClassNotFoundException {
420421

421422
DatasetAttributes convertedDatasetAttributes = getConvertedDatasetAttributes(attributes);
422-
final DataBlock<byte[]> block = readBlock(dataset, convertedDatasetAttributes, gridPosition);
423+
final DataBlock<byte[]> block = readChunk(dataset, convertedDatasetAttributes, gridPosition);
423424
if (block == null)
424425
return null;
425426

0 commit comments

Comments
 (0)