]> wimlib.net Git - wimlib/blob - include/wimlib/matchfinder_nonsliding.h
v1.7.4
[wimlib] / include / wimlib / matchfinder_nonsliding.h
1 /*
2  * matchfinder_nonsliding.h
3  *
4  * Definitions for nonsliding window matchfinders.
5  *
6  * "Nonsliding window" means that any prior sequence can be matched.
7  */
8
9 #if MATCHFINDER_WINDOW_ORDER <= 16
10 typedef u16 pos_t;
11 #else
12 typedef u32 pos_t;
13 #endif
14
15 #if MATCHFINDER_WINDOW_ORDER != 16 && MATCHFINDER_WINDOW_ORDER != 32
16
17 /* Not all the bits of the position type are needed, so the sign bit can be
18  * reserved to mean "out of bounds".  */
19 #define MATCHFINDER_INITVAL ((pos_t)-1)
20
21 static inline bool
22 matchfinder_match_in_window(pos_t cur_match, const u8 *in_base, const u8 *in_next)
23 {
24         return !(cur_match & ((pos_t)1 << (sizeof(pos_t) * 8 - 1)));
25 }
26
27 #else
28
29 /* All bits of the position type are needed, so use 0 to mean "out of bounds".
30  * This prevents the beginning of the buffer from matching anything; however,
31  * this doesn't matter much.  */
32
33 #define MATCHFINDER_INITVAL ((pos_t)0)
34
35 static inline bool
36 matchfinder_match_in_window(pos_t cur_match, const u8 *in_base, const u8 *in_next)
37 {
38         return cur_match != 0;
39 }
40
41 #endif
42
43 static inline pos_t
44 matchfinder_slot_for_match(pos_t cur_match)
45 {
46         return cur_match;
47 }