A toolkit for working with phylogenetic data.
v0.20.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Bitvector Class Reference

#include <genesis/utils/math/bitvector.hpp>

Detailed Description

Definition at line 46 of file bitvector.hpp.

Public Member Functions

 Bitvector ()=default
 Default constructor. Creates an empty Bitvector of size 0. More...
 
 Bitvector (const size_t size, const bool initial_value=false)
 Constructor that takes a size and an optional bool value to initialize the Bitvector, false by default. More...
 
 Bitvector (const size_t size, const std::initializer_list< int > list)
 Constructor that takes a size and a list of values (positions) to be set to true. More...
 
 Bitvector (Bitvector const &other, size_t bits)
 Create a Bitvector by copying the first bits of another Bitvector. More...
 
 Bitvector (Bitvector const &)=default
 
 Bitvector (Bitvector &&)=default
 
 ~Bitvector ()=default
 
size_t count () const
 Count the number of set bits in the Bitvector, that is, its Hamming weight. More...
 
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
 
Bitvectoroperator&= (Bitvector const &rhs)
 
Bitvectoroperator= (Bitvector const &)=default
 
Bitvectoroperator= (Bitvector &&)=default
 
bool operator== (const Bitvector &other) const
 
bool operator[] (size_t index) const
 Return the value of a single bit, without boundary check. More...
 
Bitvectoroperator^= (Bitvector const &rhs)
 
Bitvectoroperator|= (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

typedef uint64_t IntType
 

Static Public Attributes

static const size_t IntSize = sizeof(IntType) * 8
 

Constructor & Destructor Documentation

Bitvector ( )
default

Default constructor. Creates an empty Bitvector of size 0.

Bitvector ( const size_t  size,
const bool  initial_value = false 
)
inline

Constructor that takes a size and an optional bool value to initialize the Bitvector, false by default.

Definition at line 70 of file bitvector.hpp.

Bitvector ( const size_t  size,
const std::initializer_list< int >  list 
)
inline

Constructor that takes a size and a list of values (positions) to be set to true.

Definition at line 81 of file bitvector.hpp.

Bitvector ( Bitvector const &  other,
size_t  bits 
)
inline

Create a Bitvector by copying the first bits of another Bitvector.

If bits > other.size(), all bits are used.

Definition at line 94 of file bitvector.hpp.

~Bitvector ( )
default
Bitvector ( Bitvector const &  )
default
Bitvector ( Bitvector &&  )
default

Member Function Documentation

size_t count ( ) const

Count the number of set bits in the Bitvector, that is, its Hamming weight.

Definition at line 174 of file bitvector.cpp.

std::string dump ( ) const

Definition at line 278 of file bitvector.cpp.

std::string dump_int ( IntType  x) const

Definition at line 292 of file bitvector.cpp.

void flip ( size_t  index)
inline

Flip (negate) the value of a single bit, with boundary check.

Definition at line 173 of file bitvector.hpp.

bool get ( size_t  index) const
inline

Return the value of a single bit, with boundary check.

Definition at line 128 of file bitvector.hpp.

size_t hash ( ) const

Return an std::hash value for the Bitvector.

Definition at line 203 of file bitvector.cpp.

void negate ( )

Flip all bits.

Definition at line 224 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 235 of file bitvector.cpp.

bool operator!= ( const Bitvector other) const

Definition at line 165 of file bitvector.cpp.

Bitvector & operator&= ( Bitvector const &  rhs)

Definition at line 109 of file bitvector.cpp.

Bitvector& operator= ( Bitvector const &  )
default
Bitvector& operator= ( Bitvector &&  )
default
bool operator== ( const Bitvector other) const

Definition at line 152 of file bitvector.cpp.

bool operator[] ( size_t  index) const
inline

Return the value of a single bit, without boundary check.

Definition at line 121 of file bitvector.hpp.

Bitvector & operator^= ( Bitvector const &  rhs)

Definition at line 133 of file bitvector.cpp.

Bitvector & operator|= ( Bitvector const &  rhs)

Definition at line 121 of file bitvector.cpp.

Bitvector operator~ ( ) const

Definition at line 145 of file bitvector.cpp.

void set ( size_t  index)
inline

Set the value of a single bit to true, with boundary check.

Definition at line 139 of file bitvector.hpp.

void set ( size_t  index,
bool  value 
)
inline

Set the value of a single bit to a given bool value, with boundary check.

Definition at line 161 of file bitvector.hpp.

void set_all ( const bool  value = false)

Set all the bits to a specified value.

Definition at line 242 of file bitvector.cpp.

size_t size ( ) const
inline

Return the size (number of bits) of this Bitvector.

Definition at line 200 of file bitvector.hpp.

void unset ( size_t  index)
inline

Set the value of a single bit to false, with boundary check.

Definition at line 150 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 215 of file bitvector.cpp.

Member Typedef Documentation

typedef uint64_t IntType

Definition at line 54 of file bitvector.hpp.

Member Data Documentation

const size_t IntSize = sizeof(IntType) * 8
static

Definition at line 55 of file bitvector.hpp.


The documentation for this class was generated from the following files: