All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.mapdb.serializer.SerializerByteArrayDelta Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 3.1.0
Show newest version
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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy