X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=include%2Fwimlib%2Flz_hash.h;h=f7618152b9b02377936b37d3280bb49f83ecabe8;hb=4a20aae0dd8469a352517a0b107416ffa99ccc55;hp=9a856a5b698ca7b132a2ad91c5049f6e4bb5de3f;hpb=31786dbc470c919893bf4fc5cc91a0f73cbee720;p=wimlib diff --git a/include/wimlib/lz_hash.h b/include/wimlib/lz_hash.h index 9a856a5b..f7618152 100644 --- a/include/wimlib/lz_hash.h +++ b/include/wimlib/lz_hash.h @@ -1,30 +1,39 @@ -#ifndef _WIMLIB_LZ_HASH_H -#define _WIMLIB_LZ_HASH_H +/* + * lz_hash.h - hashing for Lempel-Ziv matchfinding + * + * The following copying information applies to this specific source code file: + * + * Written in 2014-2015 by Eric Biggers + * + * To the extent possible under law, the author(s) have dedicated all copyright + * and related and neighboring rights to this software to the public domain + * worldwide via the Creative Commons Zero 1.0 Universal Public Domain + * Dedication (the "CC0"). + * + * This software is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the CC0 for more details. + * + * You should have received a copy of the CC0 along with this software; if not + * see . + */ -#include "wimlib/compress_common.h" +#ifndef _LZ_HASH_H +#define _LZ_HASH_H -struct lz_params { - unsigned min_match; - unsigned max_match; - unsigned max_offset; - unsigned nice_match; - unsigned good_match; - unsigned max_chain_len; - unsigned max_lazy_match; - unsigned too_far; -}; +#include "wimlib/types.h" -typedef void (*lz_record_match_t)(unsigned len, unsigned offset, void *ctx); -typedef void (*lz_record_literal_t)(u8 lit, void *ctx); +/* + * The hash function: given a sequence prefix held in the low-order bits of a + * 32-bit value, multiply by a carefully-chosen large constant. Discard any + * bits of the product that don't fit in a 32-bit value, but take the + * next-highest @num_bits bits of the product as the hash value, as those have + * the most randomness. + */ +static forceinline u32 +lz_hash(u32 seq, unsigned num_bits) +{ + return (u32)(seq * 0x1E35A7BD) >> (32 - num_bits); +} -extern void -lz_analyze_block(const u8 window[restrict], - u32 window_size, - lz_record_match_t record_match, - lz_record_literal_t record_literal, - void *record_ctx, - const struct lz_params *params, - u32 prev_tab[restrict]); - - -#endif /* _WIMLIB_LZ_HASH_H */ +#endif /* _LZ_HASH_H */