org.mapdb
Class BTreeKeySerializer<K>

java.lang.Object
  extended by org.mapdb.BTreeKeySerializer<K>
Type Parameters:
K - type of key
Direct Known Subclasses:
BTreeKeySerializer.BasicKeySerializer, BTreeKeySerializer.Tuple2KeySerializer, BTreeKeySerializer.Tuple3KeySerializer, BTreeKeySerializer.Tuple4KeySerializer, BTreeKeySerializer.Tuple5KeySerializer, BTreeKeySerializer.Tuple6KeySerializer

public abstract class BTreeKeySerializer<K>
extends Object

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...


Nested Class Summary
static class BTreeKeySerializer.BasicKeySerializer
          Basic Key Serializer which just writes data without applying any compression.
static class BTreeKeySerializer.Tuple2KeySerializer<A,B>
          Applies delta compression on array of tuple.
static class BTreeKeySerializer.Tuple3KeySerializer<A,B,C>
          Applies delta compression on array of tuple.
static class BTreeKeySerializer.Tuple4KeySerializer<A,B,C,D>
          Applies delta compression on array of tuple.
static class BTreeKeySerializer.Tuple5KeySerializer<A,B,C,D,E>
          Applies delta compression on array of tuple.
static class BTreeKeySerializer.Tuple6KeySerializer<A,B,C,D,E,F>
          Applies delta compression on array of tuple.
 
Field Summary
static BTreeKeySerializer BASIC
           
static BTreeKeySerializer<String> STRING
          Applies delta packing on java.lang.String.
static BTreeKeySerializer.Tuple2KeySerializer TUPLE2
          Tuple2 Serializer which uses Default Serializer from DB and expect values to implement Comparable interface.
static BTreeKeySerializer.Tuple3KeySerializer TUPLE3
          Tuple3 Serializer which uses Default Serializer from DB and expect values to implement Comparable interface.
static BTreeKeySerializer.Tuple4KeySerializer TUPLE4
          Tuple4 Serializer which uses Default Serializer from DB and expect values to implement Comparable interface.
static BTreeKeySerializer<Integer> ZERO_OR_POSITIVE_INT
          Applies delta packing on java.lang.Integer.
static BTreeKeySerializer<Long> ZERO_OR_POSITIVE_LONG
          Applies delta packing on java.lang.Long.
 
Constructor Summary
BTreeKeySerializer()
           
 
Method Summary
abstract  Object[] deserialize(DataInput in, int start, int end, int size)
          Deserializes keys for single BTree Node.
abstract  Comparator<K> getComparator()
          Some key serializers may only work with they own comparators.
static byte[] leadingValuePackRead(DataInput in, byte[] previous, int ignoreLeadingCount)
          Read previously written data from leadingValuePackWrite() method.
static void leadingValuePackWrite(DataOutput out, byte[] buf, byte[] previous, int ignoreLeadingCount)
          This method is used for delta compression for keys.
abstract  void serialize(DataOutput out, int start, int end, Object[] keys)
          Serialize keys from single BTree Node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BASIC

public static final BTreeKeySerializer BASIC

ZERO_OR_POSITIVE_LONG

public static final BTreeKeySerializer<Long> ZERO_OR_POSITIVE_LONG
Applies delta packing on java.lang.Long. All keys must be non negative. Difference between consequential numbers is also packed itself, so for small diffs it takes only single byte per number.


ZERO_OR_POSITIVE_INT

public static final BTreeKeySerializer<Integer> ZERO_OR_POSITIVE_INT
Applies delta packing on java.lang.Integer. All keys must be non negative. Difference between consequential numbers is also packed itself, so for small diffs it takes only single byte per number.


STRING

public static final BTreeKeySerializer<String> STRING
Applies delta packing on java.lang.String. This serializer splits consequent strings to two parts: shared prefix and different suffix. Only suffix is than stored.


TUPLE2

public static final BTreeKeySerializer.Tuple2KeySerializer TUPLE2
Tuple2 Serializer which uses Default Serializer from DB and expect values to implement Comparable interface.


TUPLE3

public static final BTreeKeySerializer.Tuple3KeySerializer TUPLE3
Tuple3 Serializer which uses Default Serializer from DB and expect values to implement Comparable interface.


TUPLE4

public static final BTreeKeySerializer.Tuple4KeySerializer TUPLE4
Tuple4 Serializer which uses Default Serializer from DB and expect values to implement Comparable interface.

Constructor Detail

BTreeKeySerializer

public BTreeKeySerializer()
Method Detail

serialize

public abstract void serialize(DataOutput out,
                               int start,
                               int end,
                               Object[] keys)
                        throws IOException
Serialize keys from single BTree Node.

Parameters:
out - output stream where to put ata
start - where data start in array. Before this index all keys are null
end - where data ends in array (exclusive). From this index all keys are null
keys - array of keys for single BTree Node
Throws:
IOException

deserialize

public abstract Object[] deserialize(DataInput in,
                                     int start,
                                     int end,
                                     int size)
                              throws IOException
Deserializes keys for single BTree Node. To

Parameters:
in - input stream to read data from
start - where data start in array. Before this index all keys are null
end - where data ends in array (exclusive). From this index all keys are null
size - size of array which should be returned
Returns:
array of keys for single BTree Node
Throws:
IOException

getComparator

public abstract Comparator<K> getComparator()
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.

Returns:
comparator which must be used with this method. `null` if comparator is not strictly required.

leadingValuePackRead

public static byte[] leadingValuePackRead(DataInput in,
                                          byte[] previous,
                                          int ignoreLeadingCount)
                                   throws IOException
Read previously written data from leadingValuePackWrite() method. author: Kevin Day

Throws:
IOException

leadingValuePackWrite

public static void leadingValuePackWrite(DataOutput out,
                                         byte[] buf,
                                         byte[] previous,
                                         int ignoreLeadingCount)
                                  throws IOException
This method is used for delta compression for keys. Writes the contents of buf to the DataOutput out, with special encoding if there are common leading bytes in the previous group stored by this compressor. author: Kevin Day

Throws:
IOException


Copyright © 2014. All Rights Reserved.