32 #ifndef EXPERIMENTAL_EXPERIMENTAL_H_ 33 #define EXPERIMENTAL_EXPERIMENTAL_H_ 43 using idx = std::size_t;
50 namespace experimental {
63 std::vector<value_type>
v_;
86 : storage_size_{N / (
sizeof(
value_type) * CHAR_BIT) + 1}, N_{N},
117 std::size_t result = 0;
118 for (
idx i = 0; i <
size(); ++i) {
155 bool all() const noexcept {
171 bool any() const noexcept {
return !(this->
none()); }
211 std::random_device rd;
212 std::mt19937 gen{rd()};
213 std::bernoulli_distribution d{p};
215 this->
set(pos, d(gen));
227 for (
idx i = 0; i <
size(); ++i) {
291 assert(this->
size() == rhs.size());
294 for (
idx i = 0; i < n; ++i) {
295 if (v_[i] != rhs.v_[i]) {
309 return !(*
this == rhs);
321 for (
idx i = rhs.
size(); i-- > 0;) {
337 template <
class CharT =
char,
class Traits = std::
char_traits<CharT>,
338 class Allocator = std::allocator<CharT>>
339 std::basic_string<CharT, Traits, Allocator>
340 to_string(CharT zero = CharT(
'0'), CharT one = CharT(
'1'))
const {
341 std::basic_string<CharT, Traits, Allocator> result;
342 idx bitset_size = this->
size();
343 result.resize(bitset_size);
345 for (
idx i = bitset_size; i-- > 0;) {
347 result[bitset_size - i - 1] = zero;
349 result[bitset_size - i - 1] = one;
418 if (this->
get(pos[0]) != this->
get(pos[1])) {
429 if (this->
get(pos[0])) {
430 this->SWAP({pos[1], pos[2]});
439 gate_count.
NOT = gate_count.
X = 0;
440 gate_count.
CNOT = gate_count.
SWAP = 0;
441 gate_count.
FRED = gate_count.
TOF = 0;
bool all() const noexcept
Definition: experimental.h:155
Dynamic_bitset & rand(double p=0.5)
Definition: experimental.h:226
std::vector< value_type > v_
Storage space.
Definition: experimental.h:63
bool operator==(const Dynamic_bitset &rhs) const noexcept
Definition: experimental.h:290
friend std::ostream & operator<<(std::ostream &os, const Dynamic_bitset &rhs)
Definition: experimental.h:319
Bit_circuit & SWAP(const std::vector< idx > &pos)
Definition: experimental.h:417
Bit_circuit & X(idx pos)
Definition: experimental.h:382
idx N_
Number of bits.
Definition: experimental.h:62
Bit_circuit & TOF(const std::vector< idx > &pos)
Definition: experimental.h:407
Definition: experimental.h:364
Bit_circuit & FRED(const std::vector< idx > &pos)
Definition: experimental.h:428
Quantum++ main namespace.
Definition: codes.h:35
idx storage_size_
Storage size.
Definition: experimental.h:61
idx storage_size() const
Size of the underlying storage space (in units of value_type, unsigned int by default) ...
Definition: experimental.h:108
Dynamic_bitset & flip(idx pos)
Definition: experimental.h:265
Definition: experimental.h:361
Definition: experimental.h:56
Bit_circuit & NOT(idx pos)
Definition: experimental.h:390
Dynamic_bitset & reset(idx pos)
Definition: experimental.h:240
Bit_circuit & reset() noexcept
Definition: experimental.h:438
bool any() const noexcept
Definition: experimental.h:171
std::size_t idx
Definition: experimental.h:43
bool get(idx pos) const
Definition: experimental.h:132
unsigned int value_type
Type of the storage elements.
Definition: experimental.h:58
Bit_circuit & CNOT(const std::vector< idx > &pos)
Definition: experimental.h:398
bool operator!=(const Dynamic_bitset &rhs) const noexcept
Definition: experimental.h:308
idx count() const noexcept
Definition: experimental.h:116
bool none() const noexcept
Definition: experimental.h:139
Dynamic_bitset & rand(idx pos, double p=0.5)
Definition: experimental.h:210
idx size() const
Number of bits stored in the bitset.
Definition: experimental.h:101
Dynamic_bitset & flip() noexcept
Definition: experimental.h:276
std::size_t idx
Non-negative integer index.
Definition: types.h:39
Dynamic_bitset & reset() noexcept
Definition: experimental.h:251
idx offset_(idx pos) const
Offset of the pos bit in the storage space relative to its index.
Definition: experimental.h:78
idx index_(idx pos) const
Index of the pos bit in the storage space.
Definition: experimental.h:70
Dynamic_bitset(idx N)
Constructor, initializes all bits to false (zero)
Definition: experimental.h:85
const storage_type & data() const
Raw storage space of the bitset.
Definition: experimental.h:95
std::basic_string< CharT, Traits, Allocator > to_string(CharT zero=CharT('0'), CharT one=CharT('1')) const
Definition: experimental.h:340
std::vector< value_type > storage_type
Type of the storage.
Definition: experimental.h:59