Sux
|
Namespaces | |
bits | |
function | |
util | |
Classes | |
class | Rank |
class | Select |
class | SelectZero |
Typedefs | |
using | auint64_t = std::uint64_t __attribute__((__may_alias__)) |
using | auint32_t = std::uint32_t __attribute__((__may_alias__)) |
using | auint16_t = std::uint16_t __attribute__((__may_alias__)) |
using | auint8_t = std::uint8_t __attribute__((__may_alias__)) |
Functions | |
constexpr size_t | ceil_log2_plus1 (size_t n) |
int | ceil_log2 (const uint64_t x) |
constexpr uint64_t | round_pow2 (uint64_t v) |
int | rho (uint64_t word) |
int | lambda (uint64_t word) |
int | lambda_safe (uint64_t word) |
uint64_t | clear_rho (uint64_t word) |
uint64_t | mask_rho (uint64_t word) |
uint64_t | mask_lambda (uint64_t word) |
uint64_t | compact_bitmask (size_t count, size_t pos) |
uint64_t | bitextract (const uint64_t *word, int from, int length) |
uint64_t | byteread (const void *const word, int length) |
void | bytewrite (void *const word, int length, uint64_t val) |
void | bytewrite_inc (void *const word, uint64_t inc) |
uint64_t | bitread (const void *const word, int from, int length) |
void | bitwrite (void *word, int from, int length, uint64_t val) |
void | bitwrite_inc (void *const word, int from, int length, uint64_t inc) |
int | nu (uint64_t word) |
uint64_t | mround (uint64_t number, uint64_t multiple) |
size_t | updroot (size_t j, size_t n) |
uint64_t | select64 (uint64_t x, uint64_t k) |
bool | is_big_endian (void) |
bool | is_little_endian (void) |
template<class T > | |
std::enable_if< std::is_integral< T >::value, T >::type | swap_endian (T value) |
template<class T > | |
T | hton (T value) |
template<class T > | |
T | ntoh (T value) |
template<class T > | |
T | ltoh (T value) |
template<class T > | |
T | htol (T value) |
Variables | |
constexpr uint8_t | kSelectInByte [2048] |
using sux::auint16_t = typedef std::uint16_t __attribute__((__may_alias__)) |
using sux::auint32_t = typedef std::uint32_t __attribute__((__may_alias__)) |
using sux::auint64_t = typedef std::uint64_t __attribute__((__may_alias__)) |
Aliased unsigned integers
Strict aliasing rule: it's illegal to access the same memory location with data of different types. If you have two pointers T* and a U*, the compiler can assume they are not pointing the same data. Accessing such a data invokes undefined behavior.
GCC may_alias attribute is basically the opposite of the C restrict
keyword: it prevents the compiler to make strict aliasing assumptions. With these aliased types is now valid to access aliased pointers. [1]
[1] https://gcc.gnu.org/onlinedocs/gcc-8.2.0/gcc/Common-Type-Attributes.html
using sux::auint8_t = typedef std::uint8_t __attribute__((__may_alias__)) |
|
inline |
Extract consecutives bits in a word.
word | binary word. |
from | starting index (up to 63). |
length | length of the word (up to 64). |
Extracts from word
the bits in the range [from, from + length)
and returns them in the least significant bits of the result.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
log2 rounded up.
|
constexpr |
Static (i.e. computed in compile time) 1 + log2 rounded up.
|
inline |
Set to 0 the least significant 1-bit in a word.
word | binary word. |
|
inline |
Generate a compact bitmask.
count | quantity of set bit. |
pos | starting position. |
This fucntion returns a bitmask with count
1-bits: every bit from pos
to pos+count
is set to one. If pos
is zero the bitmask has its count
least significant bits setted to one.
T sux::htol | ( | T | value | ) |
Host endianness to little endian converter
value | integral value |
T sux::hton | ( | T | value | ) |
Host to network endianness converter
value | integral value |
|
inline |
Check if the architecture is big endian
|
inline |
Check if the architecture is little endian
|
inline |
Find the index of the most significant 1-bit in a word.
word | binary word. |
The Knuth's lambda function is the dual of the rho function.
The behavior in zero is undefined.
|
inline |
Find the index of the most significant 1-bit in a word.
word | binary word. |
The Knuth's lambda function is the dual of the rho function.
Returns -1 on input zero.
T sux::ltoh | ( | T | value | ) |
Little endian to host endianness converter
value | integral value |
|
inline |
Bitmask where only the most significant 1-bit is set.
word | Binary word. |
Undefined behavior when word
is zero.
|
inline |
Bitmask where only the least significant 1-bit is set.
word | Binary word. |
Compute 2^rho(word)
for any word
that is not zero.
|
inline |
Return a number rounded to the desired power of two multiple.
number | value to round up. |
multiple | power of two to which you want to round number . |
T sux::ntoh | ( | T | value | ) |
Network to host endianness converter
value | integral value |
|
inline |
Count the number of 1-bits in a word.
word | binary word. |
|
inline |
Find the index of the least significant 1-bit in a word.
word | binary word. |
The Knuth's ruler function returns the number of trailing 0-bits in word
starting from the least significant position. It returns 0 when word
is 2^0 and it returns 63 when it is 2^63.
The behavior in zero is undefined.
|
constexpr |
Static round up to the next highest power of two.
v | value to round up. |
The algorithm is a well known bit hack [1].
[1] https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
|
inline |
Returns the index of the k-th 1-bit in the 64-bit word x.
x | 64-bit word. |
k | 0-based rank (k = 0 returns the position of the first 1-bit). |
Uses the broadword selection algorithm by Vigna [1], improved by Gog and Petri [2] and Vigna [3]. Facebook's Folly implementation [4].
[1] Sebastiano Vigna. Broadword Implementation of Rank/Select Queries. WEA, 2008
[2] Simon Gog, Matthias Petri. Optimized succinct data structures for massive data. Softw. Pract. Exper., 2014
[3] Sebastiano Vigna. MG4J 5.2.1. http://mg4j.di.unimi.it/
[4] Facebook Folly library: https://github.com/facebook/folly
std::enable_if<std::is_integral<T>::value, T>::type sux::swap_endian | ( | T | value | ) |
Transform from big-endian to little-endian and vice versa
value | integral value (sizeof 1, 2, 4 or 8 bytes) |
|
inline |
Grandest grandparent parent of a node in the update tree.
j | index of a node. |
n | size of the Fenwick tree. |
|
constexpr |