diff options
author | David Robillard <d@drobilla.net> | 2018-08-18 17:40:30 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2018-09-29 14:47:01 +0200 |
commit | faa5c52caaa74761dd5e0078b5472da202e955ec (patch) | |
tree | f2971ec6ae00a3a5355f4616cbbe0a62a64fe3f2 | |
parent | ad4f4edefc5da702e9efa4ec7b40830e91abb6cf (diff) | |
download | chilbert-faa5c52caaa74761dd5e0078b5472da202e955ec.tar.gz chilbert-faa5c52caaa74761dd5e0078b5472da202e955ec.tar.bz2 chilbert-faa5c52caaa74761dd5e0078b5472da202e955ec.zip |
Remove problematic conversion operators
-rw-r--r-- | chilbert/BigBitVec.hpp | 45 | ||||
-rw-r--r-- | chilbert/FixBitVec.hpp | 6 | ||||
-rw-r--r-- | chilbert/GrayCodeRank.hpp | 2 | ||||
-rw-r--r-- | chilbert/Hilbert.ipp | 4 | ||||
-rw-r--r-- | chilbert/Operations.hpp | 16 |
5 files changed, 36 insertions, 37 deletions
diff --git a/chilbert/BigBitVec.hpp b/chilbert/BigBitVec.hpp index dcc2c99..ea2d7bf 100644 --- a/chilbert/BigBitVec.hpp +++ b/chilbert/BigBitVec.hpp @@ -36,12 +36,18 @@ namespace chilbert { class CBigBitVec { public: - CBigBitVec(const size_t bits = 0) + explicit CBigBitVec(const size_t bits) : m_pcRacks{make_racks(FBVS_NEEDED(bits))} , m_iRacks{bits == 0 ? 0 : FBVS_NEEDED(bits)} { } + CBigBitVec(const size_t bits, const FBV_UINT value) + : CBigBitVec{bits} + { + m_pcRacks[0] = value; + } + CBigBitVec(const CBigBitVec& vec) : m_pcRacks{make_racks(vec.m_iRacks)} , m_iRacks{vec.m_iRacks} @@ -55,27 +61,20 @@ public: CBigBitVec(CBigBitVec&& vec) = default; - CBigBitVec(const CFixBitVec& vec) - : m_pcRacks{make_racks(1)} - , m_iRacks{1} - { - m_pcRacks[0] = vec.rack(); - } - /// Return the size in bits size_t size() const { return m_iRacks * FBV_BITS; } /// Set all bits to zero CBigBitVec& reset() { - memset(m_pcRacks.get(), 0, sizeof(CFixBitVec) * m_iRacks); + memset(m_pcRacks.get(), 0, sizeof(FBV_UINT) * m_iRacks); return *this; } /// Set all bits to one CBigBitVec& set() { - memset(m_pcRacks.get(), 0xFF, sizeof(CFixBitVec) * m_iRacks); + memset(m_pcRacks.get(), 0xFF, sizeof(FBV_UINT) * m_iRacks); return *this; } @@ -131,12 +130,12 @@ public: m_pcRacks = make_racks(m_iRacks); memcpy(m_pcRacks.get(), vec.m_pcRacks.get(), - sizeof(CFixBitVec) * m_iRacks); + sizeof(FBV_UINT) * m_iRacks); } else if (vec.m_iRacks > 0) { m_iRacks = vec.m_iRacks; memcpy(m_pcRacks.get(), vec.m_pcRacks.get(), - sizeof(CFixBitVec) * m_iRacks); + sizeof(FBV_UINT) * m_iRacks); } else { m_iRacks = 0; m_pcRacks.reset(); @@ -147,28 +146,6 @@ public: CBigBitVec& operator=(CBigBitVec&& vec) = default; - CBigBitVec& operator=(const CFixBitVec& vec) - { - if (!m_pcRacks) { - m_pcRacks = make_racks(1); - } - - m_iRacks = 1; - m_pcRacks[0] = vec.rack(); - return *this; - } - - CBigBitVec& operator=(const FBV_UINT j) - { - if (!m_pcRacks) { - m_pcRacks = make_racks(1); - } - - m_iRacks = 1; - m_pcRacks[0] = j; - return *this; - } - /// Return the value of the `index`th bit bool test(const size_t index) const { diff --git a/chilbert/FixBitVec.hpp b/chilbert/FixBitVec.hpp index 289334a..610119f 100644 --- a/chilbert/FixBitVec.hpp +++ b/chilbert/FixBitVec.hpp @@ -49,6 +49,12 @@ public: assert(bits <= FBV_BITS); } + CFixBitVec(const size_t bits, const FBV_UINT value) + : m_rack{value} + { + assert(bits <= FBV_BITS); + } + /// Return the size in bits size_t size() const { return FBV_BITS; } diff --git a/chilbert/GrayCodeRank.hpp b/chilbert/GrayCodeRank.hpp index 7bbfa69..60e644a 100644 --- a/chilbert/GrayCodeRank.hpp +++ b/chilbert/GrayCodeRank.hpp @@ -46,7 +46,7 @@ compactIndex(const size_t* const ms, H& h, HC& hc) { - hc = 0; + resetBits(hc); size_t hi = 0; size_t hci = 0; diff --git a/chilbert/Hilbert.ipp b/chilbert/Hilbert.ipp index 4cf5fec..523bfec 100644 --- a/chilbert/Hilbert.ipp +++ b/chilbert/Hilbert.ipp @@ -152,7 +152,7 @@ _coordsToIndex(const P* const p, // Initialize e.reset(); l.reset(); - h.reset(); + resetBits(h); // Work from MSB to LSB size_t d = D0; @@ -226,7 +226,7 @@ _indexToCoords(P* p, const size_t m, const size_t n, const H& h, I&& scratch) e.reset(); l.reset(); for (size_t j = 0; j < n; j++) { - p[j] = 0U; + resetBits(p[j]); } // Work from MSB to LSB diff --git a/chilbert/Operations.hpp b/chilbert/Operations.hpp index 5781e6c..3b9dd53 100644 --- a/chilbert/Operations.hpp +++ b/chilbert/Operations.hpp @@ -35,6 +35,22 @@ using IntegralIndex = std::enable_if_t<std::is_integral<T>::value, size_t>; template <typename T> using BitsetIndex = std::enable_if_t<!std::is_integral<T>::value, size_t>; +/// Reset all bits in `field` +template <typename T> +std::enable_if_t<std::is_integral<T>::value> +resetBits(T& field) +{ + field = static_cast<T>(0); +} + +/// Reset all bits in `field` +template <typename T> +std::enable_if_t<!std::is_integral<T>::value> +resetBits(T& field) +{ + field.reset(); +} + /// Return the `index`th bit in `field` template <typename T> bool |