diff options
-rw-r--r-- | chilbert/detail/MultiBitVec.hpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/chilbert/detail/MultiBitVec.hpp b/chilbert/detail/MultiBitVec.hpp index 283601f..a184287 100644 --- a/chilbert/detail/MultiBitVec.hpp +++ b/chilbert/detail/MultiBitVec.hpp @@ -24,6 +24,7 @@ #include "chilbert/detail/BitVecMask.hpp" #include "chilbert/detail/operations.hpp" +#include <array> #include <cassert> #include <climits> #include <cstdint> @@ -366,15 +367,16 @@ template <class Derived> void gray_code_inv(MultiBitVec<Derived>& value) { - typename MultiBitVec<Derived>::Rack s = 0; + using Rack = typename MultiBitVec<Derived>::Rack; + + constexpr std::array<Rack, 2> masks{Rack{0}, ~Rack{0}}; + bool s = 0; for (size_t ri = 0; ri < value.num_racks(); ++ri) { const size_t i = value.num_racks() - ri - 1; auto& rack = value.rack(i); gray_code_inv(rack); - if (s) { - rack = ~rack; - } + rack ^= masks[s]; s = rack & 1; } } |