A library for working with phylogenetic and population genetic data.
v0.27.0
TwobitVector Class Reference

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

Detailed Description

Definition at line 41 of file twobit_vector.hpp.

Public Member Functions

 TwobitVector ()=default
 
 TwobitVector (size_t size)
 Constructor that initializes the vector with size many zero values. More...
 
 TwobitVector (TwobitVector &&)=default
 
 TwobitVector (TwobitVector const &)=default
 
 ~TwobitVector ()=default
 
void clear ()
 Clear the vector, so that it contains no data. More...
 
WordTypedata_at (size_t index)
 Return a single word of the vector. More...
 
WordType const & data_at (size_t index) const
 Return a single word of the vector. More...
 
size_t data_size () const
 Return the number of words (of type WordType) that are used to store the values in the vector. More...
 
ValueType get (size_t index) const
 Get the value at a position in the vector. More...
 
WordType hash () const
 Calculate a hash value of the vector, based on its size() and the xor of all its words. More...
 
void insert_at (size_t index, ValueType value)
 Insert a value at a position. More...
 
bool operator!= (TwobitVector const &other) const
 Inequality operator, opposite of operator==(). More...
 
TwobitVectoroperator= (TwobitVector &&)=default
 
TwobitVectoroperator= (TwobitVector const &)=default
 
bool operator== (TwobitVector const &other) const
 Equality operator. More...
 
ValueType operator[] (size_t index) const
 Alias for get(). More...
 
void remove_at (size_t index)
 Remove the value at a position. More...
 
void set (size_t index, ValueType value)
 Set a value at a position in the vector. More...
 
size_t size () const
 Return the size of the vector, that is, how many values (of type ValueType) it currently holds. More...
 
bool validate () const
 Validation function that checks some basic invariants. More...
 

Public Types

enum  ValueType : WordType { A = 0, C = 1, G = 2, T = 3 }
 Value Type enumeration for the elements of a TwobitVector. More...
 
using WordType = uint64_t
 Underlying word type for the bitvector. More...
 

Static Public Attributes

static const size_t kValuesPerWord = sizeof( WordType ) * 8 / 2
 Constant that holds the number of values (of tyoe ValueType) that are stored in a single word in the vector. More...
 

Constructor & Destructor Documentation

◆ TwobitVector() [1/4]

TwobitVector ( )
default

◆ TwobitVector() [2/4]

TwobitVector ( size_t  size)

Constructor that initializes the vector with size many zero values.

Definition at line 118 of file twobit_vector.cpp.

◆ ~TwobitVector()

~TwobitVector ( )
default

◆ TwobitVector() [3/4]

TwobitVector ( TwobitVector const &  )
default

◆ TwobitVector() [4/4]

TwobitVector ( TwobitVector &&  )
default

Member Function Documentation

◆ clear()

void clear ( )

Clear the vector, so that it contains no data.

Definition at line 405 of file twobit_vector.cpp.

◆ data_at() [1/2]

TwobitVector::WordType & data_at ( size_t  index)

Return a single word of the vector.

This is useful for external functions that want to directly work on the underlying bit representation.

Definition at line 187 of file twobit_vector.cpp.

◆ data_at() [2/2]

TwobitVector::WordType const & data_at ( size_t  index) const

Return a single word of the vector.

This is useful for external functions that want to directly work on the underlying bit representation.

Definition at line 176 of file twobit_vector.cpp.

◆ data_size()

size_t data_size ( ) const

Return the number of words (of type WordType) that are used to store the values in the vector.

Definition at line 140 of file twobit_vector.cpp.

◆ get()

TwobitVector::ValueType get ( size_t  index) const

Get the value at a position in the vector.

Definition at line 149 of file twobit_vector.cpp.

◆ hash()

Calculate a hash value of the vector, based on its size() and the xor of all its words.

This is a simple function, but might just be enough for using it in a hashmap.

Definition at line 198 of file twobit_vector.cpp.

◆ insert_at()

void insert_at ( size_t  index,
TwobitVector::ValueType  value 
)

Insert a value at a position.

The size() is increased by one.

Definition at line 290 of file twobit_vector.cpp.

◆ operator!=()

bool operator!= ( TwobitVector const &  other) const

Inequality operator, opposite of operator==().

Definition at line 230 of file twobit_vector.cpp.

◆ operator=() [1/2]

TwobitVector& operator= ( TwobitVector &&  )
default

◆ operator=() [2/2]

TwobitVector& operator= ( TwobitVector const &  )
default

◆ operator==()

bool operator== ( TwobitVector const &  other) const

Equality operator.

Definition at line 214 of file twobit_vector.cpp.

◆ operator[]()

TwobitVector::ValueType operator[] ( size_t  index) const

Alias for get().

Definition at line 165 of file twobit_vector.cpp.

◆ remove_at()

void remove_at ( size_t  index)

Remove the value at a position.

The size() is decreased by one.

Definition at line 342 of file twobit_vector.cpp.

◆ set()

void set ( size_t  index,
TwobitVector::ValueType  value 
)

Set a value at a position in the vector.

Definition at line 269 of file twobit_vector.cpp.

◆ size()

size_t size ( ) const

Return the size of the vector, that is, how many values (of type ValueType) it currently holds.

Definition at line 131 of file twobit_vector.cpp.

◆ validate()

bool validate ( ) const

Validation function that checks some basic invariants.

This is mainly useful in testing. The function checks whether the vector is correctly sized and contains zero padding at its end.

Definition at line 241 of file twobit_vector.cpp.

Member Typedef Documentation

◆ WordType

using WordType = uint64_t

Underlying word type for the bitvector.

We use 64bit words to store the 2bit values (of type ValueType), so that we get best speed on modern architectures.

Definition at line 55 of file twobit_vector.hpp.

Member Enumeration Documentation

◆ ValueType

enum ValueType : WordType
strong

Value Type enumeration for the elements of a TwobitVector.

The values 0-3 are named A, C, G and T, respectively, in order to ease the use with nucleotide sequences.

The underlying value of the enum is WordType, so that a cast does not need to convert internally.

Enumerator

Definition at line 66 of file twobit_vector.hpp.

Member Data Documentation

◆ kValuesPerWord

const size_t kValuesPerWord = sizeof( WordType ) * 8 / 2
static

Constant that holds the number of values (of tyoe ValueType) that are stored in a single word in the vector.

As we use 64bit words, this value is 32.

Definition at line 79 of file twobit_vector.hpp.


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