@Override public Batch deserialize(DataInput in, int available) throws IOException { final int length = Varint.readUnsignedVarInt(in); long[] nodeIds = new long[length + 1]; int[] xordinates = new int[length + 1]; int[] yordinates = new int[length + 1]; Varints.readLongArrayDeltaEncoded(in, nodeIds, 0, length); Varints.readIntArrayDeltaEncoded(in, xordinates, 0, length); Varints.readIntArrayDeltaEncoded(in, yordinates, 0, length); Batch batch = new Batch(length, nodeIds, xordinates, yordinates); return batch; } };
public static long[] readSignedLongArray(DataInput in) throws IOException { final int length = readLength(in); long[] values = new long[length]; for (int i = 0; i < length; i++) { values[i] = readSignedVarLong(in); } return values; }
@Override public void serialize(DataOutput out, Batch value) throws IOException { final int length = value.length; final long[] nodeIds = value.nodeIds; final int[] xordinates = value.xordinates; final int[] yordinates = value.yordinates; Varint.writeUnsignedVarInt(length, out); Varints.writeLongArrayDeltaEncoded(out, nodeIds, 0, length); Varints.writeIntArrayDeltaEncoded(out, xordinates, 0, length); Varints.writeIntArrayDeltaEncoded(out, yordinates, 0, length); }
public static void writeSignedIntArray(int[] values, DataOutput out) throws IOException { final int length = values.length; writeLength(values, out); for (int i = 0; i < length; i++) { writeSignedVarInt(values[i], out); } }
CoordinateSequence parseBoundsCoordinates() { final int boundsSectionSize = header.boundsSize; if (0 == boundsSectionSize) { return FloatPackedCoordinateSequence.EMPTY_2D; } final int boundsOffset = header.boundsOffset(); DataInput in = data.asDataInput(boundsOffset); int[] x; int[] y; try { x = Varints.readSignedIntArray(in); y = Varints.readSignedIntArray(in); } catch (IOException e) { throw Throwables.propagate(e); } int[][] coords = new int[][] { x, y }; return new FloatPackedCoordinateSequence(coords); }
int[] xordinates = allOrdinates[0]; int[] yordinates = allOrdinates[1]; Varints.writeSignedIntArray(xordinates, boundsStream); Varints.writeSignedIntArray(yordinates, boundsStream); final int coordsSectionSzie = boundsStream.size();
public static void writeUnignedIntArray(int[] values, DataOutput out) throws IOException { final int length = values.length; writeLength(values, out); for (int i = 0; i < length; i++) { writeUnsignedVarInt(values[i], out); } }
CoordinateSequence parseBoundsCoordinates() { final int boundsSectionSize = header.boundsSize; if (0 == boundsSectionSize) { return FloatPackedCoordinateSequence.EMPTY_2D; } final int boundsOffset = header.boundsOffset(); DataInput in = data.asDataInput(boundsOffset); int[] x; int[] y; try { x = Varints.readSignedIntArray(in); y = Varints.readSignedIntArray(in); } catch (IOException e) { throw new RuntimeException(e); } int[][] coords = new int[][] { x, y }; return new FloatPackedCoordinateSequence(coords); }
int[] xordinates = allOrdinates[0]; int[] yordinates = allOrdinates[1]; Varints.writeSignedIntArray(xordinates, boundsStream); Varints.writeSignedIntArray(yordinates, boundsStream); final int coordsSectionSzie = boundsStream.size();
public static void writeIntArrayDeltaEncoded(int[] values, DataOutput out) throws IOException { final int length = values.length; writeLength(values, out); int prev = 0; for (int i = 0; i < length; i++) { int value = values[i]; int delta = value - prev; prev = value; writeSignedVarInt(delta, out); } }
public static int[] readUnsignedIntArray(DataInput in, AtomicInteger outBytesRead) throws IOException { final int length = readLength(in); int[] values = new int[length]; for (int i = 0; i < length; i++) { values[i] = readUnsignedVarInt(in); } return values; }
public static void writeLongArrayDeltaEncoded(long[] values, DataOutput out) throws IOException { final int length = writeLength(values, out); long prev = 0; for (int i = 0; i < length; i++) { long value = values[i]; long delta = value - prev; prev = value; writeSignedVarLong(delta, out); } }
public static int[] readIntArrayDeltaEncoded(DataInput in) throws IOException { final int length = readLength(in); int[] values = new int[length]; int prev = 0; for (int i = 0; i < length; i++) { int delta = readSignedVarInt(in); int value = prev + delta; values[i] = value; prev = value; } return values; }
public static void writeSignedLongArray(long[] values, DataOutput out) throws IOException { final int length = writeLength(values, out); for (int i = 0; i < length; i++) { writeSignedVarLong(values[i], out); } }
public static int[] readIntArrayDeltaEncoded(DataInput in) throws IOException { final int length = readLength(in); int[] values = new int[length]; int prev = 0; for (int i = 0; i < length; i++) { int delta = readSignedVarInt(in); int value = prev + delta; values[i] = value; prev = value; } return values; }
public static void writeIntArrayDeltaEncoded(int[] values, DataOutput out) throws IOException { final int length = values.length; writeLength(values, out); int prev = 0; for (int i = 0; i < length; i++) { int value = values[i]; int delta = value - prev; prev = value; writeSignedVarInt(delta, out); } }
public static int[] readSignedIntArray(DataInput in) throws IOException { final int length = readLength(in); int[] values = new int[length]; for (int i = 0; i < length; i++) { values[i] = readSignedVarInt(in); } return values; }
public static void writeSignedIntArray(int[] values, DataOutput out) throws IOException { final int length = values.length; writeLength(values, out); for (int i = 0; i < length; i++) { writeSignedVarInt(values[i], out); } }
public static long[] readUnsignedLongArray(DataInput in) throws IOException { final int length = readLength(in); long[] values = new long[length]; for (int i = 0; i < length; i++) { values[i] = readUnsignedVarLong(in); } return values; }
public static void writeLongArrayDeltaEncoded(long[] values, DataOutput out) throws IOException { final int length = writeLength(values, out); long prev = 0; for (int i = 0; i < length; i++) { long value = values[i]; long delta = value - prev; prev = value; writeSignedVarLong(delta, out); } }