4 * Fast searching for repeat offset matches.
6 * The author dedicates this file to the public domain.
7 * You can do whatever you want with this file.
10 #ifndef _LZ_REPSEARCH_H
11 #define _LZ_REPSEARCH_H
13 #include "wimlib/lz_extend.h"
14 #include "wimlib/util.h"
17 lz_extend_repmatch(const u8 *strptr, const u8 *matchptr, u32 max_len);
20 * Find the longest repeat offset match.
22 * If no match of at least 2 bytes is found, then return 0.
24 * If a match of at least 2 bytes is found, then return its length and set
25 * *slot_ret to the index of its offset in @queue.
28 lz_repsearch(const u8 * const strptr, const u32 bytes_remaining,
29 const u32 max_match_len, const u32 repeat_offsets[],
30 const unsigned num_repeat_offsets, unsigned *slot_ret)
34 if (likely(bytes_remaining >= 2)) {
35 const u32 max_len = min(max_match_len, bytes_remaining);
36 const u16 str = *(const u16 *)strptr;
38 for (unsigned i = 0; i < num_repeat_offsets; i++) {
39 const u8 * const matchptr = strptr - repeat_offsets[i];
41 /* Check the first two bytes. If they match, then
42 * extend the match to its full length. */
43 if (*(const u16 *)matchptr == str) {
44 const u32 len = lz_extend_repmatch(strptr, matchptr, max_len);
55 #endif /* _LZ_REPSEARCH_H */