Skip to content

Commit

Permalink
LZMA2: allocate larger block first (either dictionary or hash+son)
Browse files Browse the repository at this point in the history
git-svn-id: https://freearc.svn.sourceforge.net/svnroot/freearc@636 3a4f7f31-9599-433d-91b1-573e8b61252c
  • Loading branch information
bulatz committed Sep 23, 2009
1 parent fb6fe4a commit 182ef48
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 29 deletions.
70 changes: 43 additions & 27 deletions Compression/LZMA2/C/LzFind.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,40 +199,56 @@ int MatchFinder_Create(CMatchFinder *p, UInt32 historySize, UInt32 hashSize,
p->keepSizeAfter = matchMaxLen + keepAddBufferAfter;
/* we need one additional byte, since we use MoveBlock after pos++ and before dictionary using */

if (LzInWindow_Create(p, sizeReserv, alloc))
{
p->matchMaxLen = matchMaxLen;
hashSize /= sizeof(CLzRef); // convert bytes to hashtable entries
p->hashMask = p->btMode==MF_HashTable? hashSize/p->cutValue-1 // every hash slot contains cutValue entries with the same hash value
: hashSize-1;
p->fixedHashSize = 0;
if (p->numHashBytes > 2) p->fixedHashSize += kHash2Size;
if (p->numHashBytes > 3) p->fixedHashSize += kHash3Size;
if (p->numHashBytes > 4) p->fixedHashSize += kHash4Size;

p->matchMaxLen = matchMaxLen;
hashSize /= sizeof(CLzRef); // convert bytes to hashtable entries
p->hashMask = p->btMode==MF_HashTable? hashSize/p->cutValue-1 // every hash slot contains cutValue entries with the same hash value
: hashSize-1;
p->fixedHashSize = 0;
if (p->numHashBytes > 2) p->fixedHashSize += kHash2Size;
if (p->numHashBytes > 3) p->fixedHashSize += kHash3Size;
if (p->numHashBytes > 4) p->fixedHashSize += kHash4Size;

{
UInt32 prevHashSizeSum = p->hashSizeSum;
UInt32 prevNumSons = p->numSons;
p->historySize = historySize;
p->hashSizeSum = hashSize + p->fixedHashSize;
p->cyclicBufferSize = historySize + 1;
p->numSons = p->btMode==MF_BinaryTree ? p->cyclicBufferSize * 2
: p->btMode==MF_HashChain ? p->cyclicBufferSize
: 0;
if (p->hash != 0 && prevHashSizeSum == p->hashSizeSum &&
(p->son != 0 || prevNumSons == 0) && prevNumSons == p->numSons)
{
UInt32 prevHashSizeSum = p->hashSizeSum;
UInt32 prevNumSons = p->numSons;
p->historySize = historySize;
p->hashSizeSum = hashSize + p->fixedHashSize;
p->cyclicBufferSize = historySize + 1;
p->numSons = p->btMode==MF_BinaryTree ? p->cyclicBufferSize * 2
: p->btMode==MF_HashChain ? p->cyclicBufferSize
: 0;
if (p->hash != 0 && prevHashSizeSum == p->hashSizeSum &&
(p->son != 0 || prevNumSons == 0) && prevNumSons == p->numSons)
{
if (LzInWindow_Create(p, sizeReserv, alloc))
return 1;
}
}
else
{
MatchFinder_FreeThisClassMemory(p, alloc);
p->hash = AllocRefs(p->hashSizeSum, alloc);
p->son = p->numSons? AllocRefs(p->numSons, alloc) : 0;
if (p->hash != 0 && (p->numSons==0 || p->son!=0))

// Allocate larger block first (either dictionary or hash+son)
if (historySize + sizeReserv > (p->hashSizeSum + p->numSons) * sizeof(CLzRef))
{
return 1;
if (LzInWindow_Create(p, sizeReserv, alloc))
{
p->hash = AllocRefs(p->hashSizeSum, alloc);
p->son = p->numSons? AllocRefs(p->numSons, alloc) : 0;
if (p->hash != 0 && (p->numSons==0 || p->son!=0))
return 1;
}
}
else
{
p->son = p->numSons? AllocRefs(p->numSons, alloc) : 0;
p->hash = AllocRefs(p->hashSizeSum, alloc);
if (p->hash != 0 && (p->numSons==0 || p->son!=0))
if (LzInWindow_Create(p, sizeReserv, alloc))
return 1;
}
}
}

MatchFinder_Free(p, alloc);
return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions Compression/LZMA2/readme
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
+4. ����� ���������� �������� � 1 �� �� 64 ��: RC_BUF_SIZE
+5. ��� ���������� ������ ������������ ������ 256 �� (LARGE_BUFFER_SIZE)
+6. ������ ���� � ��������� ������ (CalcHashSize, ReservedAreaSize)
6. ������� �� 3 ����� (hash,son) � ������� �������� ������� ����; MatchFinder_Normalize3
6. kMtMaxValForNormalize=(1<<30)-1, ��� ��� ������� �������� ������������ � ht4 mf
+6. ������� �� 3 ����� (hash,son) � ������� �������� ������� ����; MatchFinder_Normalize3
+6. kMtMaxValForNormalize=(1<<30)-1, ��� ��� ������� �������� ������������ � ht4 mf
+7. kDicLogSizeMaxCompress = 31; MF_HashTable; hashSize; LzmaEncProps_Normalize
8. compress_all_at_once
+9. maxDist[] = {0, 0, 128, 2048, 64<<10, 2<<20, 12<<20} (����������� lazy matching)
Expand Down

0 comments on commit 182ef48

Please sign in to comment.