2012-10-30 22:02:45 +01:00
|
|
|
/* LzFind.h -- Match finder for LZ algorithms
|
|
|
|
2009-04-22 : Igor Pavlov : Public domain */
|
|
|
|
|
|
|
|
#ifndef __LZ_FIND_H
|
|
|
|
#define __LZ_FIND_H
|
|
|
|
|
|
|
|
#include "Types.h"
|
|
|
|
|
2014-01-27 05:55:01 +01:00
|
|
|
typedef uint32_t CLzRef;
|
2012-10-30 22:02:45 +01:00
|
|
|
|
2014-01-28 03:57:54 +01:00
|
|
|
struct CMatchFinder
|
2012-10-30 22:02:45 +01:00
|
|
|
{
|
2014-01-27 05:55:01 +01:00
|
|
|
uint8_t *buffer;
|
|
|
|
uint32_t pos;
|
|
|
|
uint32_t posLimit;
|
|
|
|
uint32_t streamPos;
|
|
|
|
uint32_t lenLimit;
|
2012-10-30 22:02:45 +01:00
|
|
|
|
2014-01-27 05:55:01 +01:00
|
|
|
uint32_t cyclicBufferPos;
|
|
|
|
uint32_t cyclicBufferSize; /* it must be = (historySize + 1) */
|
2012-10-30 22:02:45 +01:00
|
|
|
|
2014-01-27 05:55:01 +01:00
|
|
|
uint32_t matchMaxLen;
|
2012-10-30 22:02:45 +01:00
|
|
|
CLzRef *hash;
|
|
|
|
CLzRef *son;
|
2014-01-27 05:55:01 +01:00
|
|
|
uint32_t hashMask;
|
|
|
|
uint32_t cutValue;
|
2012-10-30 22:02:45 +01:00
|
|
|
|
2014-01-27 05:55:01 +01:00
|
|
|
uint8_t *bufferBase;
|
2014-01-28 03:57:54 +01:00
|
|
|
struct ISeqInStream *stream;
|
2012-10-30 22:02:45 +01:00
|
|
|
int streamEndWasReached;
|
|
|
|
|
2014-01-27 05:55:01 +01:00
|
|
|
uint32_t blockSize;
|
|
|
|
uint32_t keepSizeBefore;
|
|
|
|
uint32_t keepSizeAfter;
|
2012-10-30 22:02:45 +01:00
|
|
|
|
2014-01-27 05:55:01 +01:00
|
|
|
uint32_t numHashBytes;
|
2012-10-30 22:02:45 +01:00
|
|
|
int directInput;
|
|
|
|
size_t directInputRem;
|
|
|
|
int btMode;
|
|
|
|
int bigHash;
|
2014-01-27 05:55:01 +01:00
|
|
|
uint32_t historySize;
|
|
|
|
uint32_t fixedHashSize;
|
|
|
|
uint32_t hashSizeSum;
|
|
|
|
uint32_t numSons;
|
2012-10-30 22:02:45 +01:00
|
|
|
SRes result;
|
2014-01-27 05:55:01 +01:00
|
|
|
uint32_t crc[256];
|
2014-01-28 03:57:54 +01:00
|
|
|
};
|
2012-10-30 22:02:45 +01:00
|
|
|
|
|
|
|
#define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer)
|
2014-01-27 05:55:01 +01:00
|
|
|
#define Inline_MatchFinder_GetIndexByte(p, index) ((p)->buffer[(int32_t)(index)])
|
2012-10-30 22:02:45 +01:00
|
|
|
|
|
|
|
#define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)
|
|
|
|
|
2014-01-28 03:57:54 +01:00
|
|
|
int MatchFinder_NeedMove(struct CMatchFinder *p);
|
|
|
|
uint8_t *MatchFinder_GetPointerToCurrentPos(struct CMatchFinder *p);
|
|
|
|
void MatchFinder_MoveBlock(struct CMatchFinder *p);
|
|
|
|
void MatchFinder_ReadIfRequired(struct CMatchFinder *p);
|
2012-10-30 22:02:45 +01:00
|
|
|
|
2014-01-28 03:57:54 +01:00
|
|
|
void MatchFinder_Construct(struct CMatchFinder *p);
|
2012-10-30 22:02:45 +01:00
|
|
|
|
|
|
|
/* Conditions:
|
|
|
|
historySize <= 3 GB
|
|
|
|
keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB
|
|
|
|
*/
|
2014-01-28 03:57:54 +01:00
|
|
|
int MatchFinder_Create(struct CMatchFinder *p, uint32_t historySize,
|
2014-01-27 05:55:01 +01:00
|
|
|
uint32_t keepAddBufferBefore, uint32_t matchMaxLen, uint32_t keepAddBufferAfter,
|
2014-01-28 03:57:54 +01:00
|
|
|
struct ISzAlloc *alloc);
|
|
|
|
void MatchFinder_Free(struct CMatchFinder *p, struct ISzAlloc *alloc);
|
2014-01-27 05:55:01 +01:00
|
|
|
void MatchFinder_Normalize3(uint32_t subValue, CLzRef *items, uint32_t numItems);
|
2014-01-28 03:57:54 +01:00
|
|
|
void MatchFinder_ReduceOffsets(struct CMatchFinder *p, uint32_t subValue);
|
2012-10-30 22:02:45 +01:00
|
|
|
|
2014-01-27 05:55:01 +01:00
|
|
|
uint32_t * GetMatchesSpec1(uint32_t lenLimit, uint32_t curMatch, uint32_t pos, const uint8_t *buffer, CLzRef *son,
|
|
|
|
uint32_t _cyclicBufferPos, uint32_t _cyclicBufferSize, uint32_t _cutValue,
|
|
|
|
uint32_t *distances, uint32_t maxLen);
|
2012-10-30 22:02:45 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
Conditions:
|
|
|
|
Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func.
|
|
|
|
Mf_GetPointerToCurrentPos_Func's result must be used only before any other function
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef void (*Mf_Init_Func)(void *object);
|
2014-01-27 05:55:01 +01:00
|
|
|
typedef uint8_t (*Mf_GetIndexByte_Func)(void *object, int32_t index);
|
|
|
|
typedef uint32_t (*Mf_GetNumAvailableBytes_Func)(void *object);
|
|
|
|
typedef const uint8_t * (*Mf_GetPointerToCurrentPos_Func)(void *object);
|
|
|
|
typedef uint32_t (*Mf_GetMatches_Func)(void *object, uint32_t *distances);
|
|
|
|
typedef void (*Mf_Skip_Func)(void *object, uint32_t);
|
2012-10-30 22:02:45 +01:00
|
|
|
|
2014-01-28 03:57:54 +01:00
|
|
|
struct IMatchFinder
|
2012-10-30 22:02:45 +01:00
|
|
|
{
|
|
|
|
Mf_Init_Func Init;
|
|
|
|
Mf_GetIndexByte_Func GetIndexByte;
|
|
|
|
Mf_GetNumAvailableBytes_Func GetNumAvailableBytes;
|
|
|
|
Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos;
|
|
|
|
Mf_GetMatches_Func GetMatches;
|
|
|
|
Mf_Skip_Func Skip;
|
2014-01-28 03:57:54 +01:00
|
|
|
};
|
2012-10-30 22:02:45 +01:00
|
|
|
|
2014-01-28 03:57:54 +01:00
|
|
|
void MatchFinder_CreateVTable(struct CMatchFinder *p, struct IMatchFinder *vTable);
|
2012-10-30 22:02:45 +01:00
|
|
|
|
2014-01-28 03:57:54 +01:00
|
|
|
void MatchFinder_Init(struct CMatchFinder *p);
|
|
|
|
uint32_t Bt3Zip_MatchFinder_GetMatches(struct CMatchFinder *p, uint32_t *distances);
|
|
|
|
uint32_t Hc3Zip_MatchFinder_GetMatches(struct CMatchFinder *p, uint32_t *distances);
|
|
|
|
void Bt3Zip_MatchFinder_Skip(struct CMatchFinder *p, uint32_t num);
|
|
|
|
void Hc3Zip_MatchFinder_Skip(struct CMatchFinder *p, uint32_t num);
|
2012-10-30 22:02:45 +01:00
|
|
|
|
|
|
|
#endif
|