Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright (c) Yann Collet, Facebook, Inc.
0003  * All rights reserved.
0004  *
0005  * This source code is licensed under both the BSD-style license (found in the
0006  * LICENSE file in the root directory of this source tree) and the GPLv2 (found
0007  * in the COPYING file in the root directory of this source tree).
0008  * You may select, at your option, one of the above-listed licenses.
0009  */
0010 
0011 #ifndef ZSTD_LDM_H
0012 #define ZSTD_LDM_H
0013 
0014 
0015 #include "zstd_compress_internal.h"   /* ldmParams_t, U32 */
0016 #include <linux/zstd.h>   /* ZSTD_CCtx, size_t */
0017 
0018 /*-*************************************
0019 *  Long distance matching
0020 ***************************************/
0021 
0022 #define ZSTD_LDM_DEFAULT_WINDOW_LOG ZSTD_WINDOWLOG_LIMIT_DEFAULT
0023 
0024 void ZSTD_ldm_fillHashTable(
0025             ldmState_t* state, const BYTE* ip,
0026             const BYTE* iend, ldmParams_t const* params);
0027 
0028 /*
0029  * ZSTD_ldm_generateSequences():
0030  *
0031  * Generates the sequences using the long distance match finder.
0032  * Generates long range matching sequences in `sequences`, which parse a prefix
0033  * of the source. `sequences` must be large enough to store every sequence,
0034  * which can be checked with `ZSTD_ldm_getMaxNbSeq()`.
0035  * @returns 0 or an error code.
0036  *
0037  * NOTE: The user must have called ZSTD_window_update() for all of the input
0038  * they have, even if they pass it to ZSTD_ldm_generateSequences() in chunks.
0039  * NOTE: This function returns an error if it runs out of space to store
0040  *       sequences.
0041  */
0042 size_t ZSTD_ldm_generateSequences(
0043             ldmState_t* ldms, rawSeqStore_t* sequences,
0044             ldmParams_t const* params, void const* src, size_t srcSize);
0045 
0046 /*
0047  * ZSTD_ldm_blockCompress():
0048  *
0049  * Compresses a block using the predefined sequences, along with a secondary
0050  * block compressor. The literals section of every sequence is passed to the
0051  * secondary block compressor, and those sequences are interspersed with the
0052  * predefined sequences. Returns the length of the last literals.
0053  * Updates `rawSeqStore.pos` to indicate how many sequences have been consumed.
0054  * `rawSeqStore.seq` may also be updated to split the last sequence between two
0055  * blocks.
0056  * @return The length of the last literals.
0057  *
0058  * NOTE: The source must be at most the maximum block size, but the predefined
0059  * sequences can be any size, and may be longer than the block. In the case that
0060  * they are longer than the block, the last sequences may need to be split into
0061  * two. We handle that case correctly, and update `rawSeqStore` appropriately.
0062  * NOTE: This function does not return any errors.
0063  */
0064 size_t ZSTD_ldm_blockCompress(rawSeqStore_t* rawSeqStore,
0065             ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
0066             void const* src, size_t srcSize);
0067 
0068 /*
0069  * ZSTD_ldm_skipSequences():
0070  *
0071  * Skip past `srcSize` bytes worth of sequences in `rawSeqStore`.
0072  * Avoids emitting matches less than `minMatch` bytes.
0073  * Must be called for data that is not passed to ZSTD_ldm_blockCompress().
0074  */
0075 void ZSTD_ldm_skipSequences(rawSeqStore_t* rawSeqStore, size_t srcSize,
0076     U32 const minMatch);
0077 
0078 /* ZSTD_ldm_skipRawSeqStoreBytes():
0079  * Moves forward in rawSeqStore by nbBytes, updating fields 'pos' and 'posInSequence'.
0080  * Not to be used in conjunction with ZSTD_ldm_skipSequences().
0081  * Must be called for data with is not passed to ZSTD_ldm_blockCompress().
0082  */
0083 void ZSTD_ldm_skipRawSeqStoreBytes(rawSeqStore_t* rawSeqStore, size_t nbBytes);
0084 
0085 /* ZSTD_ldm_getTableSize() :
0086  *  Estimate the space needed for long distance matching tables or 0 if LDM is
0087  *  disabled.
0088  */
0089 size_t ZSTD_ldm_getTableSize(ldmParams_t params);
0090 
0091 /* ZSTD_ldm_getSeqSpace() :
0092  *  Return an upper bound on the number of sequences that can be produced by
0093  *  the long distance matcher, or 0 if LDM is disabled.
0094  */
0095 size_t ZSTD_ldm_getMaxNbSeq(ldmParams_t params, size_t maxChunkSize);
0096 
0097 /* ZSTD_ldm_adjustParameters() :
0098  *  If the params->hashRateLog is not set, set it to its default value based on
0099  *  windowLog and params->hashLog.
0100  *
0101  *  Ensures that params->bucketSizeLog is <= params->hashLog (setting it to
0102  *  params->hashLog if it is not).
0103  *
0104  *  Ensures that the minMatchLength >= targetLength during optimal parsing.
0105  */
0106 void ZSTD_ldm_adjustParameters(ldmParams_t* params,
0107                                ZSTD_compressionParameters const* cParams);
0108 
0109 
0110 #endif /* ZSTD_FAST_H */