com.yahoo.sketches.ArrayOfDoublesSerDe Maven / Gradle / Ivy
/*
* Copyright 2015-16, Yahoo! Inc.
* Licensed under the terms of the Apache License 2.0. See LICENSE file at the project root for terms.
*/
package com.yahoo.sketches;
import com.yahoo.memory.Memory;
import com.yahoo.memory.NativeMemory;
/**
* Methods of serializing and deserializing arrays of Double.
*
* @author Alex Saydakov
*/
public class ArrayOfDoublesSerDe extends ArrayOfItemsSerDe {
@Override
public byte[] serializeToByteArray(final Double[] items) {
final byte[] bytes = new byte[Double.BYTES * items.length];
final Memory mem = new NativeMemory(bytes);
long offsetBytes = 0;
for (int i = 0; i < items.length; i++) {
mem.putDouble(offsetBytes, items[i]);
offsetBytes += Double.BYTES;
}
return bytes;
}
@Override
public Double[] deserializeFromMemory(Memory mem, int length) {
final Double[] array = new Double[length];
long offsetBytes = 0;
for (int i = 0; i < length; i++) {
array[i] = mem.getDouble(offsetBytes);
offsetBytes += Double.BYTES;
}
return array;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy