leerho commented on code in PR #447:
URL: https://github.com/apache/datasketches-java/pull/447#discussion_r1286493003
##########
src/main/java/org/apache/datasketches/common/ArrayOfLongsSerDe.java:
##########
@@ -29,28 +31,57 @@
*/
public class ArrayOfLongsSerDe extends ArrayOfItemsSerDe<Long> {
+ @Override
+ public byte[] serializeToByteArray(final Long item) {
+ final byte[] byteArr = new byte[Long.BYTES];
+ putLongLE(byteArr, 0, item.longValue());
+ return byteArr;
+ }
+
@Override
public byte[] serializeToByteArray(final Long[] items) {
final byte[] bytes = new byte[Long.BYTES * items.length];
final WritableMemory mem = WritableMemory.writableWrap(bytes);
- long offsetBytes = 0;
+ long offset = 0;
for (int i = 0; i < items.length; i++) {
- mem.putLong(offsetBytes, items[i]);
- offsetBytes += Long.BYTES;
+ mem.putLong(offset, items[i]);
+ offset += Long.BYTES;
}
return bytes;
}
@Override
- public Long[] deserializeFromMemory(final Memory mem, final int length) {
- Util.checkBounds(0, (long)length * Long.BYTES, mem.getCapacity());
- final Long[] array = new Long[length];
- long offsetBytes = 0;
- for (int i = 0; i < length; i++) {
- array[i] = mem.getLong(offsetBytes);
- offsetBytes += Long.BYTES;
+ public Long deserializeOneFromMemory(final Memory mem, final long offset) {
+ return mem.getLong(offset);
+ }
+
+ @Override
+ @Deprecated
+ public Long[] deserializeFromMemory(final Memory mem, final int numItems) {
+ return deserializeFromMemory(mem, 0, numItems);
+ }
+
+ @Override
+ public Long[] deserializeFromMemory(final Memory mem, final long
offsetBytes, final int numItems) {
+ long offset = offsetBytes;
+ Util.checkBounds(offset, Long.BYTES * numItems, mem.getCapacity());
Review Comment:
All fixed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]