LzFind.c revision 4fd606d1f5abe38e1f42c38de1d2e895166bd0f4
/** @file
Based on LZMA SDK 4.65:
LzFind.c -- Match finder for LZ algorithms
2008-10-04 : Igor Pavlov : Public domain
Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef EFIAPI
#include <string.h>
#endif // !EFIAPI
#include "LzFind.h"
#include "LzHash.h"
#define kEmptyHashValue 0
#define kStartMaxLen 3
{
if (!p->directInput)
{
p->bufferBase = 0;
}
}
/* keepSizeBefore + keepSizeAfter + keepSizeReserv must be < 4G) */
{
if (p->directInput)
{
return 1;
}
{
LzInWindow_Free(p, alloc);
}
return (p->bufferBase != 0);
}
{
}
static void MatchFinder_ReadBlock(CMatchFinder *p)
{
return;
for (;;)
{
if (size == 0)
return;
return;
if (size == 0)
{
p->streamEndWasReached = 1;
return;
}
return;
}
}
void MatchFinder_MoveBlock(CMatchFinder *p)
{
memmove(p->bufferBase,
p->buffer - p->keepSizeBefore,
}
int MatchFinder_NeedMove(CMatchFinder *p)
{
/* if (p->streamEndWasReached) return 0; */
}
void MatchFinder_ReadIfRequired(CMatchFinder *p)
{
if (p->streamEndWasReached)
return;
}
static void MatchFinder_CheckAndMoveAndRead(CMatchFinder *p)
{
if (MatchFinder_NeedMove(p))
}
static void MatchFinder_SetDefaultSettings(CMatchFinder *p)
{
p->cutValue = 32;
p->btMode = 1;
p->numHashBytes = 4;
/* p->skipModeBits = 0; */
p->directInput = 0;
p->bigHash = 0;
}
#define kCrcPoly 0xEDB88320
void MatchFinder_Construct(CMatchFinder *p)
{
UInt32 i;
p->bufferBase = 0;
p->directInput = 0;
p->hash = 0;
for (i = 0; i < 256; i++)
{
UInt32 r = i;
int j;
for (j = 0; j < 8; j++)
p->crc[i] = r;
}
}
{
p->hash = 0;
}
{
LzInWindow_Free(p, alloc);
}
{
return 0;
}
{
if (historySize > kMaxHistorySize)
{
MatchFinder_Free(p, alloc);
return 0;
}
/* we need one additional byte, since we use MoveBlock after pos++ and before dictionary using */
{
p->matchMaxLen = matchMaxLen;
{
p->fixedHashSize = 0;
if (p->numHashBytes == 2)
else
{
hs >>= 1;
/* hs >>= p->skipModeBits; */
{
if (p->numHashBytes == 3)
else
hs >>= 1;
}
}
hs++;
hs += p->fixedHashSize;
}
{
p->historySize = historySize;
p->hashSizeSum = hs;
return 1;
if (p->hash != 0)
{
return 1;
}
}
}
MatchFinder_Free(p, alloc);
return 0;
}
static void MatchFinder_SetLimits(CMatchFinder *p)
{
if (limit2 <= p->keepSizeAfter)
{
if (limit2 > 0)
limit2 = 1;
}
else
limit2 -= p->keepSizeAfter;
{
if (lenLimit > p->matchMaxLen)
lenLimit = p->matchMaxLen;
}
}
void MatchFinder_Init(CMatchFinder *p)
{
UInt32 i;
for (i = 0; i < p->hashSizeSum; i++)
p->hash[i] = kEmptyHashValue;
p->cyclicBufferPos = 0;
p->buffer = p->bufferBase;
p->streamEndWasReached = 0;
}
{
}
{
UInt32 i;
for (i = 0; i < numItems; i++)
{
else
}
}
static void MatchFinder_Normalize(CMatchFinder *p)
{
}
static void MatchFinder_CheckLimits(CMatchFinder *p)
{
if (p->pos == kMaxValForNormalize)
if (p->cyclicBufferPos == p->cyclicBufferSize)
p->cyclicBufferPos = 0;
}
static UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
{
for (;;)
{
return distances;
{
{
break;
{
return distances;
}
}
}
}
}
UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
{
for (;;)
{
{
return distances;
}
{
CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
{
break;
{
{
return distances;
}
}
}
{
}
else
{
}
}
}
}
static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
{
for (;;)
{
{
return;
}
{
CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
{
break;
{
{
return;
}
}
}
{
}
else
{
}
}
}
}
#define MOVE_POS \
++p->cyclicBufferPos; \
p->buffer++; \
#define MF_PARAMS(p) p->pos, p->buffer, p->son, p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue
#define SKIP_FOOTER \
{
offset = 0;
}
{
offset = 0;
}
{
p->hash[hash2Value] =
maxLen = 2;
offset = 0;
{
break;
offset = 2;
{
}
}
}
{
p->hash[ hash2Value] =
maxLen = 1;
offset = 0;
{
offset = 2;
}
{
maxLen = 3;
offset += 2;
}
if (offset != 0)
{
break;
{
}
}
if (maxLen < 3)
maxLen = 3;
}
{
p->hash[ hash2Value] =
maxLen = 1;
offset = 0;
{
offset = 2;
}
{
maxLen = 3;
offset += 2;
}
if (offset != 0)
{
break;
{
}
}
if (maxLen < 3)
maxLen = 3;
}
{
}
{
do
{
SKIP_HEADER(2)
}
while (--num != 0);
}
{
do
{
SKIP_HEADER(3)
}
while (--num != 0);
}
{
do
{
SKIP_HEADER(3)
p->hash[hash2Value] =
}
while (--num != 0);
}
{
do
{
SKIP_HEADER(4)
p->hash[ hash2Value] =
}
while (--num != 0);
}
{
do
{
SKIP_HEADER(4)
p->hash[ hash2Value] =
}
while (--num != 0);
}
{
do
{
SKIP_HEADER(3)
}
while (--num != 0);
}
{
vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinder_GetPointerToCurrentPos;
if (!p->btMode)
{
}
else if (p->numHashBytes == 2)
{
}
else if (p->numHashBytes == 3)
{
}
else
{
}
}