public class LZ4HC
extends java.lang.Object
These functions compress data in successive blocks of any size, using previous blocks as dictionary, to improve compression ratio. One key assumption
is that previous blocks (up to 64 KB) remain read-accessible while compressing next blocks. There is an exception for ring buffers, which can be
smaller than 64 KB. Ring-buffer scenario is automatically detected and handled within compress_HC_continue.
Before starting compression, state must be allocated and properly initialized. createStreamHC does both, though compression level is set to
CLEVEL_DEFAULT.
Selecting the compression level can be done with resetStreamHC_fast (starts a new stream) setCompressionLevel (anytime, between blocks in the
same stream) (experimental). LZ4_resetStreamHC_fast() only works on states which have been properly initialized at least once, which is
automatically the case when state is created using LZ4_createStreamHC().
After reset, a first "fictional block" can be designated as initial dictionary, using loadDictHC (Optional).
Invoke compress_HC_continue to compress each successive block. The number of blocks is unlimited. Previous input blocks, including initial
dictionary when present, must remain accessible and unmodified during compression.
It's allowed to update compression level anytime between blocks, using LZ4_setCompressionLevel() (experimental).
dst buffer should be sized to handle worst case scenarios (see compressBound, it ensures compression success). In case of failure, the API
does not guarantee recovery, so the state must be reset. To ensure compression success whenever dst buffer size cannot be made ≥
LZ4_compressBound(), consider using compress_HC_continue_destSize.
Whenever previous input blocks can't be preserved unmodified in-place during compression of next blocks, it's possible to copy the last blocks into a
more stable memory space, using saveDictHC. Return value of LZ4_saveDictHC() is the size of dictionary effectively saved into
safeBuffer (≤ 64 KB)
After completing a streaming compression, it's possible to start a new stream of blocks, using the same LZ4_streamHC_t state, just by
resetting it, using LZ4_resetStreamHC_fast().
| Modifier and Type | Field and Description |
|---|---|
static int |
LZ4_STREAMHCSIZE |
static int |
LZ4_STREAMHCSIZE_SIZET |
static int |
LZ4HC_CLEVEL_DEFAULT
Compression level.
|
static int |
LZ4HC_CLEVEL_MAX
Compression level.
|
static int |
LZ4HC_CLEVEL_MIN
Compression level.
|
static int |
LZ4HC_CLEVEL_OPT_MIN
Compression level.
|
static int |
LZ4HC_DICTIONARY_LOGSIZE |
static int |
LZ4HC_HASH_LOG |
static int |
LZ4HC_HASH_MASK |
static int |
LZ4HC_HASHTABLESIZE |
static int |
LZ4HC_MAXD |
static int |
LZ4HC_MAXD_MASK |
| Modifier and Type | Method and Description |
|---|---|
static void |
LZ4_attach_HC_dictionary(long working_stream,
long dictionary_stream)
This is an experimental API that allows for the efficient use of a static dictionary many times.
|
static int |
LZ4_compress_HC_continue_destSize(long streamHCPtr,
java.nio.ByteBuffer src,
java.nio.ByteBuffer dst,
java.nio.IntBuffer srcSizePtr)
Similar to
compress_HC_continue, but will read as much data as possible from src to fit into targetDstSize budget. |
static int |
LZ4_compress_HC_continue(long streamHCPtr,
java.nio.ByteBuffer src,
java.nio.ByteBuffer dst) |
static int |
LZ4_compress_HC_destSize(java.nio.ByteBuffer stateHC,
java.nio.ByteBuffer src,
java.nio.ByteBuffer dst,
java.nio.IntBuffer srcSizePtr,
int compressionLevel)
Will compress as much data as possible from
src to fit into targetDstSize budget. |
static int |
LZ4_compress_HC_extStateHC_fastReset(java.nio.ByteBuffer state,
java.nio.ByteBuffer src,
java.nio.ByteBuffer dst,
int compressionLevel)
A variant of
compress_HC_extStateHC. |
static int |
LZ4_compress_HC_extStateHC(java.nio.ByteBuffer state,
java.nio.ByteBuffer src,
java.nio.ByteBuffer dst,
int compressionLevel)
Same as
compress_HC, but using an externally allocated memory segment for state. |
static int |
LZ4_compress_HC(java.nio.ByteBuffer src,
java.nio.ByteBuffer dst,
int compressionLevel)
Compress data from
src into dst, using the powerful but slower "HC" algorithm. |
static long |
LZ4_createStreamHC()
Creates memory for LZ4 HC streaming state.
|
static void |
LZ4_favorDecompressionSpeed(long LZ4_streamHCPtr,
boolean favor)
Parser will favor decompression speed over compression ratio.
|
static int |
LZ4_freeStreamHC(long streamHCPtr)
Releases memory for LZ4 HC streaming state.
|
static long |
LZ4_initStreamHC(java.nio.ByteBuffer buffer)
Required before first use of a statically allocated
LZ4_streamHC_t. |
static int |
LZ4_loadDictHC(long streamHCPtr,
java.nio.ByteBuffer dictionary) |
static void |
LZ4_resetStreamHC_fast(long LZ4_streamHCPtr,
int compressionLevel)
When an
LZ4_streamHC_t is known to be in a internally coherent state, it can often be prepared for a new compression with almost no work, only
sometimes falling back to the full, expensive reset that is always required when the stream is in an indeterminate state (i.e., the reset performed by
initStreamHC). |
static int |
LZ4_saveDictHC(long streamHCPtr,
java.nio.ByteBuffer safeBuffer) |
static void |
LZ4_setCompressionLevel(long LZ4_streamHCPtr,
int compressionLevel)
It's possible to change compression level between successive invocations of
LZ4_compress_HC_continue*() for dynamic adaptation. |
static int |
LZ4_sizeofStateHC() |
static void |
nLZ4_attach_HC_dictionary(long working_stream,
long dictionary_stream)
Unsafe version of:
attach_HC_dictionary |
static int |
nLZ4_compress_HC_continue_destSize(long streamHCPtr,
long src,
long dst,
long srcSizePtr,
int targetDstSize)
Unsafe version of:
compress_HC_continue_destSize |
static int |
nLZ4_compress_HC_continue(long streamHCPtr,
long src,
long dst,
int srcSize,
int maxDstSize) |
static int |
nLZ4_compress_HC_destSize(long stateHC,
long src,
long dst,
long srcSizePtr,
int targetDstSize,
int compressionLevel)
Unsafe version of:
compress_HC_destSize |
static int |
nLZ4_compress_HC_extStateHC_fastReset(long state,
long src,
long dst,
int srcSize,
int dstCapacity,
int compressionLevel)
Unsafe version of:
compress_HC_extStateHC_fastReset |
static int |
nLZ4_compress_HC_extStateHC(long state,
long src,
long dst,
int srcSize,
int maxDstSize,
int compressionLevel)
Unsafe version of:
compress_HC_extStateHC |
static int |
nLZ4_compress_HC(long src,
long dst,
int srcSize,
int dstCapacity,
int compressionLevel)
Unsafe version of:
compress_HC |
static void |
nLZ4_favorDecompressionSpeed(long LZ4_streamHCPtr,
int favor)
Unsafe version of:
favorDecompressionSpeed |
static int |
nLZ4_freeStreamHC(long streamHCPtr)
Unsafe version of:
freeStreamHC |
static long |
nLZ4_initStreamHC(long buffer,
long size)
Unsafe version of:
initStreamHC |
static int |
nLZ4_loadDictHC(long streamHCPtr,
long dictionary,
int dictSize) |
static void |
nLZ4_resetStreamHC_fast(long LZ4_streamHCPtr,
int compressionLevel)
Unsafe version of:
resetStreamHC_fast |
static int |
nLZ4_saveDictHC(long streamHCPtr,
long safeBuffer,
int maxDictSize) |
static void |
nLZ4_setCompressionLevel(long LZ4_streamHCPtr,
int compressionLevel)
Unsafe version of:
setCompressionLevel |
public static final int LZ4HC_CLEVEL_MIN
public static final int LZ4HC_CLEVEL_DEFAULT
public static final int LZ4HC_CLEVEL_OPT_MIN
public static final int LZ4HC_CLEVEL_MAX
public static final int LZ4HC_DICTIONARY_LOGSIZE
public static final int LZ4HC_MAXD
public static final int LZ4HC_MAXD_MASK
public static final int LZ4HC_HASH_LOG
public static final int LZ4HC_HASHTABLESIZE
public static final int LZ4HC_HASH_MASK
public static final int LZ4_STREAMHCSIZE
public static final int LZ4_STREAMHCSIZE_SIZET
public static int nLZ4_compress_HC(long src,
long dst,
int srcSize,
int dstCapacity,
int compressionLevel)
compress_HCsrcSize - max supported value is MAX_INPUT_SIZEpublic static int LZ4_compress_HC(java.nio.ByteBuffer src,
java.nio.ByteBuffer dst,
int compressionLevel)
src into dst, using the powerful but slower "HC" algorithm.
Compression is guaranteed to succeed if dstCapacity ≥ compressBound(srcSize)`
dst - must be already allocatedcompressionLevel - any value between 1 and CLEVEL_MAX will work. Values > CLEVEL_MAX behave the same as CLEVEL_MAX.dst or 0 if compression failspublic static int LZ4_sizeofStateHC()
public static int nLZ4_compress_HC_extStateHC(long state,
long src,
long dst,
int srcSize,
int maxDstSize,
int compressionLevel)
compress_HC_extStateHCpublic static int LZ4_compress_HC_extStateHC(java.nio.ByteBuffer state,
java.nio.ByteBuffer src,
java.nio.ByteBuffer dst,
int compressionLevel)
compress_HC, but using an externally allocated memory segment for state.
state size is provided by sizeofStateHC. Memory segment must be aligned on 8-bytes boundaries (which a normal malloc() should do
properly).
public static int nLZ4_compress_HC_destSize(long stateHC,
long src,
long dst,
long srcSizePtr,
int targetDstSize,
int compressionLevel)
compress_HC_destSizesrcSizePtr - on success, *srcSizePtr is updated to indicate how much bytes were read from srcpublic static int LZ4_compress_HC_destSize(java.nio.ByteBuffer stateHC,
java.nio.ByteBuffer src,
java.nio.ByteBuffer dst,
java.nio.IntBuffer srcSizePtr,
int compressionLevel)
src to fit into targetDstSize budget.srcSizePtr - on success, *srcSizePtr is updated to indicate how much bytes were read from srcdst (necessarily ≤ targetDstSize) or 0 if compression failspublic static long LZ4_createStreamHC()
Newly created states are automatically initialized. A same state can be used multiple times consecutively, starting with resetStreamHC_fast to start
a new stream of blocks.
public static int nLZ4_freeStreamHC(long streamHCPtr)
freeStreamHCpublic static int LZ4_freeStreamHC(long streamHCPtr)
public static void nLZ4_resetStreamHC_fast(long LZ4_streamHCPtr,
int compressionLevel)
resetStreamHC_fastpublic static void LZ4_resetStreamHC_fast(long LZ4_streamHCPtr,
int compressionLevel)
LZ4_streamHC_t is known to be in a internally coherent state, it can often be prepared for a new compression with almost no work, only
sometimes falling back to the full, expensive reset that is always required when the stream is in an indeterminate state (i.e., the reset performed by
initStreamHC).
LZ4_streamHCs are guaranteed to be in a valid state when:
createStreamHCinitStreamHCmemset(stream, 0, sizeof(LZ4_streamHC_t))resetStreamHC_fastcompress_HC_extStateHC) and that
returned successNote: A stream that was last used in a compression call that returned an error may be passed to this function. However, it will be fully reset, which will clear any existing history and settings from the context.
public static int nLZ4_loadDictHC(long streamHCPtr,
long dictionary,
int dictSize)
public static int LZ4_loadDictHC(long streamHCPtr,
java.nio.ByteBuffer dictionary)
public static int nLZ4_compress_HC_continue(long streamHCPtr,
long src,
long dst,
int srcSize,
int maxDstSize)
public static int LZ4_compress_HC_continue(long streamHCPtr,
java.nio.ByteBuffer src,
java.nio.ByteBuffer dst)
public static int nLZ4_compress_HC_continue_destSize(long streamHCPtr,
long src,
long dst,
long srcSizePtr,
int targetDstSize)
compress_HC_continue_destSizesrcSizePtr - on success, *srcSizePtr will be updated to indicate how much bytes were read from src. Note that this function may not consume the
entire input.public static int LZ4_compress_HC_continue_destSize(long streamHCPtr,
java.nio.ByteBuffer src,
java.nio.ByteBuffer dst,
java.nio.IntBuffer srcSizePtr)
compress_HC_continue, but will read as much data as possible from src to fit into targetDstSize budget.srcSizePtr - on success, *srcSizePtr will be updated to indicate how much bytes were read from src. Note that this function may not consume the
entire input.dst (necessarily ≤ targetDstSize) or 0 if compression failspublic static int nLZ4_saveDictHC(long streamHCPtr,
long safeBuffer,
int maxDictSize)
public static int LZ4_saveDictHC(long streamHCPtr,
java.nio.ByteBuffer safeBuffer)
public static long nLZ4_initStreamHC(long buffer,
long size)
initStreamHCpublic static long LZ4_initStreamHC(java.nio.ByteBuffer buffer)
LZ4_streamHC_t.public static void nLZ4_setCompressionLevel(long LZ4_streamHCPtr,
int compressionLevel)
setCompressionLevelpublic static void LZ4_setCompressionLevel(long LZ4_streamHCPtr,
int compressionLevel)
LZ4_compress_HC_continue*() for dynamic adaptation.public static void nLZ4_favorDecompressionSpeed(long LZ4_streamHCPtr,
int favor)
favorDecompressionSpeedpublic static void LZ4_favorDecompressionSpeed(long LZ4_streamHCPtr,
boolean favor)
Only applicable to levels ≥ CLEVEL_OPT_MIN.
public static int nLZ4_compress_HC_extStateHC_fastReset(long state,
long src,
long dst,
int srcSize,
int dstCapacity,
int compressionLevel)
compress_HC_extStateHC_fastResetpublic static int LZ4_compress_HC_extStateHC_fastReset(java.nio.ByteBuffer state,
java.nio.ByteBuffer src,
java.nio.ByteBuffer dst,
int compressionLevel)
compress_HC_extStateHC.
Using this variant avoids an expensive initialization step. It is only safe to call if the state buffer is known to be correctly initialized already
(see comment on resetStreamHC_fast for a definition of "correctly initialized"). From a high level, the difference is that this function initializes
the provided state with a call to resetStreamHC_fast while compress_HC_extStateHC starts with a call to initStreamHC.
public static void nLZ4_attach_HC_dictionary(long working_stream,
long dictionary_stream)
attach_HC_dictionarypublic static void LZ4_attach_HC_dictionary(long working_stream,
long dictionary_stream)
Rather than re-loading the dictionary buffer into a working context before each compression, or copying a pre-loaded dictionary's
LZ4_streamHC_t into a working LZ4_streamHC_t, this function introduces a no-copy setup mechanism, in which the working stream
references the dictionary stream in-place.
Several assumptions are made about the state of the dictionary stream. Currently, only streams which have been prepared by loadDictHC should be
expected to work.
Alternatively, the provided dictionary stream pointer may be NULL, in which case any existing dictionary stream is unset.
A dictionary should only be attached to a stream without any history (i.e., a stream that has just been reset).
The dictionary will remain attached to the working stream only for the current stream session. Calls to resetStreamHC_fast will remove the
dictionary context association from the working stream. The dictionary stream (and source buffer) must remain in-place / accessible / unchanged through
the lifetime of the stream session.
Copyright LWJGL. All Rights Reserved. License terms.