mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-16 14:16:09 -06:00
52 lines
963 B
C++
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;
|
|
|
|
}
|
|
}
|