X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=ucw%2Fvarint.h;h=493af8167c6134560f40ecea4deae47036e31f6d;hb=ec6703bb4d58e504fde8ea8429f9b26ab6632696;hp=79952dc143eb76dd02c582397ef8b070a4bb4007;hpb=790966f9e1eb198ec8e6374d66c9211b01fd9a12;p=libucw.git diff --git a/ucw/varint.h b/ucw/varint.h index 79952dc1..493af816 100644 --- a/ucw/varint.h +++ b/ucw/varint.h @@ -10,18 +10,23 @@ #ifndef _UCW_VARINT_H #define _UCW_VARINT_H +#ifdef CONFIG_UCW_CLEAN_ABI +#define varint_get_big ucw_varint_get_big +#define varint_put_big ucw_varint_put_big +#endif + /*** * The encoding works in the following way: * - * First byte Stored values + * First byte Stored values * - * 0xxxxxxx 7 bits - * 10xxxxxx +1 byte 14 bits, value shifted by 2^7 - * 110xxxxx +2 bytes 21 bits, value shifted by 2^7+2^14 - * 1110xxxx +3 bytes 28 bits, value shifted by 2^7+2^14+2^21 + * 0xxxxxxx 7 bits + * 10xxxxxx +1 byte 14 bits, value shifted by 2^7 + * 110xxxxx +2 bytes 21 bits, value shifted by 2^7+2^14 + * 1110xxxx +3 bytes 28 bits, value shifted by 2^7+2^14+2^21 * .... - * 11111110 +7 bytes 56 bits, value shifted by 2^7+2^14+2^21+2^28+2^35+2^42 - * 11111111 +8 bytes full 64 bits, value shifted by 2^7+2^14+2^21+2^28+2^35+2^42+2^56 + * 11111110 +7 bytes 56 bits, value shifted by 2^7+2^14+2^21+2^28+2^35+2^42 + * 11111111 +8 bytes full 64 bits, value shifted by 2^7+2^14+2^21+2^28+2^35+2^42+2^56 * * The values are stored in bigendian to allow lexicographic sorting. * The encoding and algorithms are aimed to be optimised for storing shorter numbers. @@ -48,14 +53,14 @@ #define PUTB4(b) PUTB(0,b-1) PUTB(1,b-2) PUTB(2,b-3) PUTB(3,b-4) /* for internal use only, need the length > 4 */ -uns varint_put_big(byte *p, u64 u); +uint varint_put_big(byte *p, u64 u); const byte *varint_get_big(const byte *p, u64 *r); /** * Encode u64 value u into byte sequence p. * Returns the number of bytes used (at least 1 and at most 9). **/ -static inline uns varint_put(byte *p, u64 u) +static inline uint varint_put(byte *p, u64 u) { if (u < VARINT_SHIFT_L1) { p[0] = (byte)u; @@ -166,18 +171,18 @@ static inline int varint_invalid(const byte *p) * Store the invalid sequence. * Returns always 2 (2 bytes were used, to be consistent with varint_put). **/ -static inline uns varint_put_invalid(byte *p) +static inline uint varint_put_invalid(byte *p) { p[0] = p[1] = 0xff; return 2; } /** Compute the length of encoding in bytes from the first byte hdr of the encoding. **/ -static inline uns varint_len(const byte hdr) +static inline uint varint_len(const byte hdr) { byte b = ~hdr; - uns l = 0; + uint l = 0; if (!b) l = -1; else { @@ -189,7 +194,7 @@ static inline uns varint_len(const byte hdr) } /** Compute the number of bytes needed to store the value u. **/ -static inline uns varint_space(u64 u) +static inline uint varint_space(u64 u) { if (u < VARINT_SHIFT_L1) return 1;