Skip to content

Commit 6079e1b

Browse files
bogovicjtpietzsch
authored andcommitted
fix: remove writeRegion default implementations
1 parent bae5c24 commit 6079e1b

1 file changed

Lines changed: 9 additions & 53 deletions

File tree

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

Lines changed: 9 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@
3939
import java.util.Map;
4040
import java.util.concurrent.ExecutionException;
4141
import java.util.concurrent.ExecutorService;
42-
import org.janelia.saalfeldlab.n5.shard.Nesting.NestedGrid;
43-
import org.janelia.saalfeldlab.n5.shard.Nesting.NestedPosition;
44-
import org.janelia.saalfeldlab.n5.shard.Region;
4542

4643
/**
4744
* A simple structured container API for hierarchies of chunked
@@ -320,33 +317,13 @@ interface DataBlockSupplier<T> {
320317
* @param writeFully if false, merge existing data in shards/blocks that overlap the region boundary. if true, override everything.
321318
* @throws N5Exception the exception
322319
*/
323-
default <T> void writeRegion(
324-
String datasetPath,
325-
DatasetAttributes datasetAttributes,
326-
long[] min,
327-
long[] size,
328-
DataBlockSupplier<T> dataBlocks,
329-
boolean writeFully) throws N5Exception {
330-
331-
final NestedGrid grid = datasetAttributes.getNestedBlockGrid();
332-
final Region region = new Region(min, size, grid);
333-
for (long[] key : Region.gridPositions(region.minPos().key(), region.maxPos().key())) {
334-
final NestedPosition pos = grid.nestedPosition(key, grid.numLevels() - 1);
335-
final long[] gridPosition = pos.absolute(0);
336-
final DataBlock<T> existingDataBlock = writeFully || region.fullyContains(pos)
337-
? null
338-
: readBlock(datasetPath, datasetAttributes, gridPosition);
339-
final DataBlock<T> dataBlock = dataBlocks.get(gridPosition, existingDataBlock);
340-
// null blocks may be provided when they contain only the fill value
341-
// and only non-empty blocks should be written, for example
342-
if (dataBlock == null) {
343-
deleteBlock(datasetPath, datasetAttributes, gridPosition);
344-
} else {
345-
writeBlock(datasetPath, datasetAttributes, dataBlock);
346-
}
347-
}
348-
349-
}
320+
<T> void writeRegion(
321+
final String datasetPath,
322+
final DatasetAttributes datasetAttributes,
323+
final long[] min,
324+
final long[] size,
325+
final DataBlockSupplier<T> dataBlocks,
326+
final boolean writeFully) throws N5Exception;
350327

351328
/**
352329
* @param datasetPath the dataset path
@@ -358,35 +335,14 @@ default <T> void writeRegion(
358335
* @param exec used to parallelize over blocks and shards
359336
* @throws N5Exception the exception
360337
*/
361-
default <T> void writeRegion(
338+
<T> void writeRegion(
362339
String datasetPath,
363340
DatasetAttributes datasetAttributes,
364341
long[] min,
365342
long[] size,
366343
DataBlockSupplier<T> dataBlocks,
367344
boolean writeFully,
368-
ExecutorService exec) throws N5Exception, InterruptedException, ExecutionException {
369-
370-
final NestedGrid grid = datasetAttributes.getNestedBlockGrid();
371-
final Region region = new Region(min, size, grid);
372-
for (long[] key : Region.gridPositions(region.minPos().key(), region.maxPos().key())) {
373-
exec.submit(() -> {
374-
final NestedPosition pos = grid.nestedPosition(key, grid.numLevels() - 1);
375-
final long[] gridPosition = pos.absolute(0);
376-
final DataBlock<T> existingDataBlock = writeFully || region.fullyContains(pos)
377-
? null
378-
: readBlock(datasetPath, datasetAttributes, gridPosition);
379-
final DataBlock<T> dataBlock = dataBlocks.get(gridPosition, existingDataBlock);
380-
// null blocks may be provided when they contain only the fill value
381-
// and only non-empty blocks should be written, for example
382-
if (dataBlock == null) {
383-
deleteBlock(datasetPath, datasetAttributes, gridPosition);
384-
} else {
385-
writeBlock(datasetPath, datasetAttributes, dataBlock);
386-
}
387-
});
388-
}
389-
}
345+
ExecutorService exec) throws N5Exception, InterruptedException, ExecutionException;
390346

391347
/**
392348
* Deletes the block at {@code gridPosition}.

0 commit comments

Comments
 (0)