Skip to content

Commit f41cbbd

Browse files
authored
Merge pull request #1 from kkoz/nested-loop-fix
Modify nested detection loop
2 parents 38fcf70 + 09638fc commit f41cbbd

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

src/main/java/com/bc/zarr/ZarrArray.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -136,30 +136,30 @@ public static ZarrArray open(ZarrPath relativePath, Store store) throws IOExcept
136136
total *= i;
137137
}
138138

139-
int attempts = 0;
140-
141139
for (int ignore = 0; ignore < total; ignore++) { // essentially a while(true) for our known maximum.
142-
int j;
143-
for (j = 0; j < n; j++) {
144-
// This n-dim loops allows to walk through all possible values for all dimensions.
145-
for (boolean test : Arrays.asList(true, false)) {
146-
attempts++;
147-
final String chunkFilename = ZarrUtils.createChunkFilename(ptr, test);
148-
final ZarrPath chunkFilePath = relativePath.resolve(chunkFilename);
149-
try (final InputStream storageStream = store.getInputStream(chunkFilePath.storeKey)) {
150-
if (storageStream != null) { // TODO: test available() ?
151-
nested = test;
152-
break;
153-
}
140+
// This n-dim loops allows to walk through all possible values for all dimensions.
141+
for (boolean test : Arrays.asList(true, false)) {
142+
final String chunkFilename = ZarrUtils.createChunkFilename(ptr, test);
143+
final ZarrPath chunkFilePath = relativePath.resolve(chunkFilename);
144+
try (final InputStream storageStream = store.getInputStream(chunkFilePath.storeKey)) {
145+
if (storageStream != null) { // TODO: test available() ?
146+
nested = test;
147+
break;
148+
}
149+
}
150+
}
151+
if (nested != null) {
152+
break;
153+
} else {
154+
for(int j = 0; j < n; j++) {
155+
ptr[j]++;
156+
if(ptr[j] < shape[j]) {
157+
break;
158+
} else {
159+
ptr[j] = 0;
154160
}
155161
}
156-
157-
// Increment and/or exit
158-
ptr[j]++;
159-
if (ptr[j] < shape[j]) break;
160-
ptr[j] = 0;
161162
}
162-
if (j == n) break;
163163
}
164164

165165
if (nested == null) {

0 commit comments

Comments
 (0)