diff options
author | David Robillard <d@drobilla.net> | 2018-08-19 16:47:38 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2018-09-29 14:49:01 +0200 |
commit | 03f39c8be08d632d1f982f5ba5f2e95256be1122 (patch) | |
tree | 41ae78da247659bf8261bdd2397fadf32550d2d9 | |
parent | fa3d8f677b6a30c2115e7d167d4938e293dfad81 (diff) | |
download | chilbert-03f39c8be08d632d1f982f5ba5f2e95256be1122.tar.gz chilbert-03f39c8be08d632d1f982f5ba5f2e95256be1122.tar.bz2 chilbert-03f39c8be08d632d1f982f5ba5f2e95256be1122.zip |
Use consistent naming scheme
-rw-r--r-- | chilbert/BigBitVec.hpp | 8 | ||||
-rw-r--r-- | chilbert/FixBitVec.hpp | 8 | ||||
-rw-r--r-- | chilbert/GetBits.hpp | 4 | ||||
-rw-r--r-- | chilbert/GetLocation.hpp | 4 | ||||
-rw-r--r-- | chilbert/GrayCodeRank.hpp | 42 | ||||
-rw-r--r-- | chilbert/Hilbert.hpp | 40 | ||||
-rw-r--r-- | chilbert/Hilbert.ipp | 116 | ||||
-rw-r--r-- | chilbert/MultiBitVec.hpp | 10 | ||||
-rw-r--r-- | chilbert/Operations.hpp | 36 | ||||
-rw-r--r-- | chilbert/SetBits.hpp | 4 | ||||
-rw-r--r-- | chilbert/SetLocation.hpp | 4 | ||||
-rw-r--r-- | chilbert/StaticBitVec.hpp | 8 | ||||
-rw-r--r-- | test/test_bitvec.cpp | 10 | ||||
-rw-r--r-- | test/test_gray_code_rank.cpp | 16 | ||||
-rw-r--r-- | test/test_hilbert.cpp | 12 |
15 files changed, 161 insertions, 161 deletions
diff --git a/chilbert/BigBitVec.hpp b/chilbert/BigBitVec.hpp index 91a516d..be6e5e0 100644 --- a/chilbert/BigBitVec.hpp +++ b/chilbert/BigBitVec.hpp @@ -131,16 +131,16 @@ struct is_bitvec<CBigBitVec> template <> void -grayCode(CBigBitVec& value) +gray_code(CBigBitVec& value) { - grayCode(static_cast<MultiBitVec<CBigBitVec>&>(value)); + gray_code(static_cast<MultiBitVec<CBigBitVec>&>(value)); } template <> void -grayCodeInv(CBigBitVec& value) +gray_code_inv(CBigBitVec& value) { - grayCodeInv(static_cast<MultiBitVec<CBigBitVec>&>(value)); + gray_code_inv(static_cast<MultiBitVec<CBigBitVec>&>(value)); } } // namespace chilbert diff --git a/chilbert/FixBitVec.hpp b/chilbert/FixBitVec.hpp index 001e4c2..8cd3d72 100644 --- a/chilbert/FixBitVec.hpp +++ b/chilbert/FixBitVec.hpp @@ -245,7 +245,7 @@ public: /// Return 1 + the index of the first set bit, or 0 if there are none size_t find_first() const { - return static_cast<size_t>(chilbert::ffs(m_rack)); + return static_cast<size_t>(chilbert::find_first(m_rack)); } /// Return the number of set bits @@ -367,16 +367,16 @@ struct is_bitvec<CFixBitVec> template <> void -grayCode(CFixBitVec& value) +gray_code(CFixBitVec& value) { value.rack() ^= (value.rack() >> 1); } template <> void -grayCodeInv(CFixBitVec& value) +gray_code_inv(CFixBitVec& value) { - grayCodeInv<CFixBitVec::Rack>(value.rack()); + gray_code_inv<CFixBitVec::Rack>(value.rack()); } } // namespace chilbert diff --git a/chilbert/GetBits.hpp b/chilbert/GetBits.hpp index 288fd25..196751d 100644 --- a/chilbert/GetBits.hpp +++ b/chilbert/GetBits.hpp @@ -32,10 +32,10 @@ namespace chilbert { */ template <class H, class I> inline void -getBits(const H& h, const size_t n, const size_t i, I& w) +get_bits(const H& h, const size_t n, const size_t i, I& w) { for (size_t j = 0; j < n; j++) { - setBit(w, j, testBit(h, i + j)); + set_bit(w, j, test_bit(h, i + j)); } } diff --git a/chilbert/GetLocation.hpp b/chilbert/GetLocation.hpp index 816b7b7..3594c80 100644 --- a/chilbert/GetLocation.hpp +++ b/chilbert/GetLocation.hpp @@ -25,10 +25,10 @@ namespace chilbert { template <class P, class I> inline void -getLocation(const P* const p, const size_t n, const size_t i, I& l) +get_location(const P* const p, const size_t n, const size_t i, I& l) { for (size_t j = 0; j < n; ++j) { - setBit(l, j, testBit(p[j], i)); + set_bit(l, j, test_bit(p[j], i)); } } diff --git a/chilbert/GrayCodeRank.hpp b/chilbert/GrayCodeRank.hpp index 1e3895f..d7fbc77 100644 --- a/chilbert/GrayCodeRank.hpp +++ b/chilbert/GrayCodeRank.hpp @@ -31,17 +31,17 @@ namespace chilbert { // at each level of precision. template <class H, class HC> inline void -compactIndex(const size_t* const ms, - const size_t* const ds, - const size_t n, - const size_t m, - H& h, - HC& hc) +compact_index(const size_t* const ms, + const size_t* const ds, + const size_t n, + const size_t m, + H& h, + HC& hc) { assert(h.size() >= n * m); assert(hc.size() >= std::accumulate(ms, ms + n, size_t(0))); - resetBits(hc); + reset_bits(hc); auto hm = h.mask(0); auto hcm = hc.mask(0); @@ -69,7 +69,7 @@ compactIndex(const size_t* const ms, template <class I> inline void -grayCodeRank(const I& mask, const I& gi, const size_t n, I& r) +gray_code_rank(const I& mask, const I& gi, const size_t n, I& r) { assert(mask.size() == n); assert(gi.size() == n); @@ -93,13 +93,13 @@ grayCodeRank(const I& mask, const I& gi, const size_t n, I& r) template <class I> inline void -grayCodeRankInv(const I& mask, - const I& ptrn, - const I& r, - const size_t n, - const size_t b, - I& g, - I& gi) +gray_code_rank_inv(const I& mask, + const I& ptrn, + const I& r, + const size_t n, + const size_t b, + I& g, + I& gi) { assert(mask.size() == n); assert(ptrn.size() == n); @@ -147,12 +147,12 @@ grayCodeRankInv(const I& mask, template <class I> inline void -extractMask(const size_t* const ms, - const size_t n, - const size_t d, - const size_t i, - I& mask, - size_t& b) +extract_mask(const size_t* const ms, + const size_t n, + const size_t d, + const size_t i, + I& mask, + size_t& b) { assert(0 <= d && d < n); assert(mask.size() == n); diff --git a/chilbert/Hilbert.hpp b/chilbert/Hilbert.hpp index 5b4646d..80b0247 100644 --- a/chilbert/Hilbert.hpp +++ b/chilbert/Hilbert.hpp @@ -31,10 +31,10 @@ namespace chilbert { * @param[out] h Hilbert Index. */ template <class P, class H> -inline void coordsToIndex(const P* const p, - const size_t m, - const size_t n, - H& h); +inline void coords_to_index(const P* const p, + const size_t m, + const size_t n, + H& h); /** Map the Hilbert Index `p` to a point. * @@ -44,10 +44,10 @@ inline void coordsToIndex(const P* const p, * @param h Hilbert Index. */ template <class P, class H> -inline void indexToCoords(P* const p, - const size_t m, - const size_t n, - const H& h); +inline void index_to_coords(P* const p, + const size_t m, + const size_t n, + const H& h); /** Map the point `p` to a Compact Hilbert Index. * @@ -59,12 +59,12 @@ inline void indexToCoords(P* const p, * @param m Optional largest precision in `m`. */ template <class P, class H> -inline void coordsToCompactIndex(const P* const p, - const size_t* const ms, - const size_t n, - H& hc, - const size_t M = 0, - const size_t m = 0); +inline void coords_to_compact_index(const P* const p, + const size_t* const ms, + const size_t n, + H& hc, + const size_t M = 0, + const size_t m = 0); /** Map the Compact Hilbert Index `hc` to a point. * @@ -76,12 +76,12 @@ inline void coordsToCompactIndex(const P* const p, * @param m Optional largest precision in `m`. */ template <class P, class H> -inline void compactIndexToCoords(P* const p, - const size_t* const ms, - const size_t n, - const H& hc, - const size_t M = 0, - const size_t m = 0); +inline void compact_index_to_coords(P* const p, + const size_t* const ms, + const size_t n, + const H& hc, + const size_t M = 0, + const size_t m = 0); } // namespace chilbert diff --git a/chilbert/Hilbert.ipp b/chilbert/Hilbert.ipp index 726b204..66849ea 100644 --- a/chilbert/Hilbert.ipp +++ b/chilbert/Hilbert.ipp @@ -93,7 +93,7 @@ transform(const I& e, const size_t d, const size_t n, I& a) // Inverse 'transforms' a point. template <class I> inline void -transformInv(const I& e, const size_t d, const size_t n, I& a) +transform_inv(const I& e, const size_t d, const size_t n, I& a) { assert(a.size() == n); a.rotl(d); @@ -146,12 +146,12 @@ update2(const I& l, const I& t, const size_t n, I& e, size_t& d) template <class P, class H, class I> inline void -_coordsToIndex(const P* const p, - const size_t m, - const size_t n, - H& h, - I&& scratch, - size_t* const ds = nullptr // #HACK +_coords_to_index(const P* const p, + const size_t m, + const size_t n, + H& h, + I&& scratch, + size_t* const ds = nullptr // #HACK ) { I e{std::move(scratch)}; @@ -162,7 +162,7 @@ _coordsToIndex(const P* const p, // Initialize e.reset(); l.reset(); - resetBits(h); + reset_bits(h); // Work from MSB to LSB size_t d = D0; @@ -174,7 +174,7 @@ _coordsToIndex(const P* const p, } // Get corner of sub-hypercube where point lies. - getLocation<P, I>(p, n, static_cast<size_t>(i), l); + get_location<P, I>(p, n, static_cast<size_t>(i), l); // Mirror and reflect the location. // t = T_{(e,d)}(l) @@ -188,13 +188,13 @@ _coordsToIndex(const P* const p, // Concatenate to the index. ho -= n; - setBits<H, I>(h, n, ho, w); + set_bits<H, I>(h, n, ho, w); // Update the entry point and direction. update2<I>(l, t, n, e, d); } - grayCodeInv(h); + gray_code_inv(h); } // This is wrapper to the basic Hilbert curve index @@ -205,10 +205,10 @@ _coordsToIndex(const P* const p, // Assumes h is big enough for the output (n*m bits!) template <class P, class H> inline void -coordsToIndex(const P* const p, // [in ] point - const size_t m, // [in ] precision of each dimension in bits - const size_t n, // [in ] number of dimensions - H& h // [out] Hilbert index +coords_to_index(const P* const p, // [in ] point + const size_t m, // [in ] precision of each dimension in bits + const size_t n, // [in ] number of dimensions + H& h // [out] Hilbert index ) { assert(num_bits(h) >= n * m); @@ -216,16 +216,16 @@ coordsToIndex(const P* const p, // [in ] point if (n <= FBV_BITS) { // Intermediate variables will fit in fixed width - _coordsToIndex<P, H, CFixBitVec>(p, m, n, h, CFixBitVec(n)); + _coords_to_index<P, H, CFixBitVec>(p, m, n, h, CFixBitVec(n)); } else { // Otherwise, they must be BigBitVecs - _coordsToIndex<P, H, CBigBitVec>(p, m, n, h, CBigBitVec(n)); + _coords_to_index<P, H, CBigBitVec>(p, m, n, h, CBigBitVec(n)); } } template <class P, class H, class I> inline void -_indexToCoords(P* p, const size_t m, const size_t n, const H& h, I&& scratch) +_index_to_coords(P* p, const size_t m, const size_t n, const H& h, I&& scratch) { I e{std::move(scratch)}; I l{e}; @@ -236,7 +236,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++) { - resetBits(p[j]); + reset_bits(p[j]); } // Work from MSB to LSB @@ -245,20 +245,20 @@ _indexToCoords(P* p, const size_t m, const size_t n, const H& h, I&& scratch) for (intptr_t i = static_cast<intptr_t>(m - 1); i >= 0; i--) { // Get the Hilbert index bits ho -= n; - getBits<H, I>(h, n, ho, w); + get_bits<H, I>(h, n, ho, w); // t = GrayCode(w) t = w; - grayCode(t); + gray_code(t); // Reverse the transform // l = T^{-1}_{(e,d)}(t) l = t; - transformInv<I>(e, d, n, l); + transform_inv<I>(e, d, n, l); // Distribute these bits // to the coordinates. - setLocation<P, I>(p, n, static_cast<size_t>(i), l); + set_location<P, I>(p, n, static_cast<size_t>(i), l); // Update the entry point and direction. update1<I>(l, t, w, n, e, d); @@ -274,10 +274,10 @@ _indexToCoords(P* p, const size_t m, const size_t n, const H& h, I&& scratch) // appropriate variable. template <class P, class H> inline void -indexToCoords(P* const p, // [out] point - const size_t m, // [in ] precision of each dimension in bits - const size_t n, // [in ] number of dimensions - const H& h // [out] Hilbert index +index_to_coords(P* const p, // [out] point + const size_t m, // [in ] precision of each dimension in bits + const size_t n, // [in ] number of dimensions + const H& h // [out] Hilbert index ) { assert(m > 0); @@ -287,22 +287,22 @@ indexToCoords(P* const p, // [out] point if (n <= FBV_BITS) { // Intermediate variables will fit in fixed width - _indexToCoords<P, H, CFixBitVec>(p, m, n, h, CFixBitVec(n)); + _index_to_coords<P, H, CFixBitVec>(p, m, n, h, CFixBitVec(n)); } else { // Otherwise, they must be BigBitVecs - _indexToCoords<P, H, CBigBitVec>(p, m, n, h, CBigBitVec(n)); + _index_to_coords<P, H, CBigBitVec>(p, m, n, h, CBigBitVec(n)); } } template <class P, class HC, class I> inline void -_coordsToCompactIndex(const P* const p, - const size_t* const ms, - const size_t n, - HC& hc, - I&& scratch, - size_t M = 0, - size_t m = 0) +_coords_to_compact_index(const P* const p, + const size_t* const ms, + const size_t n, + HC& hc, + I&& scratch, + size_t M = 0, + size_t m = 0) { // Get total precision and max precision if not supplied if (M == 0 || m == 0) { @@ -327,12 +327,12 @@ _coordsToCompactIndex(const P* const p, if (mn > FBV_BITS) { CBigBitVec h(mn); - _coordsToIndex<P, CBigBitVec, I>(p, m, n, h, std::move(scratch), ds); - compactIndex<CBigBitVec, HC>(ms, ds, n, m, h, hc); + _coords_to_index<P, CBigBitVec, I>(p, m, n, h, std::move(scratch), ds); + compact_index<CBigBitVec, HC>(ms, ds, n, m, h, hc); } else { CFixBitVec h(mn); - _coordsToIndex<P, CFixBitVec, I>(p, m, n, h, std::move(scratch), ds); - compactIndex<CFixBitVec, HC>(ms, ds, n, m, h, hc); + _coords_to_index<P, CFixBitVec, I>(p, m, n, h, std::move(scratch), ds); + compact_index<CFixBitVec, HC>(ms, ds, n, m, h, hc); } delete[] ds; @@ -346,7 +346,7 @@ _coordsToCompactIndex(const P* const p, // Assumes h is big enough for the output (n*m bits!) template <class P, class HC> inline void -coordsToCompactIndex( +coords_to_compact_index( const P* const p, // [in ] point const size_t* const ms, // [in ] precision of each dimension in bits size_t n, // [in ] number of dimensions @@ -356,24 +356,24 @@ coordsToCompactIndex( { if (n <= FBV_BITS) { // Intermediate variables will fit in fixed width? - _coordsToCompactIndex<P, HC, CFixBitVec>( + _coords_to_compact_index<P, HC, CFixBitVec>( p, ms, n, hc, CFixBitVec(n), M, m); } else { // Otherwise, they must be BigBitVecs. - _coordsToCompactIndex<P, HC, CBigBitVec>( + _coords_to_compact_index<P, HC, CBigBitVec>( p, ms, n, hc, CBigBitVec(n), M, m); } } template <class P, class HC, class I> inline void -_compactIndexToCoords(P* const p, - const size_t* ms, - const size_t n, - const HC& hc, - I&& scratch, - size_t M, - size_t m) +_compact_index_to_coords(P* const p, + const size_t* ms, + const size_t n, + const HC& hc, + I&& scratch, + size_t M, + size_t m) { I e{std::move(scratch)}; I l{e}; @@ -411,7 +411,7 @@ _compactIndexToCoords(P* const p, for (intptr_t i = static_cast<intptr_t>(m - 1); i >= 0; i--) { // Get the mask and ptrn size_t b = 0; - extractMask<I>(ms, n, d, static_cast<size_t>(i), mask, b); + extract_mask<I>(ms, n, d, static_cast<size_t>(i), mask, b); ptrn = e; assert(ptrn.size() == n); ptrn.rotr(d); @@ -419,20 +419,20 @@ _compactIndexToCoords(P* const p, // Get the Hilbert index bits M -= b; r.reset(); // GetBits doesn't do this - getBits<HC, I>(hc, b, M, r); + get_bits<HC, I>(hc, b, M, r); // w = GrayCodeRankInv(r) // t = GrayCode(w) - grayCodeRankInv<I>(mask, ptrn, r, n, b, t, w); + gray_code_rank_inv<I>(mask, ptrn, r, n, b, t, w); // Reverse the transform // l = T^{-1}_{(e,d)}(t) l = t; - transformInv<I>(e, d, n, l); + transform_inv<I>(e, d, n, l); // Distribute these bits // to the coordinates. - setLocation<P, I>(p, n, static_cast<size_t>(i), l); + set_location<P, I>(p, n, static_cast<size_t>(i), l); // Update the entry point and direction. update1<I>(l, t, w, n, e, d); @@ -448,7 +448,7 @@ _compactIndexToCoords(P* const p, // appropriate variable. template <class P, class HC> inline void -compactIndexToCoords( +compact_index_to_coords( P* const p, // [out] point const size_t* ms, // [in ] precision of each dimension in bits const size_t n, // [in ] number of dimensions @@ -459,12 +459,12 @@ compactIndexToCoords( if (n <= FBV_BITS) { // Intermediate variables will fit in fixed width CFixBitVec scratch(n); - _compactIndexToCoords<P, HC, CFixBitVec>( + _compact_index_to_coords<P, HC, CFixBitVec>( p, ms, n, hc, std::move(scratch), M, m); } else { // Otherwise, they must be BigBitVecs CBigBitVec scratch(n); - _compactIndexToCoords<P, HC, CBigBitVec>( + _compact_index_to_coords<P, HC, CBigBitVec>( p, ms, n, hc, std::move(scratch), M, m); } } diff --git a/chilbert/MultiBitVec.hpp b/chilbert/MultiBitVec.hpp index 42b12c9..1401fd7 100644 --- a/chilbert/MultiBitVec.hpp +++ b/chilbert/MultiBitVec.hpp @@ -175,7 +175,7 @@ public: size_t find_first() const { for (size_t i = 0; i < num_racks(); ++i) { - const int j = ffs(rack(i)); + const int j = chilbert::find_first(rack(i)); if (j) { return (i * bits_per_rack) + static_cast<size_t>(j); } @@ -344,14 +344,14 @@ private: template <class Derived> void -grayCode(MultiBitVec<Derived>& value) +gray_code(MultiBitVec<Derived>& value) { typename MultiBitVec<Derived>::Rack s = 0; for (size_t ri = 0; ri < value.num_racks(); ++ri) { const size_t i = value.num_racks() - ri - 1; const auto t = value.rack(i) & 1; - grayCode(value.rack(i)); + gray_code(value.rack(i)); value.rack(i) ^= (s << (MultiBitVec<Derived>::bits_per_rack - 1)); s = t; } @@ -359,14 +359,14 @@ grayCode(MultiBitVec<Derived>& value) template <class Derived> void -grayCodeInv(MultiBitVec<Derived>& value) +gray_code_inv(MultiBitVec<Derived>& value) { typename MultiBitVec<Derived>::Rack 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); - grayCodeInv(rack); + gray_code_inv(rack); if (s) { rack = ~rack; } diff --git a/chilbert/Operations.hpp b/chilbert/Operations.hpp index 37a4b03..24474cc 100644 --- a/chilbert/Operations.hpp +++ b/chilbert/Operations.hpp @@ -33,7 +33,7 @@ namespace chilbert { /// Reset all bits in `field` template <typename T> std::enable_if_t<std::is_integral<T>::value> -resetBits(T& field) +reset_bits(T& field) { field = static_cast<T>(0); } @@ -41,7 +41,7 @@ resetBits(T& field) /// Reset all bits in `field` template <typename T> std::enable_if_t<is_bitvec_v<T>> -resetBits(T& field) +reset_bits(T& field) { field.reset(); } @@ -49,7 +49,7 @@ resetBits(T& field) /// Return the `index`th bit in `field` template <typename T> std::enable_if_t<std::is_integral<T>::value, bool> -testBit(const T& field, const size_t index) +test_bit(const T& field, const size_t index) { assert(size_t(index) < sizeof(field) * CHAR_BIT); return field & (T{1} << index); @@ -58,7 +58,7 @@ testBit(const T& field, const size_t index) /// Return the `index`th bit in `field` template <typename T> std::enable_if_t<is_bitvec_v<T>, bool> -testBit(const T& field, const size_t index) +test_bit(const T& field, const size_t index) { return field.test(index); } @@ -66,27 +66,27 @@ testBit(const T& field, const size_t index) /// Set the `index`th bit in `field` template <typename T> std::enable_if_t<std::is_integral<T>::value> -setBit(T& field, const size_t index) +set_bit(T& field, const size_t index) { assert(size_t(index) < sizeof(field) * CHAR_BIT); field |= (T{1} << index); - assert(testBit(field, index)); + assert(test_bit(field, index)); } /// Set the `index`th bit in `field` to `value` template <typename T> std::enable_if_t<std::is_integral<T>::value> -setBit(T& field, const size_t index, const bool value) +set_bit(T& field, const size_t index, const bool value) { assert(size_t(index) < sizeof(field) * CHAR_BIT); field ^= (-T{value} ^ field) & (T{1U} << index); - assert(testBit(field, index) == value); + assert(test_bit(field, index) == value); } /// Set the `index`th bit in `field` template <typename T> std::enable_if_t<is_bitvec_v<T>> -setBit(T& field, const size_t index) +set_bit(T& field, const size_t index) { field.set(index); } @@ -94,7 +94,7 @@ setBit(T& field, const size_t index) /// Set the `index`th bit in `field` to `value` template <typename T> std::enable_if_t<is_bitvec_v<T>> -setBit(T& field, const size_t index, const bool value) +set_bit(T& field, const size_t index, const bool value) { field.set(index, value); } @@ -119,42 +119,42 @@ pop_count<unsigned long long>(const unsigned long long& field) /// Return 1 + the index of the least significant 1-bit of `field`, or zero template <typename T> -int ffs(const T field); +int find_first(const T field); template <> int -ffs<unsigned long>(const unsigned long field) +find_first<unsigned long>(const unsigned long field) { return __builtin_ffsl(static_cast<long>(field)); } template <> int -ffs<unsigned long long>(const unsigned long long field) +find_first<unsigned long long>(const unsigned long long field) { return __builtin_ffsll(static_cast<long long>(field)); } /// Calculates the Gray Code of `value` in place template <typename T> -std::enable_if_t<is_bitvec_v<T>> grayCode(T& value); +std::enable_if_t<is_bitvec_v<T>> gray_code(T& value); /// Implementation of grayCode for any integral type template <typename T> std::enable_if_t<std::is_integral<T>::value> -grayCode(T& value) +gray_code(T& value) { value ^= (value >> 1); } /// Calculates the inverse Gray Code of `value` in place template <typename T> -std::enable_if_t<is_bitvec_v<T>> grayCodeInv(T& value); +std::enable_if_t<is_bitvec_v<T>> gray_code_inv(T& value); -/// Implementation of grayCodeInv for any integral type +/// Implementation of gray_code_inv for any integral type template <typename T> std::enable_if_t<std::is_integral<T>::value> -grayCodeInv(T& value) +gray_code_inv(T& value) { for (T shift = 1; shift < sizeof(T) * CHAR_BIT; shift <<= 1) { value ^= (value >> shift); diff --git a/chilbert/SetBits.hpp b/chilbert/SetBits.hpp index 0adbbf8..cc5d602 100644 --- a/chilbert/SetBits.hpp +++ b/chilbert/SetBits.hpp @@ -32,10 +32,10 @@ namespace chilbert { */ template <class H, class I> inline void -setBits(H& h, const size_t n, const size_t i, const I& w) +set_bits(H& h, const size_t n, const size_t i, const I& w) { for (size_t j = 0; j < n; j++) { - setBit(h, i + j, testBit(w, j)); + set_bit(h, i + j, test_bit(w, j)); } } diff --git a/chilbert/SetLocation.hpp b/chilbert/SetLocation.hpp index 47aa969..344c0f8 100644 --- a/chilbert/SetLocation.hpp +++ b/chilbert/SetLocation.hpp @@ -25,10 +25,10 @@ namespace chilbert { template <class P, class I> inline void -setLocation(P* const p, const size_t n, const size_t i, const I& l) +set_location(P* const p, const size_t n, const size_t i, const I& l) { for (size_t j = 0; j < n; j++) { - setBit(p[j], i, testBit(l, j)); + set_bit(p[j], i, test_bit(l, j)); } } diff --git a/chilbert/StaticBitVec.hpp b/chilbert/StaticBitVec.hpp index 1501746..64b8c99 100644 --- a/chilbert/StaticBitVec.hpp +++ b/chilbert/StaticBitVec.hpp @@ -95,16 +95,16 @@ struct is_bitvec<StaticBitVec<N>> template <size_t N> void -grayCode(StaticBitVec<N>& value) +gray_code(StaticBitVec<N>& value) { - grayCode(static_cast<MultiBitVec<StaticBitVec<N>>&>(value)); + gray_code(static_cast<MultiBitVec<StaticBitVec<N>>&>(value)); } template <size_t N> void -grayCodeInv(StaticBitVec<N>& value) +gray_code_inv(StaticBitVec<N>& value) { - grayCodeInv(static_cast<MultiBitVec<StaticBitVec<N>>&>(value)); + gray_code_inv(static_cast<MultiBitVec<StaticBitVec<N>>&>(value)); } } // namespace chilbert diff --git a/test/test_bitvec.cpp b/test/test_bitvec.cpp index b891aca..fdadb19 100644 --- a/test/test_bitvec.cpp +++ b/test/test_bitvec.cpp @@ -251,13 +251,13 @@ test_gray_code(Context& ctx) { const T v = make_random_bitvec<T, N>(ctx); T r = v; - grayCode(r); + gray_code(r); if (N > 0) { assert(N == 1 || r == (v ^ (v >> 1))); T s = r; - grayCodeInv(s); + gray_code_inv(s); assert(s == v); } } @@ -270,11 +270,11 @@ test_comparison(Context&) T b = make_zero_bitvec<T, N>(); for (size_t bit = 1; bit < N; ++bit) { - setBit(a, bit, 1); + set_bit(a, bit, 1); for (size_t i = 0; i < bit; ++i) { - setBit(a, i, rand() % 2 == 0); - setBit(b, i, rand() % 2 == 0); + set_bit(a, i, rand() % 2 == 0); + set_bit(b, i, rand() % 2 == 0); } assert(b < a); diff --git a/test/test_gray_code_rank.cpp b/test/test_gray_code_rank.cpp index 8be40f1..fa3fe3c 100644 --- a/test/test_gray_code_rank.cpp +++ b/test/test_gray_code_rank.cpp @@ -38,7 +38,7 @@ get_mask(const std::array<size_t, D>& ms, const size_t d, const size_t step) { T mask = make_zero_bitvec<T, D>(); size_t b; - chilbert::extractMask(ms.data(), D, d, step, mask, b); + chilbert::extract_mask(ms.data(), D, d, step, mask, b); assert(b == mask.count()); @@ -74,21 +74,21 @@ test_gray_code_rank(Context& ctx) const auto b = make_random_bitvec<T, D>(ctx); auto ga = a; - grayCode(ga); + gray_code(ga); auto gb = b; - grayCode(gb); + gray_code(gb); // Calculate gray code ranks auto ra = make_zero_bitvec<T, D>(); - chilbert::grayCodeRank(mask, ga, D, ra); + chilbert::gray_code_rank(mask, ga, D, ra); auto rb = make_zero_bitvec<T, D>(); - chilbert::grayCodeRank(mask, gb, D, rb); + chilbert::gray_code_rank(mask, gb, D, rb); // Ensure ranks have at most mask.count() bits auto max = make_zero_bitvec<T, D>(); - setBit(max, mask.count(), 1); + set_bit(max, mask.count(), 1); assert(ra < max); assert(rb < max); @@ -101,11 +101,11 @@ test_gray_code_rank(Context& ctx) const auto pat = ~mask; auto ga_out = make_zero_bitvec<T, D>(); auto gag_out = make_zero_bitvec<T, D>(); - grayCodeRankInv(mask, pat, ra, D, mask.count(), gag_out, ga_out); + gray_code_rank_inv(mask, pat, ra, D, mask.count(), gag_out, ga_out); assert((ga_out & mask) == (ga & mask)); auto gag_check = ga_out; - grayCode(gag_check); + gray_code(gag_check); assert(gag_check == gag_out); } } diff --git a/test/test_hilbert.cpp b/test/test_hilbert.cpp index 36a2992..0daf749 100644 --- a/test/test_hilbert.cpp +++ b/test/test_hilbert.cpp @@ -106,12 +106,12 @@ test_standard(Context& ctx) H ha = make_zero_bitvec<H, D * M>(); assert(ha.size() >= D * M); - chilbert::coordsToIndex(pa.data(), M, D, ha); + chilbert::coords_to_index(pa.data(), M, D, ha); { // Ensure unmapping results in the original point auto pa_out = make_random_point<M, D>(ctx); - chilbert::indexToCoords(pa_out.data(), M, D, ha); + chilbert::index_to_coords(pa_out.data(), M, D, ha); assert(pa_out == pa); } @@ -124,7 +124,7 @@ test_standard(Context& ctx) // Unmap next hilbert index to a point auto pb = make_random_point<M, D>(ctx); - chilbert::indexToCoords(pb.data(), M, D, hb); + chilbert::index_to_coords(pb.data(), M, D, hb); // Ensure next point is 1 unit of distance away from first assert(squared_distance(pa, pb) == 1); @@ -142,12 +142,12 @@ test_compact(Context& ctx) T ha = make_zero_bitvec<T, D * M>(); assert(ha.size() >= D * M); - chilbert::coordsToCompactIndex(pa.data(), ms.data(), D, ha); + chilbert::coords_to_compact_index(pa.data(), ms.data(), D, ha); { // Ensure unmapping results in the original point auto pa_out = make_random_point<M, D>(ctx); - chilbert::compactIndexToCoords(pa_out.data(), ms.data(), D, ha); + chilbert::compact_index_to_coords(pa_out.data(), ms.data(), D, ha); assert(pa_out == pa); } @@ -160,7 +160,7 @@ test_compact(Context& ctx) // Unmap next hilbert index to a point auto pb = make_random_point<M, D>(ctx); - chilbert::compactIndexToCoords(pb.data(), ms.data(), D, hb); + chilbert::compact_index_to_coords(pb.data(), ms.data(), D, hb); // Ensure next point is 1 unit of distance away from first assert(squared_distance(pa, pb) == 1); |