misc/libphysfs/lzma/C/Compress/Lz/MatchFinder.h
changeset 13881 99b265e0d1d0
parent 13880 5f819b90d479
child 13882 b172a5d40eee
equal deleted inserted replaced
13880:5f819b90d479 13881:99b265e0d1d0
     1 /* MatchFinder.h */
       
     2 
       
     3 #ifndef __MATCHFINDER_H
       
     4 #define __MATCHFINDER_H
       
     5 
       
     6 #include "../../IStream.h"
       
     7 
       
     8 typedef UInt32 CLzRef;
       
     9 
       
    10 typedef struct _CMatchFinder
       
    11 {
       
    12   Byte *buffer;
       
    13   UInt32 pos;
       
    14   UInt32 posLimit;
       
    15   UInt32 streamPos;
       
    16   UInt32 lenLimit;
       
    17 
       
    18   UInt32 cyclicBufferPos;
       
    19   UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */
       
    20 
       
    21   UInt32 matchMaxLen;
       
    22   CLzRef *hash;
       
    23   CLzRef *son;
       
    24   UInt32 hashMask;
       
    25   UInt32 cutValue;
       
    26 
       
    27   Byte *bufferBase;
       
    28   ISeqInStream *stream;
       
    29   int streamEndWasReached;
       
    30 
       
    31   UInt32 blockSize;
       
    32   UInt32 keepSizeBefore;
       
    33   UInt32 keepSizeAfter;
       
    34 
       
    35   UInt32 numHashBytes;
       
    36   int directInput;
       
    37   int btMode;
       
    38   /* int skipModeBits; */
       
    39   int bigHash;
       
    40   UInt32 historySize;
       
    41   UInt32 fixedHashSize;
       
    42   UInt32 hashSizeSum;
       
    43   UInt32 numSons;
       
    44 
       
    45   HRes result;
       
    46 } CMatchFinder;
       
    47 
       
    48 #define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer)
       
    49 #define Inline_MatchFinder_GetIndexByte(p, index) ((p)->buffer[(Int32)(index)])
       
    50 
       
    51 #define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)
       
    52 
       
    53 int MatchFinder_NeedMove(CMatchFinder *p);
       
    54 Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p);
       
    55 void MatchFinder_MoveBlock(CMatchFinder *p);
       
    56 void MatchFinder_ReadIfRequired(CMatchFinder *p);
       
    57 
       
    58 void MatchFinder_Construct(CMatchFinder *p);
       
    59 
       
    60 /* Conditions:
       
    61      historySize <= 3 GB
       
    62      keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB
       
    63 */
       
    64 int MatchFinder_Create(CMatchFinder *p, UInt32 historySize, 
       
    65     UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
       
    66     ISzAlloc *alloc);
       
    67 void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc);
       
    68 void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems);
       
    69 void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue);
       
    70 
       
    71 UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son, 
       
    72     UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue, 
       
    73     UInt32 *distances, UInt32 maxLen);
       
    74 
       
    75 /* 
       
    76 Conditions:
       
    77   Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func.
       
    78   Mf_GetPointerToCurrentPos_Func's result must be used only before any other function
       
    79 */
       
    80 
       
    81 typedef void (*Mf_Init_Func)(void *object);
       
    82 typedef Byte (*Mf_GetIndexByte_Func)(void *object, Int32 index);
       
    83 typedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object);
       
    84 typedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object);
       
    85 typedef UInt32 (*Mf_GetMatches_Func)(void *object, UInt32 *distances);
       
    86 typedef void (*Mf_Skip_Func)(void *object, UInt32);
       
    87 
       
    88 typedef struct _IMatchFinder
       
    89 {
       
    90   Mf_Init_Func Init;
       
    91   Mf_GetIndexByte_Func GetIndexByte;
       
    92   Mf_GetNumAvailableBytes_Func GetNumAvailableBytes;
       
    93   Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos;
       
    94   Mf_GetMatches_Func GetMatches;
       
    95   Mf_Skip_Func Skip;
       
    96 } IMatchFinder;
       
    97 
       
    98 void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable);
       
    99 
       
   100 void MatchFinder_Init(CMatchFinder *p);
       
   101 UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
       
   102 UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
       
   103 void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
       
   104 void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
       
   105 
       
   106 #endif