Quantum++
v1.2
A modern C++11 quantum computing library
|
Dynamic bitset class, allows the specification of the number of bits at runtime (unlike std::bitset<N>) More...
#include <classes/reversible.h>
Public Types | |
using | value_type = unsigned int |
Type of the storage elements. More... | |
using | storage_type = std::vector< value_type > |
Type of the storage. More... | |
Public Member Functions | |
Dynamic_bitset (idx N) | |
Constructor, initializes all bits to false (zero) More... | |
virtual | ~Dynamic_bitset ()=default |
Default virtual destructor. More... | |
const storage_type & | data () const |
Raw storage space of the bitset. More... | |
idx | size () const noexcept |
Number of bits stored in the bitset. More... | |
idx | storage_size () const noexcept |
Size of the underlying storage space (in units of value_type, unsigned int by default) More... | |
idx | count () const noexcept |
Number of bits set to one in the bitset (Hamming weight) More... | |
bool | get (idx pos) const noexcept |
The value of the bit at position pos. More... | |
bool | none () const noexcept |
Checks whether none of the bits are set. More... | |
bool | all () const noexcept |
Checks whether all bits are set. More... | |
bool | any () const noexcept |
Checks whether any bit is set. More... | |
Dynamic_bitset & | set (idx pos, bool value=true) |
Sets the bit at position pos. More... | |
Dynamic_bitset & | set () noexcept |
Set all bits to true. More... | |
Dynamic_bitset & | rand (idx pos, double p=0.5) |
Sets the bit at position pos according to a Bernoulli(p) distribution. More... | |
Dynamic_bitset & | rand (double p=0.5) |
Sets all bits according to a Bernoulli(p) distribution. More... | |
Dynamic_bitset & | reset (idx pos) |
Sets the bit at position pos to false. More... | |
Dynamic_bitset & | reset () noexcept |
Sets all bits to false. More... | |
Dynamic_bitset & | flip (idx pos) |
Flips the bit at position pos. More... | |
Dynamic_bitset & | flip () noexcept |
Flips all bits. More... | |
bool | operator== (const Dynamic_bitset &rhs) const noexcept |
Equality operator. More... | |
bool | operator!= (const Dynamic_bitset &rhs) const noexcept |
Inequality operator. More... | |
idx | operator- (const Dynamic_bitset &rhs) const noexcept |
Number of places the two bitsets differ (Hamming distance) More... | |
template<class CharT = char, class Traits = std::char_traits<CharT>, class Allocator = std::allocator<CharT>> | |
std::basic_string< CharT, Traits, Allocator > | to_string (CharT zero=CharT('0'), CharT one=CharT('1')) const |
String representation. More... | |
![]() | |
IDisplay ()=default | |
Default constructor. More... | |
IDisplay (const IDisplay &)=default | |
Default copy constructor. More... | |
IDisplay (IDisplay &&)=default | |
Default move constructor. More... | |
IDisplay & | operator= (const IDisplay &)=default |
Default copy assignment operator. More... | |
IDisplay & | operator= (IDisplay &&)=default |
Default move assignment operator. More... | |
virtual | ~IDisplay ()=default |
Default virtual destructor. More... | |
Protected Member Functions | |
idx | index_ (idx pos) const |
Index of the pos bit in the storage space. More... | |
idx | offset_ (idx pos) const |
Offset of the pos bit in the storage space relative to its index. More... | |
Protected Attributes | |
idx | storage_size_ |
Storage size. More... | |
idx | N_ |
Number of bits. More... | |
std::vector< value_type > | v_ |
Storage space. More... | |
Private Member Functions | |
std::ostream & | display (std::ostream &os) const override |
qpp::IDisplay::display() override, displays the bitset bit by bit More... | |
Dynamic bitset class, allows the specification of the number of bits at runtime (unlike std::bitset<N>)
using qpp::Dynamic_bitset::storage_type = std::vector<value_type> |
Type of the storage.
using qpp::Dynamic_bitset::value_type = unsigned int |
Type of the storage elements.
|
inlineexplicit |
Constructor, initializes all bits to false (zero)
N | Number of bits in the bitset |
|
virtualdefault |
Default virtual destructor.
|
inlinenoexcept |
Checks whether all bits are set.
|
inlinenoexcept |
Checks whether any bit is set.
|
inlinenoexcept |
Number of bits set to one in the bitset (Hamming weight)
|
inline |
Raw storage space of the bitset.
|
inlineoverrideprivatevirtual |
qpp::IDisplay::display() override, displays the bitset bit by bit
os | Output stream passed by reference |
Implements qpp::IDisplay.
|
inline |
Flips the bit at position pos.
pos | Position in the bitset |
|
inlinenoexcept |
Flips all bits.
|
inlinenoexcept |
The value of the bit at position pos.
pos | Position in the bitset |
Index of the pos bit in the storage space.
pos | Bit location |
|
inlinenoexcept |
Checks whether none of the bits are set.
Offset of the pos bit in the storage space relative to its index.
pos | Bit location |
|
inlinenoexcept |
Inequality operator.
rhs | Dynamic_bitset against which the inequality is being tested |
|
inlinenoexcept |
Number of places the two bitsets differ (Hamming distance)
rhs | Dynamic_bitset against which the the Hamming distance is computed |
|
inlinenoexcept |
Equality operator.
rhs | Dynamic_bitset against which the equality is being tested |
|
inline |
Sets the bit at position pos according to a Bernoulli(p) distribution.
pos | Position in the bitset |
p | Probability |
|
inline |
Sets all bits according to a Bernoulli(p) distribution.
p | Probability |
|
inline |
Sets the bit at position pos to false.
pos | Position in the bitset |
|
inlinenoexcept |
Sets all bits to false.
|
inline |
Sets the bit at position pos.
pos | Position in the bitset |
value | Bit value |
|
inlinenoexcept |
Set all bits to true.
|
inlinenoexcept |
Number of bits stored in the bitset.
|
inlinenoexcept |
Size of the underlying storage space (in units of value_type, unsigned int by default)
|
inline |
String representation.
CharT | String character type |
Traits | String traits |
Allocator | String Allocator |
zero | Character representing the zero |
one | Character representing the one |
|
protected |
Number of bits.
|
protected |
Storage size.
|
protected |
Storage space.