40 return mask ?
sizeof(T) * 8 - do_clz(mask) : 0;
43 static const unsigned char hob_tab[256] = {
44 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4,
45 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
46 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
47 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
48 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
49 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
50 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
51 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
52 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
53 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
54 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
55 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
56 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
57 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
58 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
59 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8
63 if constexpr(
sizeof(T) > 4) {
64 if (mask >= 0x100000000ul) {
69 if (mask >= 0x10000u) {
77 return result + hob_tab[mask];
84 template<
typename T,
typename U>
85 static constexpr
inline
88 return (shift >=
sizeof(T) * 8 ? 0 : x << shift);
129 if (value >= mid_start + spare) {
130 value = (value - (mid_start + spare)) |
132 }
else if (value >= mid_start) {
137 if (bits + n_bits >
sizeof(acc) * 8) {
141 Assert(bits <=
sizeof(acc) * 8);
142 acc |= (value << n_bits);
148 acc |= (value << n_bits);
150 while (n_bits >= 8) {
172 encode_interpolative(
pos, j, mid);
181 Assert(force == di_current.is_initialized());
191 pos = read_bits(bits - 1);
192 if (
pos < mid_start) {
193 if (read_bits(1))
pos += mid_start + spare;
196 pos = read_bits(bits);
203 BitReader::read_bits(
int count)
206 if (count >
int(
sizeof(acc) * 8 - 7)) {
212 Assert(count <=
int(
sizeof(acc) * 8));
213 const size_t half_the_bits =
sizeof(acc) * 4;
214 result = read_bits(half_the_bits);
215 return result | (read_bits(count - half_the_bits) << half_the_bits);
217 while (n_bits < count) {
229 BitReader::decode_interpolative(
int j,
int k,
232 Assert(!di_current.is_initialized());
234 di_current.set_j(j, pos_j);
235 di_current.set_k(k, pos_k);
239 BitReader::decode_interpolative_next()
241 Assert(di_current.is_initialized());
242 while (!di_stack.empty() || di_current.is_next()) {
243 if (!di_current.is_next()) {
245 di_current = di_stack.back();
247 int mid = (di_current.j + di_current.k) / 2;
248 di_current.set_j(mid, pos_ret);
251 di_stack.push_back(di_current);
252 int mid = (di_current.j + di_current.k) / 2;
254 (di_current.pos_j + mid - di_current.j);
255 di_current.set_k(mid, pos_mid);
257 #ifdef XAPIAN_ASSERTIONS
260 return di_current.pos_k;
static int highest_order_bit(T mask)
Classes to encode/decode a bitstream.
Suitable for "simple" type T.
#define UNSIGNED_OVERFLOW_OK(X)
bool encode(double lat, double lon, std::string &result)
Encode a coordinate and append it to a string.
The Xapian namespace contains public interfaces for the Xapian library.
static constexpr T safe_shl(T x, U shift)
Shift left that's safe for shifts wider than the type.
unsigned XAPIAN_TERMPOS_BASE_TYPE termpos
A term position within a document or query.
Various assertion macros.
Pack types into strings and unpack them again.
static int decode(const T(&table)[N], const char *s)
Decode a string to an integer.