2017-09-07 00:56:01 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under both the BSD-style license (found in the
|
|
|
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
|
|
|
* in the COPYING file in the root directory of this source tree).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ZSTD_LDM_H
|
|
|
|
#define ZSTD_LDM_H
|
|
|
|
|
|
|
|
#if defined (__cplusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2017-11-08 00:15:23 +00:00
|
|
|
#include "zstd_compress_internal.h" /* ldmParams_t, U32 */
|
|
|
|
#include "zstd.h" /* ZSTD_CCtx, size_t */
|
|
|
|
|
2017-09-07 00:56:01 +00:00
|
|
|
/*-*************************************
|
|
|
|
* Long distance matching
|
|
|
|
***************************************/
|
|
|
|
|
2017-09-22 21:04:39 +00:00
|
|
|
#define ZSTD_LDM_DEFAULT_WINDOW_LOG ZSTD_WINDOWLOG_DEFAULTMAX
|
2017-09-07 00:56:01 +00:00
|
|
|
|
2018-02-21 03:34:43 +00:00
|
|
|
/**
|
|
|
|
* ZSTD_ldm_generateSequences():
|
2017-09-07 00:56:01 +00:00
|
|
|
*
|
2018-02-21 03:34:43 +00:00
|
|
|
* Generates the sequences using the long distance match finder.
|
2018-03-07 03:50:50 +00:00
|
|
|
* Generates long range matching sequences in `sequences`, which parse a prefix
|
|
|
|
* of the source. `sequences` must be large enough to store every sequence,
|
|
|
|
* which can be checked with `ZSTD_ldm_getMaxNbSeq()`.
|
|
|
|
* @returns 0 or an error code.
|
2017-09-07 00:56:01 +00:00
|
|
|
*
|
2018-03-07 03:50:50 +00:00
|
|
|
* NOTE: The user must have called ZSTD_window_update() for all of the input
|
|
|
|
* they have, even if they pass it to ZSTD_ldm_generateSequences() in chunks.
|
|
|
|
* NOTE: This function returns an error if it runs out of space to store
|
|
|
|
* sequences.
|
2018-02-21 03:34:43 +00:00
|
|
|
*/
|
|
|
|
size_t ZSTD_ldm_generateSequences(
|
2018-03-19 18:07:04 +00:00
|
|
|
ldmState_t* ldms, rawSeqStore_t* sequences,
|
|
|
|
ldmParams_t const* params, void const* src, size_t srcSize);
|
2018-02-21 03:34:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ZSTD_ldm_blockCompress():
|
|
|
|
*
|
|
|
|
* Compresses a block using the predefined sequences, along with a secondary
|
|
|
|
* block compressor. The literals section of every sequence is passed to the
|
|
|
|
* secondary block compressor, and those sequences are interspersed with the
|
|
|
|
* predefined sequences. Returns the length of the last literals.
|
2018-03-07 03:50:50 +00:00
|
|
|
* Updates `rawSeqStore.pos` to indicate how many sequences have been consumed.
|
|
|
|
* `rawSeqStore.seq` may also be updated to split the last sequence between two
|
|
|
|
* blocks.
|
|
|
|
* @return The length of the last literals.
|
2017-09-07 00:56:01 +00:00
|
|
|
*
|
2018-02-21 03:34:43 +00:00
|
|
|
* NOTE: The source must be at most the maximum block size, but the predefined
|
|
|
|
* sequences can be any size, and may be longer than the block. In the case that
|
|
|
|
* they are longer than the block, the last sequences may need to be split into
|
2018-03-07 03:50:50 +00:00
|
|
|
* two. We handle that case correctly, and update `rawSeqStore` appropriately.
|
|
|
|
* NOTE: This function does not return any errors.
|
2018-02-21 03:34:43 +00:00
|
|
|
*/
|
2018-03-07 03:50:50 +00:00
|
|
|
size_t ZSTD_ldm_blockCompress(rawSeqStore_t* rawSeqStore,
|
2018-03-20 23:35:14 +00:00
|
|
|
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
2018-05-02 21:34:34 +00:00
|
|
|
void const* src, size_t srcSize);
|
2017-12-13 00:51:00 +00:00
|
|
|
|
2018-03-20 21:31:43 +00:00
|
|
|
/**
|
|
|
|
* ZSTD_ldm_skipSequences():
|
|
|
|
*
|
|
|
|
* Skip past `srcSize` bytes worth of sequences in `rawSeqStore`.
|
|
|
|
* Avoids emitting matches less than `minMatch` bytes.
|
|
|
|
* Must be called for data with is not passed to ZSTD_ldm_blockCompress().
|
|
|
|
*/
|
|
|
|
void ZSTD_ldm_skipSequences(rawSeqStore_t* rawSeqStore, size_t srcSize,
|
|
|
|
U32 const minMatch);
|
|
|
|
|
2017-09-07 00:56:01 +00:00
|
|
|
|
|
|
|
/** ZSTD_ldm_getTableSize() :
|
2018-02-21 03:34:43 +00:00
|
|
|
* Estimate the space needed for long distance matching tables or 0 if LDM is
|
|
|
|
* disabled.
|
|
|
|
*/
|
|
|
|
size_t ZSTD_ldm_getTableSize(ldmParams_t params);
|
|
|
|
|
|
|
|
/** ZSTD_ldm_getSeqSpace() :
|
|
|
|
* Return an upper bound on the number of sequences that can be produced by
|
|
|
|
* the long distance matcher, or 0 if LDM is disabled.
|
|
|
|
*/
|
|
|
|
size_t ZSTD_ldm_getMaxNbSeq(ldmParams_t params, size_t maxChunkSize);
|
2017-09-07 00:56:01 +00:00
|
|
|
|
|
|
|
/** ZSTD_ldm_getTableSize() :
|
|
|
|
* Return prime8bytes^(minMatchLength-1) */
|
|
|
|
U64 ZSTD_ldm_getHashPower(U32 minMatchLength);
|
|
|
|
|
|
|
|
/** ZSTD_ldm_adjustParameters() :
|
|
|
|
* If the params->hashEveryLog is not set, set it to its default value based on
|
|
|
|
* windowLog and params->hashLog.
|
|
|
|
*
|
|
|
|
* Ensures that params->bucketSizeLog is <= params->hashLog (setting it to
|
2018-02-21 03:34:43 +00:00
|
|
|
* params->hashLog if it is not).
|
|
|
|
*
|
|
|
|
* Ensures that the minMatchLength >= targetLength during optimal parsing.
|
|
|
|
*/
|
|
|
|
void ZSTD_ldm_adjustParameters(ldmParams_t* params,
|
|
|
|
ZSTD_compressionParameters const* cParams);
|
2017-09-07 00:56:01 +00:00
|
|
|
|
|
|
|
#if defined (__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* ZSTD_FAST_H */
|