Top Description Fields Constructors Methods
org.h2.compress

public final Class CompressLZF

extends Object
implements Compressor
Class Inheritance
All Implemented Interfaces
org.h2.compress.Compressor
Imports
java.nio.ByteBuffer

This class implements the LZF lossless data compression algorithm. LZF is a Lempel-Ziv variant with byte-aligned output, and optimized for speed.

Safety/Use Notes:

The LZF compressed format knows literal runs and back-references:

The first byte of the compressed stream is the control byte. For literal runs, the highest three bits of the control byte are not set, the lower bits are the literal run length, and the next bytes are data to copy directly into the output. For back-references, the highest three bits of the control byte are the back-reference length. If all three bits are set, then the back-reference length is stored in the next byte. The lower bits of the control byte combined with the next byte form the offset for the back-reference.

Field Summary

Modifier and TypeField and Description
private int[]
cachedHashTable

Hash table for matching byte sequences (reused for performance).

private static final int
HASH_SIZE

The number of entries in the hash table.

private static final int
MAX_LITERAL

The maximum number of literals in a chunk (32).

private static final int
MAX_OFF

The maximum offset allowed for a back-reference (8192).

private static final int
MAX_REF

The maximum back-reference length (264).

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public int
compress(byte[]
the input data
in
,
int
the offset at the input array
inPos
,
int
the number of bytes to compress
inLen
,
byte[]
the output area
out
,
int
the offset at the output array
outPos
)

Implements org.h2.compress.Compressor.compress.

Compress a number of bytes.

public int

Returns:

the end position
compress
(ByteBuffer
the input data
in
,
int
the offset at the input buffer
inPos
,
byte[]
the output area
out
,
int
the offset at the output array
outPos
)

Compress a number of bytes.

public void
expand(byte[]
the compressed data
in
,
int
the offset at the input array
inPos
,
int
the number of bytes to read
inLen
,
byte[]
the output area
out
,
int
the offset at the output array
outPos
,
int
the size of the uncompressed data
outLen
)

Implements org.h2.compress.Compressor.expand.

Expand a number of compressed bytes.

public static void
expand(ByteBuffer
the compressed data
in
,
ByteBuffer
the output area
out
)

Expand a number of compressed bytes.

private static int
first(byte[] in, int inPos)

Return the integer with the first two bytes 0, then the bytes at the index, then at index+1.

private static int
first(ByteBuffer in, int inPos)

Return the integer with the first two bytes 0, then the bytes at the index, then at index+1.

public int
getAlgorithm()

Implements org.h2.compress.Compressor.getAlgorithm.

Get the compression algorithm type.

private static int
hash(int h)

Compute the address in the hash table.

private static int
next(int v, byte[] in, int inPos)

Shift the value 1 byte left, and add the byte at index inPos+2.

private static int
next(int v, ByteBuffer in, int inPos)

Shift the value 1 byte left, and add the byte at index inPos+2.

public void
setOptions(String
the options
options
)

Implements org.h2.compress.Compressor.setOptions.

Set the compression options.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cachedHashTableback to summary
private int[] cachedHashTable

Hash table for matching byte sequences (reused for performance).

HASH_SIZEback to summary
private static final int HASH_SIZE

The number of entries in the hash table. The size is a trade-off between hash collisions (reduced compression) and speed (amount that fits in CPU cache).

MAX_LITERALback to summary
private static final int MAX_LITERAL

The maximum number of literals in a chunk (32).

MAX_OFFback to summary
private static final int MAX_OFF

The maximum offset allowed for a back-reference (8192).

MAX_REFback to summary
private static final int MAX_REF

The maximum back-reference length (264).

Constructor Detail

CompressLZFback to summary
public CompressLZF()

Method Detail

compressback to summary
public int compress(byte[] in, int inPos, int inLen, byte[] out, int outPos)

Implements org.h2.compress.Compressor.compress.

Doc from org.h2.compress.Compressor.compress.

Compress a number of bytes.

Parameters
in:byte[]

the input data

inPos:int

the offset at the input array

inLen:int

the number of bytes to compress

out:byte[]

the output area

outPos:int

the offset at the output array

Returns:int

the end position

Annotations
@Override
compressback to summary
public int compress(ByteBuffer in, int inPos, byte[] out, int outPos)

Compress a number of bytes.

Parameters
in:ByteBuffer

the input data

inPos:int

the offset at the input buffer

out:byte[]

the output area

outPos:int

the offset at the output array

Returns:int

the end position

expandback to summary
public void expand(byte[] in, int inPos, int inLen, byte[] out, int outPos, int outLen)

Implements org.h2.compress.Compressor.expand.

Doc from org.h2.compress.Compressor.expand.

Expand a number of compressed bytes.

Parameters
in:byte[]

the compressed data

inPos:int

the offset at the input array

inLen:int

the number of bytes to read

out:byte[]

the output area

outPos:int

the offset at the output array

outLen:int

the size of the uncompressed data

Annotations
@Override
expandback to summary
public static void expand(ByteBuffer in, ByteBuffer out)

Expand a number of compressed bytes.

Parameters
in:ByteBuffer

the compressed data

out:ByteBuffer

the output area

firstback to summary
private static int first(byte[] in, int inPos)

Return the integer with the first two bytes 0, then the bytes at the index, then at index+1.

firstback to summary
private static int first(ByteBuffer in, int inPos)

Return the integer with the first two bytes 0, then the bytes at the index, then at index+1.

getAlgorithmback to summary
public int getAlgorithm()

Implements org.h2.compress.Compressor.getAlgorithm.

Doc from org.h2.compress.Compressor.getAlgorithm.

Get the compression algorithm type.

Returns:int

the type

Annotations
@Override
hashback to summary
private static int hash(int h)

Compute the address in the hash table.

nextback to summary
private static int next(int v, byte[] in, int inPos)

Shift the value 1 byte left, and add the byte at index inPos+2.

nextback to summary
private static int next(int v, ByteBuffer in, int inPos)

Shift the value 1 byte left, and add the byte at index inPos+2.

setOptionsback to summary
public void setOptions(String options)

Implements org.h2.compress.Compressor.setOptions.

Doc from org.h2.compress.Compressor.setOptions.

Set the compression options. This may include settings for higher performance but less compression.

Parameters
options:String

the options

Annotations
@Override