ultimatepp/uppdev/NibblePtr/lzf.cpp
cxl 238e8e006a .dev
git-svn-id: svn://ultimatepp.org/upp/trunk@7818 f0d560ea-af0d-0410-9eb7-867de7ffcac7
2014-10-23 13:41:01 +00:00

52 lines
963 B
C++

#include "Entropy.h"
// Test/Test FooFoo
String LZFCompress(const char *s, int length)
{
String result;
const char *end = s + length;
const char *hash_table[8192];
for(int i = 0; i < 8192; i++)
hash_table[i] = s;
char *lit = s;
int litlen = min(length, 4);
s += 4;
for(;;) {
char *hptr;
for(;;) {
hash = (2654435761U * Peek32le(s)) & 8191;
hptr = hash_table[hash];
if(s - hptr < 65536 && Peek32le(hash_table[hash]) == Peek32le(s))
break;
litlen++;
hash_table[(2654435761U * Peek32le(s - 3)) & 8191] = s - 3;
s++;
if(s >= end)
return;
}
int matchlen = 4;
while(hptr + matchlen < s && s[matchlen] == hptr[matchlen])
matchlen++;
LOGHEXDUMP(lit, litlen);
LOGHEXDUMP(hptr, matchlen);
const char *e = s + matchlen;
while(s < e) {
hash_table[(2654435761U * Peek32le(s - 3)) & 8191] = s - 3;
s++;
}
lit = s;
}
}