… | |
… | |
48 | */ |
48 | */ |
49 | #ifndef FRST |
49 | #ifndef FRST |
50 | # define FRST(p) (((p[0]) << 8) | p[1]) |
50 | # define FRST(p) (((p[0]) << 8) | p[1]) |
51 | # define NEXT(v,p) (((v) << 8) | p[2]) |
51 | # define NEXT(v,p) (((v) << 8) | p[2]) |
52 | # define IDX(h) ((((h ^ (h << 5)) >> (3*8 - HLOG)) - h*5) & (HSIZE - 1)) |
52 | # define IDX(h) ((((h ^ (h << 5)) >> (3*8 - HLOG)) - h*5) & (HSIZE - 1)) |
|
|
53 | /*# define IDX(h) ((ip[0] * 121 ^ ip[1] * 33 ^ ip[2] * 1) & (HSIZE-1))*/ |
53 | #endif |
54 | #endif |
54 | /* |
55 | /* |
55 | * IDX works because it is very similar to a multiplicative hash, e.g. |
56 | * IDX works because it is very similar to a multiplicative hash, e.g. |
56 | * ((h * 57321 >> (3*8 - HLOG)) & (HSIZE - 1)) |
57 | * ((h * 57321 >> (3*8 - HLOG)) & (HSIZE - 1)) |
57 | * the latter is also quite fast on newer CPUs, and sligthly better |
58 | * the latter is also quite fast on newer CPUs, and compresses similarly. |
58 | * |
59 | * |
59 | * the next one is also quite good, albeit slow ;) |
60 | * the next one is also quite good, albeit slow ;) |
60 | * (int)(cos(h & 0xffffff) * 1e6) |
61 | * (int)(cos(h & 0xffffff) * 1e6) |
61 | */ |
62 | */ |
62 | |
63 | |
… | |
… | |
67 | # define IDX(h) ((h) & (HSIZE - 1)) |
68 | # define IDX(h) ((h) & (HSIZE - 1)) |
68 | #endif |
69 | #endif |
69 | |
70 | |
70 | #define MAX_LIT (1 << 5) |
71 | #define MAX_LIT (1 << 5) |
71 | #define MAX_OFF (1 << 13) |
72 | #define MAX_OFF (1 << 13) |
72 | #define MAX_REF ((1 << 8) + (1 << 3)) |
73 | #define MAX_REF ((1 << 8) + (1 << 3)) |
73 | |
74 | |
74 | /* |
75 | /* |
75 | * compressed format |
76 | * compressed format |
76 | * |
77 | * |
77 | * 000LLLLL <L+1> ; literal |
78 | * 000LLLLL <L+1> ; literal |
… | |
… | |
82 | |
83 | |
83 | unsigned int |
84 | unsigned int |
84 | lzf_compress (const void *const in_data, unsigned int in_len, |
85 | lzf_compress (const void *const in_data, unsigned int in_len, |
85 | void *out_data, unsigned int out_len |
86 | void *out_data, unsigned int out_len |
86 | #if LZF_STATE_ARG |
87 | #if LZF_STATE_ARG |
87 | , LZF_STATE *htab |
88 | , LZF_STATE htab |
88 | #endif |
89 | #endif |
89 | ) |
90 | ) |
90 | { |
91 | { |
91 | #if !LZF_STATE_ARG |
92 | #if !LZF_STATE_ARG |
92 | LZF_STATE htab; |
93 | LZF_STATE htab; |