1
1
mirror of http://git.sesse.net/plocate synced 2025-10-05 23:42:49 +02:00
Files
plocate/turbopfor-common.h
Steinar H. Gunderson 0f7ca618fb Switch to our own TurboPFor encoder.
This is much slower (plocate-build becomes ~6% slower or so),
but allows us to ditch the external TurboPFor dependency entirely,
and with it, the SSE4.1 demand. This should make us much more palatable
for most distributions.

The benchmark program is extended with some tests that all posting lists
in plocate.db round-trip properly through our encoder, which found a
lot of bugs during development.
2020-10-08 01:04:58 +02:00

37 lines
710 B
C++

#ifndef _TURBOPFOR_COMMON_H
#define _TURBOPFOR_COMMON_H 1
// Common definitions and utilities between turbopfor.h (decode)
// and turbopfor-encode.h (encode).
#include <limits.h>
enum BlockType {
FOR = 0,
PFOR_VB = 1,
PFOR_BITMAP = 2,
CONSTANT = 3
};
// Does not properly account for overflow.
inline unsigned div_round_up(unsigned val, unsigned div)
{
return (val + div - 1) / div;
}
inline unsigned bytes_for_packed_bits(unsigned num, unsigned bit_width)
{
return div_round_up(num * bit_width, CHAR_BIT);
}
constexpr uint32_t mask_for_bits(unsigned bit_width)
{
if (bit_width == 32) {
return 0xFFFFFFFF;
} else {
return (1U << bit_width) - 1;
}
}
#endif // !defined(_TURBOPFOR_COMMON_H)