Skip to content

Commit

Permalink
DirectIOIndexInput - add overloads for bulk retrieval (#14124)
Browse files Browse the repository at this point in the history
This commit adds overloads for bulk retrieval to DirectIOIndexInput. The implementation of these methods is identical to that of BufferedIndexInput, and it already covered by existing tests.
  • Loading branch information
ChrisHegarty committed Jan 9, 2025
1 parent 21ba3f8 commit 18c187b
Showing 1 changed file with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,63 @@ public void readBytes(byte[] dst, int offset, int len) throws IOException {
}
}

@Override
public void readInts(int[] dst, int offset, int len) throws IOException {
int remainingDst = len;
while (remainingDst > 0) {
int cnt = Math.min(buffer.remaining() / Integer.BYTES, remainingDst);
buffer.asIntBuffer().get(dst, offset + len - remainingDst, cnt);
buffer.position(buffer.position() + Integer.BYTES * cnt);
remainingDst -= cnt;
if (remainingDst > 0) {
if (buffer.hasRemaining()) {
dst[offset + len - remainingDst] = readInt();
--remainingDst;
} else {
refill(remainingDst * Integer.BYTES);
}
}
}
}

@Override
public void readFloats(float[] dst, int offset, int len) throws IOException {
int remainingDst = len;
while (remainingDst > 0) {
int cnt = Math.min(buffer.remaining() / Float.BYTES, remainingDst);
buffer.asFloatBuffer().get(dst, offset + len - remainingDst, cnt);
buffer.position(buffer.position() + Float.BYTES * cnt);
remainingDst -= cnt;
if (remainingDst > 0) {
if (buffer.hasRemaining()) {
dst[offset + len - remainingDst] = Float.intBitsToFloat(readInt());
--remainingDst;
} else {
refill(remainingDst * Float.BYTES);
}
}
}
}

@Override
public void readLongs(long[] dst, int offset, int len) throws IOException {
int remainingDst = len;
while (remainingDst > 0) {
int cnt = Math.min(buffer.remaining() / Long.BYTES, remainingDst);
buffer.asLongBuffer().get(dst, offset + len - remainingDst, cnt);
buffer.position(buffer.position() + Long.BYTES * cnt);
remainingDst -= cnt;
if (remainingDst > 0) {
if (buffer.hasRemaining()) {
dst[offset + len - remainingDst] = readLong();
--remainingDst;
} else {
refill(remainingDst * Long.BYTES);
}
}
}
}

@Override
public DirectIOIndexInput clone() {
try {
Expand Down

0 comments on commit 18c187b

Please sign in to comment.