17 #define forceinline inline 18 #define JASS_COMPRESS_INTEGER_BITS_PER_INTEGER 32 42 typedef uint32_t integer;
79 virtual size_t encode(
void *encoded,
size_t encoded_buffer_length,
const integer *source,
size_t source_integers);
92 virtual void decode(integer *decoded,
size_t integers_to_decode,
const void *source,
size_t source_length)
97 static_decode(decoded, integers_to_decode, source, source_length);
111 static inline void static_decode(integer *decoded,
size_t integers_to_decode,
const void *source_as_void,
size_t source_length)
113 const uint8_t *source =
static_cast<const uint8_t *
>(source_as_void);
114 const uint8_t *end = source + source_length;
134 virtual void decode_with_writer(
size_t integers_to_decode,
const void *source_as_void,
size_t source_length)
136 const uint8_t *source =
static_cast<const uint8_t *
>(source_as_void);
137 const uint8_t *end = source + source_length;
163 if (value < ((uint64_t)1 << 7))
165 else if (value < ((uint64_t)1 << 14))
167 else if (value < ((uint64_t)1 << 21))
169 else if (value < ((uint64_t)1 << 28))
171 #if JASS_COMPRESS_INTEGER_BITS_PER_INTEGER == 32 175 else if (value < ((uint64_t)1 << 35))
177 else if (value < ((uint64_t)1 << 42))
179 else if (value < ((uint64_t)1 << 49))
181 else if (value < ((uint64_t)1 << 56))
183 else if (value < ((uint64_t)1 << 63))
199 template <
typename DESTINATION>
200 static forceinline
void compress_into(DESTINATION &destination, integer value)
205 if (value < ((uint64_t)1 << 7))
207 else if (value < ((uint64_t)1 << 14))
209 else if (value < ((uint64_t)1 << 21))
211 else if (value < ((uint64_t)1 << 28))
213 #if JASS_COMPRESS_INTEGER_BITS_PER_INTEGER == 32 216 else if (value < ((uint64_t)1 << 35))
218 else if (value < ((uint64_t)1 << 42))
220 else if (value < ((uint64_t)1 << 49))
222 else if (value < ((uint64_t)1 << 56))
224 else if (value < ((uint64_t)1 << 63))
233 #if JASS_COMPRESS_INTEGER_BITS_PER_INTEGER == 64 235 *destination = (value >> 63) & 0x7F;
238 *destination = (value >> 56) & 0x7F;
241 *destination = (value >> 49) & 0x7F;
244 *destination = (value >> 42) & 0x7F;
247 *destination = (value >> 35) & 0x7F;
251 *destination = (value >> 28) & 0x7F;
254 *destination = (value >> 21) & 0x7F;
257 *destination = (value >> 14) & 0x7F;
260 *destination = (value >> 7) & 0x7F;
263 *destination = (value & 0x7F) | 0x80;
277 template <
typename SOURCE>
285 *decoded = *source & 0x7F;
294 *decoded = (*decoded << 7) | (*source & 0x7F);
299 *decoded = (*decoded << 7) | *source;
303 *decoded = (*decoded << 7) | (*source & 0x7F);
308 *decoded = (*decoded << 7) | *source;
312 *decoded = (*decoded << 7) | (*source & 0x7F);
317 *decoded = (*decoded << 7) | *source;
321 *decoded = (*decoded << 7) | (*source & 0x7F);
326 #if JASS_COMPRESS_INTEGER_BITS_PER_INTEGER == 64 327 *decoded = (*decoded << 7) | *source;
331 *decoded = (*decoded << 7) | (*source & 0x7F);
336 *decoded = (*decoded << 7) | *source;
340 *decoded = (*decoded << 7) | (*source & 0x7F);
345 *decoded = (*decoded << 7) | *source;
349 *decoded = (*decoded << 7) | (*source & 0x7F);
354 *decoded = (*decoded << 7) | *source;
358 *decoded = (*decoded << 7) | (*source & 0x7F);
363 *decoded = (*decoded << 7) | *source;
367 *decoded = (*decoded << 7) | (*source & 0x7F);
372 *decoded = (*decoded << 7) | *source;
389 virtual long long compress(
unsigned char *destination,
long long destination_length, uint32_t *source,
long long source_integers)
391 return encode(destination, destination_length, source, source_integers);
394 virtual void decompress(uint32_t *destination,
unsigned char *source,
long long destination_integers)
static forceinline void decompress_into(integer *decoded, SOURCE &source)
Decode the given integer placing the encoding into destination (whose size is not validated)...
Definition: compress_integer_variable_byte.h:278
virtual size_t encode(void *encoded, size_t encoded_buffer_length, const integer *source, size_t source_integers)
Encode a sequence of integers returning the number of bytes used for the encoding, or 0 if the encoded sequence doesn't fit in the buffer.
Definition: compress_integer_variable_byte.cpp:20
Variable byte compression for integer sequences.
Definition: compress_integer_variable_byte.h:39
static void static_decode(integer *decoded, size_t integers_to_decode, const void *source_as_void, size_t source_length)
Decode a sequence of integers encoded with this codex.
Definition: compress_integer_variable_byte.h:111
static forceinline void compress_into(DESTINATION &destination, integer value)
Encode the given integer placing the encoding into destination (whose size is not validated)...
Definition: compress_integer_variable_byte.h:200
virtual void decode(integer *decoded, size_t integers_to_decode, const void *source, size_t source_length)
Decode a sequence of integers encoded with this codex.
Definition: compress_integer_variable_byte.h:92
Definition: compress.h:14
virtual ~compress_integer_variable_byte()
Constructor.
Definition: compress_integer_variable_byte.h:62
compress_integer_variable_byte()
Constructor.
Definition: compress_integer_variable_byte.h:50
static size_t bytes_needed_for(integer value)
Decode a sequence of integers encoded with this codex, calling add_rsv for each SIMD register...
Definition: compress_integer_variable_byte.h:158