Skip to content

Commit

Permalink
Tornado: when dictsize increased, increase hashsize in the same propo…
Browse files Browse the repository at this point in the history
…rtion

git-svn-id: https://freearc.svn.sourceforge.net/svnroot/freearc@114 3a4f7f31-9599-433d-91b1-573e8b61252c
  • Loading branch information
bulatz committed Feb 26, 2009
1 parent 5a1a316 commit 7c80018
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
13 changes: 12 additions & 1 deletion Compression/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ static inline int file_exists (CFILENAME name) {return _taccess(name,0) == 0;}
// Number of 100 nanosecond units from 01.01.1601 to 01.01.1970
#define EPOCH_BIAS 116444736000000000ull

inline void WINAPI UnixTimeToFileTime( time_t time, FILETIME* ft )
static inline void WINAPI UnixTimeToFileTime( time_t time, FILETIME* ft )
{
*(uint64*)ft = EPOCH_BIAS + time * 10000000ull;
}
Expand Down Expand Up @@ -484,6 +484,17 @@ static inline MemSize rounddown_to_power_of (MemSize n, MemSize base)
return result;
}

// Ýòà ïðîöåäóðà îêðóãëÿåò ÷èñëî ê ëîãàðèôìè÷åñêè áëèæàéøåé ñòåïåíè
// áàçû, íàïðèìåð f(9,2)=8 f(15,2)=16
static inline MemSize round_to_nearest_power_of (MemSize n, MemSize base)
{
MemSize result;
uint64 nn = uint64(n)*n/base;
if (nn==0) return 1;
for (result=base; (nn/=base*base) != 0; result *= base);
return result;
}

// Çàìåíèòü ñèìâîëû èç ìíîæåñòâà from íà ñèìâîë to
static inline char *replace (char *str, char* from, char to)
{
Expand Down
16 changes: 13 additions & 3 deletions Compression/Tornado/C_Tornado.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,22 @@ int TORNADO_METHOD::compress (CALLBACK_FUNC *callback, void *auxdata)
return tor_compress (m, callback, auxdata);
}

// Óñòàíîâèòü ðàçìåð ñëîâàðÿ è óìåíüøèòü ðàçìåð õýøà, åñëè îí ñëèøêîì âåëèê äëÿ òàêîãî ìàëåíüêîãî áëîêà
// Óñòàíîâèòü ðàçìåð ñëîâàðÿ è îòêîððåêòèðîâàòü ðàçìåð õåøà
void TORNADO_METHOD::SetDictionary (MemSize dict)
{
if (dict>0) {
m.buffer = dict;
m.hashsize = mymin (m.hashsize/sizeof(void*), 1<<(lb(m.buffer-1)+1)) * sizeof(void*);
if (dict < m.buffer)
// Ïðè óìåíüøåíèè ñëîâàðÿ: óìåíüøèòü ðàçìåð õýøà, åñëè îí ñëèøêîì âåëèê äëÿ òàêîãî ìàëåíüêîãî áëîêà
m.hashsize = sizeof(PtrVal) * mymin (m.hashsize/sizeof(PtrVal), roundup_to_power_of(dict,2));
else
// Ïðè óâåëè÷åíèè ñëîâàðÿ: ïðîïîðöèîíàëüíî óâåëè÷èòü ðàçìåð õåøà
if (m.hashsize > 1*mb)
{
if (m.hashsize<8*mb && m.hashsize<m.buffer/2) m.hashsize = m.buffer/2; // Âî-ïåðâûõ, óâåëè÷èì ðàçìåð õåøà, åñëè îí áûë ïîäîãíàí ïîä êåø Core2
uint h = mymin (uint64(dict) / (m.buffer/64) * (m.hashsize/64), 2*gb); // Èäåàëüíûé ðàçìåð íîâîãî õåøà
m.hashsize = mymin (round_to_nearest_power_of(h / m.hash_row_width, 2) * m.hash_row_width, 2*gb); // Îêðóãëèì ðàçìåð õåøà ñ ó÷¸òîì row_width
}
m.buffer = dict;
}
}

Expand Down

0 comments on commit 7c80018

Please sign in to comment.