ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
StreamVByte.h File Reference

The Stream VByte code of Lemire, Kurz and Rupp for integers of 32 bits, beyond the variable-byte code of chapter 11, Integer Coding, of Ferragina's book [see IntegerCodes.h]: each integer takes 1 to 4 bytes, as many as its significant bytes, but the lengths are not in the bytes themselves (a flag bit per byte, which the decoder of decodeVByte() tests one byte at a time); they are apart, 2 bits per integer, 4 integers to a control byte, before all the bytes of the data. More...

#include "ADS/Contract.h"
#include "ADS/Simd.h"
#include <array>
#include <bit>
#include <cstddef>
#include <cstdint>
#include <span>
#include <utility>
#include <vector>
#include "ADS/compression/impl/StreamVByte.tpp"

Go to the source code of this file.

Namespaces

namespace  ADS

Functions

std::vector< std::uint8_t > ADS::streamVByteEncode (std::span< const std::uint32_t > x)
 the Stream VByte code of \( x \): the control bytes, then the data
std::vector< std::uint32_t > ADS::streamVByteDecode (std::span< const std::uint8_t > code, std::size_t n)
 the \( n \) integers of the Stream VByte code

Detailed description

The Stream VByte code of Lemire, Kurz and Rupp for integers of 32 bits, beyond the variable-byte code of chapter 11, Integer Coding, of Ferragina's book [see IntegerCodes.h]: each integer takes 1 to 4 bytes, as many as its significant bytes, but the lengths are not in the bytes themselves (a flag bit per byte, which the decoder of decodeVByte() tests one byte at a time); they are apart, 2 bits per integer, 4 integers to a control byte, before all the bytes of the data.

A decoder then reads a control byte and knows where the 4 integers start, with no test on the data: with ADS_WITH_HIGHWAY, on the vectors of the processor found at run time [see Simd.h], the 16 bytes from the place of the first integer are moved to their 4 places of 4 bytes, the missing high bytes made 0, by one shuffle of bytes whose mask is the entry of the control byte in a table of 256 masks, and the place moves by the sum of the 4 lengths, from a table too. The encoder finds the control bytes of 8 integers at once: each of their bytes made 0 or 1, each pair of bytes saturated to one byte, and a saturated addition that leaves the 2 bits of each integer in the top bits of its 2 bytes, which the mask of the top bits gathers; it moves the bytes of 4 integers together by the shuffle of the inverse table; the decoder takes 8 control bytes in a word and decodes 32 integers with no test while 12 more follow; elsewhere the integers are moved one at a time, still with no test. With \( \ell_i = \max( 1 , \lceil \mathrm{bitwidth}( x_i ) / 8 \rceil ) \) the bytes of \( x_i \), the code takes

\[ \lceil n / 4 \rceil + \sum_{i=0}^{n-1} \ell_i \]

bytes, i.e., the variable-byte code with 2 control bits per integer instead of 1 per byte.

The format: the \( \lceil n / 4 \rceil \) control bytes, the lengths less 1 of the integers \( 4 i \), \( 4 i + 1 \), \( 4 i + 2 \) and \( 4 i + 3 \) in the bits 0-1, 2-3, 4-5 and 6-7 of the byte \( i \), then the bytes of the integers, little-endian; \( n \) is not written, and the decoder takes it.

The contracts [see Contract.h]: the decoder gets the code of \( n \) integers. The functions are defined in StreamVByte.tpp.

See also
D. Lemire, N. Kurz, C. Rupp, Stream VByte: faster byte-oriented integer compression, Information Processing Letters 130, 1-6, 2018, doi:10.1016/j.ipl.2017.09.011
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa