]> git.sesse.net Git - plocate/blob - turbopfor-common.h
Release plocate 1.1.22.
[plocate] / turbopfor-common.h
1 #ifndef _TURBOPFOR_COMMON_H
2 #define _TURBOPFOR_COMMON_H 1
3
4 // Common definitions and utilities between turbopfor.h (decode)
5 // and turbopfor-encode.h (encode).
6
7 #include <limits.h>
8
9 enum BlockType {
10         FOR = 0,
11         PFOR_VB = 1,
12         PFOR_BITMAP = 2,
13         CONSTANT = 3
14 };
15
16 // Does not properly account for overflow.
17 inline unsigned div_round_up(unsigned val, unsigned div)
18 {
19         return (val + div - 1) / div;
20 }
21
22 inline unsigned bytes_for_packed_bits(unsigned num, unsigned bit_width)
23 {
24         return div_round_up(num * bit_width, CHAR_BIT);
25 }
26
27 constexpr uint32_t mask_for_bits(unsigned bit_width)
28 {
29         if (bit_width == 32) {
30                 return 0xFFFFFFFF;
31         } else {
32                 return (1U << bit_width) - 1;
33         }
34 }
35
36 #endif  // !defined(_TURBOPFOR_COMMON_H)