6#include "BitIncrementIterator.h"
13std::vector<bool> &operator++(std::vector<bool> &vector) {
14 if (vector.empty())
return vector;
15 bool carry = vector[vector.size() - 1];
16 vector[vector.size() - 1] = !vector[vector.size() - 1];
17 for (
int i =
static_cast<int>(vector.size()) - 2; carry && i >= 0; i--) {
19 vector[i] = !vector[i];
24std::vector<bool> &operator--(std::vector<bool> &vector) {
25 if (vector.empty())
return vector;
26 bool carry = !vector[vector.size() - 1];
27 vector[vector.size() - 1] = !vector[vector.size() - 1];
28 for (
int i =
static_cast<int>(vector.size()) - 2; carry && i >= 0; i--) {
30 vector[i] = !vector[i];
36 : vector_{starting_value},
37 fixed_(starting_value.size(), false),
38 starting_vector_{starting_value},
39 ending_vector_{
std::move(starting_value)} {
51 for (
int i =
static_cast<int>(
vector_.size()) - 2; carry && i >= 0; i--) {
59const BitIncrementIterator BitIncrementIterator::operator++(
int) {
65BitIncrementIterator &BitIncrementIterator::operator--() {
73 for (
int i =
static_cast<int>(
vector_.size()) - 2; carry && i >= 0; i--) {
80const BitIncrementIterator BitIncrementIterator::operator--(
int) {
86bool BitIncrementIterator::operator[](
size_t i)
const {
return vector_[i]; }
89 if (
fixed_[i])
return false;
104 for (
size_t i = 0; i <
vector_.size(); i++) {
111 for (
size_t i = start_pos; i <
vector_.size(); i++) {
117 for (
int i =
static_cast<int>(start_pos); i >= 0; i--) {
123 for (
size_t i = 0; i <
vector_.size(); i++) {
142 std::copy(it->begin(), std::prev(it->end()), std::ostream_iterator<bool>(os,
", "));
143 return os << *(it->rbegin());
BitIncrementIterator class.
std::vector< bool > starting_vector_
Vector to store the starting value of the iterator.
void ResetNonFixedLeft(std::size_t start_pos)
Reset all the non-fixed bits to the left of start_pos to their starting value.
bool IsDone() const
Check if the iterator is done.
bool Learn(std::size_t i)
Learn the value of the bit at position i by inverting the bit.
void ResetNonFixedRight(std::size_t start_pos=0)
Reset all the non-fixed bits to the right of start_pos to their starting value.
void ResetNonFixed()
Reset all the non-fixed bits in the vector to their starting value.
std::vector< bool > ending_vector_
Vector to store the ending value of the iterator.
std::vector< bool > vector_
The bit vector that will assume all the possible values.
BitIncrementIterator(std::size_t n)
Construct a new BitIncrementIterator object.
void UpdateVector(std::size_t i, bool value)
After a Learn operation to set the i 'th bit to value, update the vector.
std::vector< bool > fixed_
Vector to indicate the fixed bits.
Global namespace for the dlinear library.