Skip to content

Commit 8dec89a

Browse files
committed
Make SliceTrackingLazyRead non-abstract
It doesn't do any prefetching, just keeps track of what has been materialized (and uses that to avoid materializing slices that are already fully covered).
1 parent 03e9669 commit 8dec89a

2 files changed

Lines changed: 11 additions & 40 deletions

File tree

src/main/java/org/janelia/saalfeldlab/n5/readdata/prefetch/DefaultSliceTrackingLazyRead.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,4 @@ public void prefetch(final Collection<? extends Range> ranges) throws N5IOExcept
4242
materialize(fromIndex, toIndex - fromIndex);
4343
}
4444
}
45-
46-
private boolean isCovered(final Range slice) {
47-
48-
return Slices.findContainingSlice(slices, slice) != null;
49-
}
5045
}

src/main/java/org/janelia/saalfeldlab/n5/readdata/prefetch/SliceTrackingLazyRead.java

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,22 @@
22

33
import java.io.IOException;
44
import java.util.ArrayList;
5-
import java.util.Collection;
65
import java.util.List;
76
import org.janelia.saalfeldlab.n5.N5Exception.N5IOException;
87
import org.janelia.saalfeldlab.n5.readdata.LazyRead;
98
import org.janelia.saalfeldlab.n5.readdata.Range;
109
import org.janelia.saalfeldlab.n5.readdata.ReadData;
1110

12-
public abstract class SliceTrackingLazyRead implements LazyRead {
11+
/**
12+
* A {@link LazyRead} that wraps a delegate {@code LazyRead} and keeps track of
13+
* all slices that have been {@link #materialize materialized}.
14+
* <p>
15+
* When materializing a new slice, we first check whether it is completely
16+
* covered by a materialized slice that we already track. If so, then we just
17+
* return a slice on the existing materialized slice. If not, we materialize the
18+
* slice from the delegate track it.
19+
*/
20+
public class SliceTrackingLazyRead implements LazyRead {
1321

1422
protected static class Slice implements Range {
1523

@@ -75,39 +83,7 @@ public long size() throws N5IOException {
7583
return delegate.size();
7684
}
7785

78-
/**
79-
* Indicates that the given slices will be subsequently read.
80-
* {@code LazyRead} implementations (optionally) may take steps to prepare
81-
* for these subsequent slices.
82-
* <p>
83-
* Minimal implementation: Find offset and length covering all ranges that
84-
* are not yet fully covered by existing slices. Then materialize the slice
85-
* covering that range.
86-
*
87-
* @param ranges
88-
* slice ranges to prefetch
89-
*
90-
* @throws N5IOException
91-
* if any I/O error occurs
92-
*/
93-
@Override
94-
public void prefetch(final Collection<? extends Range> ranges) throws N5IOException {
95-
96-
long fromIndex = Long.MAX_VALUE;
97-
long toIndex = Long.MIN_VALUE;
98-
for (final Range slice : ranges) {
99-
if (!isCovered(slice)) {
100-
fromIndex = Math.min(fromIndex, slice.offset());
101-
toIndex = Math.max(toIndex, slice.end());
102-
}
103-
}
104-
105-
if (fromIndex < toIndex) {
106-
materialize(fromIndex, toIndex - fromIndex);
107-
}
108-
}
109-
110-
private boolean isCovered(final Range slice) {
86+
protected boolean isCovered(final Range slice) {
11187

11288
return Slices.findContainingSlice(slices, slice) != null;
11389
}

0 commit comments

Comments
 (0)