org.mapdb.serializer.SerializerByteArrayDelta Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mapdb Show documentation
Show all versions of mapdb Show documentation
MapDB provides concurrent Maps, Sets and Queues backed by disk storage or off-heap memory. It is a fast, scalable and easy to use embedded Java database.
package org.mapdb.serializer;
import org.mapdb.DataInput2;
import org.mapdb.DataOutput2;
import java.io.IOException;
/**
* Created by jan on 2/29/16.
*/
public class SerializerByteArrayDelta extends SerializerByteArray {
//TODO PERF char[][] versus Object[]
@Override
public void valueArraySerialize(DataOutput2 out, Object vals) throws IOException {
byte[][] chars = (byte[][]) vals;
//write lengths
for(byte[] b:chars){
out.packInt(b.length);
}
//$DELAY$
//find common prefix
int prefixLen = commonPrefixLen(chars);
out.packInt(prefixLen);
out.write(chars[0], 0, prefixLen);
//$DELAY$
for(byte[] b:chars){
out.write(b,prefixLen,b.length-prefixLen);
}
}
@Override
public byte[][] valueArrayDeserialize(DataInput2 in, int size) throws IOException {
byte[][] ret = new byte[size][];
//read lengths and init arrays
for(int i=0;i