Home | History | Annotate | Download | only in lzma_sdk
      1 /* LzFind.h -- Match finder for LZ algorithms
      2 2009-04-22 : Igor Pavlov : Public domain
      3 in the public domain */
      4 
      5 #ifndef __LZ_FIND_H
      6 #define __LZ_FIND_H
      7 
      8 #include "Types.h"
      9 
     10 #ifdef __cplusplus
     11 extern "C" {
     12 #endif
     13 
     14 typedef UInt32 CLzRef;
     15 
     16 typedef struct _CMatchFinder
     17 {
     18   Byte *buffer;
     19   UInt32 pos;
     20   UInt32 posLimit;
     21   UInt32 streamPos;
     22   UInt32 lenLimit;
     23 
     24   UInt32 cyclicBufferPos;
     25   UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */
     26 
     27   UInt32 matchMaxLen;
     28   CLzRef *hash;
     29   CLzRef *son;
     30   UInt32 hashMask;
     31   UInt32 cutValue;
     32 
     33   Byte *bufferBase;
     34   ISeqInStream *stream;
     35   int streamEndWasReached;
     36 
     37   UInt32 blockSize;
     38   UInt32 keepSizeBefore;
     39   UInt32 keepSizeAfter;
     40 
     41   UInt32 numHashBytes;
     42   int directInput;
     43   size_t directInputRem;
     44   int btMode;
     45   int bigHash;
     46   UInt32 historySize;
     47   UInt32 fixedHashSize;
     48   UInt32 hashSizeSum;
     49   UInt32 numSons;
     50   SRes result;
     51   UInt32 crc[256];
     52 } CMatchFinder;
     53 
     54 #define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer)
     55 #define Inline_MatchFinder_GetIndexByte(p, index) ((p)->buffer[(Int32)(index)])
     56 
     57 #define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)
     58 
     59 int MatchFinder_NeedMove(CMatchFinder *p);
     60 Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p);
     61 void MatchFinder_MoveBlock(CMatchFinder *p);
     62 void MatchFinder_ReadIfRequired(CMatchFinder *p);
     63 
     64 void MatchFinder_Construct(CMatchFinder *p);
     65 
     66 /* Conditions:
     67      historySize <= 3 GB
     68      keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB
     69 */
     70 int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
     71     UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
     72     ISzAlloc *alloc);
     73 void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc);
     74 void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems);
     75 void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue);
     76 
     77 UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son,
     78     UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,
     79     UInt32 *distances, UInt32 maxLen);
     80 
     81 /*
     82 Conditions:
     83   Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func.
     84   Mf_GetPointerToCurrentPos_Func's result must be used only before any other function
     85 */
     86 
     87 typedef void (*Mf_Init_Func)(void *object);
     88 typedef Byte (*Mf_GetIndexByte_Func)(void *object, Int32 index);
     89 typedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object);
     90 typedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object);
     91 typedef UInt32 (*Mf_GetMatches_Func)(void *object, UInt32 *distances);
     92 typedef void (*Mf_Skip_Func)(void *object, UInt32);
     93 
     94 typedef struct _IMatchFinder
     95 {
     96   Mf_Init_Func Init;
     97   Mf_GetIndexByte_Func GetIndexByte;
     98   Mf_GetNumAvailableBytes_Func GetNumAvailableBytes;
     99   Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos;
    100   Mf_GetMatches_Func GetMatches;
    101   Mf_Skip_Func Skip;
    102 } IMatchFinder;
    103 
    104 void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable);
    105 
    106 void MatchFinder_Init(CMatchFinder *p);
    107 UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
    108 UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
    109 void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
    110 void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
    111 
    112 #ifdef __cplusplus
    113 }
    114 #endif
    115 
    116 #endif
    117