|
ADS
Algorithms and Data Structures
|
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. More...
Files | |
| file | ADS/compression/StreamVByte.h |
| 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. | |
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 | |
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.
The definitions, the invariants and the costs of the area are in Theory of compression.
|
inlinenodiscard |
the \( n \) integers of the Stream VByte code
In pseudocode (Stream VByte, beyond the book), \( \mathit{shuffle}[ c ] \) and \( \mathit{len}[ c ] \) the mask and the total length of the control byte \( c \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{streamVByteDecode}( K \cdot D , n ) \cr 2 & \quad p \gets 0 \cr 3 & \quad \textbf{for}\ q \gets 0\ \textbf{to}\ \lceil n / 4 \rceil - 1 \ \textbf{do} \cr 4 & \qquad c \gets K[ q ] \cr 5 & \qquad ( x_{4 q} , \ldots , x_{4 q + 3} ) \gets \text{the bytes } D[ p .. p + 15 ] \text{ moved by } \mathit{shuffle}[ c ] \cr 6 & \qquad p \gets p + \mathit{len}[ c ] \cr 7 & \quad \textbf{return}\ x_0 \cdots x_{n-1} \end{array}} \]
Near the end of the data, where 16 bytes are not left, the integers are gathered one at a time from their lengths.
|
inlinenodiscard |
the Stream VByte code of \( x \): the control bytes, then the data
In pseudocode (Stream VByte of Lemire, Kurz and Rupp, beyond the book), one integer at a time, which the SIMD code does 8 at a time:
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{streamVByteEncode}( x_0 \cdots x_{n-1} ) \cr 2 & \quad K \gets \lceil n / 4 \rceil \text{ control bytes of } 0; \ D \gets \text{an empty string of bytes} \cr 3 & \quad \textbf{for}\ i \gets 0\ \textbf{to}\ n - 1\ \textbf{do} \cr 4 & \qquad \ell \gets \max( 1 , \lceil \mathrm{bitwidth}( x_i ) / 8 \rceil ) \cr 5 & \qquad K[ \lfloor i / 4 \rfloor ] \gets K[ \lfloor i / 4 \rfloor ] + ( \ell - 1 ) \cdot 4^{i \bmod 4} \cr 6 & \qquad \text{append the } \ell \text{ low bytes of } x_i \text{ to } D \cr 7 & \quad \textbf{return}\ K \cdot D \end{array}} \]