/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* LzFind.c -- Match finder for LZ algorithms
2008-10-04 : Igor Pavlov : Public domain */
#include <string.h>
#include "LzFind.h"
#include "LzHash.h"
#define kEmptyHashValue 0
{
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);
}
{
}
{
return;
for (;;)
{
if (size == 0)
return;
return;
if (size == 0)
{
p->streamEndWasReached = 1;
return;
}
return;
}
}
{
memmove(p->bufferBase,
p->buffer - p->keepSizeBefore,
}
{
/* if (p->streamEndWasReached) return 0; */
}
{
if (p->streamEndWasReached)
return;
}
{
if (MatchFinder_NeedMove(p))
}
{
p->cutValue = 32;
p->btMode = 1;
p->numHashBytes = 4;
/* p->skipModeBits = 0; */
p->directInput = 0;
p->bigHash = 0;
}
{
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;
}
{
if (limit2 <= p->keepSizeAfter)
{
if (limit2 > 0)
limit2 = 1;
}
else
limit2 -= p->keepSizeAfter;
{
if (lenLimit > p->matchMaxLen)
lenLimit = p->matchMaxLen;
}
}
{
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
}
}
{
}
{
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
{
}
}