#include <genesis/utils/math/bitvector.hpp>
Definition at line 48 of file bitvector.hpp.
Public Member Functions | |
Bitvector ()=default | |
Default constructor. Creates an empty Bitvector of size 0. More... | |
Bitvector (Bitvector &&)=default | |
Bitvector (Bitvector const &)=default | |
Bitvector (Bitvector const &other, size_t max_size) | |
Create a Bitvector by copying the first max_size of another Bitvector. More... | |
Bitvector (size_t size, bool initial_value=false) | |
Constructor that takes a size and an optional bool value to initialize the Bitvector, false by default. More... | |
Bitvector (size_t size, std::initializer_list< size_t > list) | |
Constructor that takes a size and a list of values (positions) to be set to true. More... | |
Bitvector (std::string const &values) | |
Constructor that takes a std::string of 0 s and 1 s to build the Bitvector. More... | |
~Bitvector ()=default | |
size_t | count () const |
Count the number of set bits in the Bitvector, that is, its Hamming weight, or population count (popcnt). More... | |
std::vector< IntType > const & | data () const |
std::string | dump () const |
std::string | dump_int (IntType x) const |
void | flip (size_t index) |
Flip (negate) the value of a single bit, with boundary check. More... | |
bool | get (size_t index) const |
Return the value of a single bit, with boundary check. More... | |
size_t | hash () const |
Return an std::hash value for the Bitvector. More... | |
void | negate () |
Flip all bits. More... | |
void | normalize () |
Bring the Bitvector in a normalized form, where the first bit is always zero. More... | |
bool | operator!= (const Bitvector &other) const |
Bitvector & | operator&= (Bitvector const &rhs) |
Bitvector & | operator= (Bitvector &&)=default |
Bitvector & | operator= (Bitvector const &)=default |
bool | operator== (const Bitvector &other) const |
bool | operator[] (size_t index) const |
Return the value of a single bit, without boundary check. More... | |
Bitvector & | operator^= (Bitvector const &rhs) |
Bitvector & | operator|= (Bitvector const &rhs) |
Bitvector | operator~ () const |
void | set (size_t index) |
Set the value of a single bit to true, with boundary check. More... | |
void | set (size_t index, bool value) |
Set the value of a single bit to a given bool value, with boundary check. More... | |
void | set_all (const bool value=false) |
Set all the bits to a specified value . More... | |
size_t | size () const |
Return the size (number of bits) of this Bitvector. More... | |
void | unset (size_t index) |
Set the value of a single bit to false, with boundary check. More... | |
IntType | x_hash () const |
Return a hash value of type IntType that is quicker to calculate than hash(). More... | |
Public Types | |
using | IntType = uint64_t |
Static Public Attributes | |
static const size_t | IntSize = sizeof(IntType) * 8 |
Friends | |
Bitvector | operator& (Bitvector const &lhs, Bitvector const &rhs) |
Bitvector | operator^ (Bitvector const &lhs, Bitvector const &rhs) |
Bitvector | operator| (Bitvector const &lhs, Bitvector const &rhs) |
|
inline |
Constructor that takes a size and an optional bool value to initialize the Bitvector, false by default.
Definition at line 72 of file bitvector.hpp.
|
inline |
Constructor that takes a size and a list of values (positions) to be set to true.
Definition at line 83 of file bitvector.hpp.
Bitvector | ( | std::string const & | values | ) |
Constructor that takes a std::string
of 0
s and 1
s to build the Bitvector.
This is for cases where some fixed Bitvector needs to be constructed (e.g., for testing purposes). The constructor throws if any character in the string is not 0
or 1
.
Definition at line 93 of file bitvector.cpp.
Create a Bitvector by copying the first max_size
of another Bitvector.
If max_size > other.size()
, all max_size are used.
Definition at line 112 of file bitvector.cpp.
|
default |
size_t count | ( | ) | const |
Count the number of set bits in the Bitvector, that is, its Hamming weight, or population count (popcnt).
Definition at line 223 of file bitvector.cpp.
|
inline |
Definition at line 276 of file bitvector.hpp.
std::string dump | ( | ) | const |
Definition at line 327 of file bitvector.cpp.
std::string dump_int | ( | IntType | x | ) | const |
Definition at line 341 of file bitvector.cpp.
|
inline |
Flip (negate) the value of a single bit, with boundary check.
Definition at line 193 of file bitvector.hpp.
|
inline |
Return the value of a single bit, with boundary check.
Definition at line 130 of file bitvector.hpp.
size_t hash | ( | ) | const |
Return an std::hash value for the Bitvector.
Definition at line 252 of file bitvector.cpp.
void negate | ( | ) |
Flip all bits.
Definition at line 270 of file bitvector.cpp.
void normalize | ( | ) |
Bring the Bitvector in a normalized form, where the first bit is always zero.
If the first bit is zero, nothing happens. However, if is is one, the whole Bitvector is flipped using negate().
Definition at line 281 of file bitvector.cpp.
bool operator!= | ( | const Bitvector & | other | ) | const |
Definition at line 214 of file bitvector.cpp.
Definition at line 128 of file bitvector.cpp.
bool operator== | ( | const Bitvector & | other | ) | const |
Definition at line 201 of file bitvector.cpp.
|
inline |
Return the value of a single bit, without boundary check.
Definition at line 121 of file bitvector.hpp.
Definition at line 158 of file bitvector.cpp.
Definition at line 143 of file bitvector.cpp.
Bitvector operator~ | ( | ) | const |
Definition at line 173 of file bitvector.cpp.
|
inline |
Set the value of a single bit to true, with boundary check.
Definition at line 147 of file bitvector.hpp.
|
inline |
Set the value of a single bit to a given bool value, with boundary check.
Definition at line 181 of file bitvector.hpp.
void set_all | ( | const bool | value = false | ) |
Set all the bits to a specified value
.
Definition at line 288 of file bitvector.cpp.
|
inline |
Return the size (number of bits) of this Bitvector.
Definition at line 230 of file bitvector.hpp.
|
inline |
Set the value of a single bit to false, with boundary check.
Definition at line 164 of file bitvector.hpp.
Bitvector::IntType x_hash | ( | ) | const |
Return a hash value of type IntType that is quicker to calculate than hash().
This can be used for obtaining a simple hash using xor of the words. The avalanche effect is of course not present, but for many applications, this hash is good enough and quite useful.
Definition at line 261 of file bitvector.cpp.
Definition at line 180 of file bitvector.cpp.
Definition at line 194 of file bitvector.cpp.
Definition at line 187 of file bitvector.cpp.
using IntType = uint64_t |
Definition at line 56 of file bitvector.hpp.
|
static |
Definition at line 57 of file bitvector.hpp.