]> wimlib.net Git - wimlib/blob - include/wimlib/matchfinder_sliding.h
Faster XPRESS compression
[wimlib] / include / wimlib / matchfinder_sliding.h
1 /*
2  * matchfinder_sliding.h
3  *
4  * Definitions for sliding window matchfinders.
5  *
6  * "Sliding window" means that only sequences beginning in the most recent
7  * MATCHFINDER_WINDOW_SIZE bytes can be matched.
8  */
9
10 #if MATCHFINDER_WINDOW_ORDER <= 15
11 typedef s16 pos_t;
12 #else
13 typedef s32 pos_t;
14 #endif
15
16 #define MATCHFINDER_INITVAL ((pos_t)-MATCHFINDER_WINDOW_SIZE)
17
18 /* In the sliding window case, positions are stored relative to 'in_base'.  */
19
20 static inline bool
21 matchfinder_match_in_window(pos_t cur_match, const u8 *in_base, const u8 *in_next)
22 {
23         return cur_match > (pos_t)((in_next - in_base) - MATCHFINDER_WINDOW_SIZE);
24 }
25
26 static inline pos_t
27 matchfinder_slot_for_match(pos_t cur_match)
28 {
29         return cur_match & (MATCHFINDER_WINDOW_SIZE - 1);
30 }