org.mapdb.BTreeKeySerializer 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;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.io.Serializable;
import java.nio.charset.Charset;
import java.util.Comparator;
/**
* Custom serializer for BTreeMap keys which enables [Delta encoding](https://en.wikipedia.org/wiki/Delta_encoding).
*
* Keys in BTree Nodes are sorted, this enables number of tricks to save disk space.
* For example for numbers we may store only difference between subsequent numbers, for string we can only take suffix, etc...
*
* @param type of key
*/
public abstract class BTreeKeySerializer{
/**
* Serialize keys from single BTree Node.
*
* @param out output stream where to put ata
* @param start where data start in array. Before this index all keys are null
* @param end where data ends in array (exclusive). From this index all keys are null
* @param keys array of keys for single BTree Node
*
* @throws IOException
*/
public abstract void serialize(DataOutput out, int start, int end, Object[] keys) throws IOException;
/**
* Deserializes keys for single BTree Node. To
*
* @param in input stream to read data from
* @param start where data start in array. Before this index all keys are null
* @param end where data ends in array (exclusive). From this index all keys are null
* @param size size of array which should be returned
* @return array of keys for single BTree Node
*
* @throws IOException
*/
public abstract Object[] deserialize(DataInput in, int start, int end, int size) throws IOException;
/**
* Some key serializers may only work with they own comparators.
* For example delta-packing stores increments between numbers and requires ascending order.
* So Key Serializer may provide its own comparator.
*
* @return comparator which must be used with this method. `null` if comparator is not strictly required.
*/
public abstract Comparator getComparator();
public static final BTreeKeySerializer BASIC = new BTreeKeySerializer.BasicKeySerializer(Serializer.BASIC);
/**
* Basic Key Serializer which just writes data without applying any compression.
* Is used by default if no other Key Serializer is specified.
*/
public static final class BasicKeySerializer extends BTreeKeySerializer