diff options
author | David Robillard <d@drobilla.net> | 2018-08-19 18:22:26 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2018-09-29 14:50:07 +0200 |
commit | ac65326242af579d6e1a7bd71730f1c78c8bde9b (patch) | |
tree | ae5225c4b9856b3e5d454378d00867d9b0c53d26 | |
parent | 7567f77828ff9661f85eabe3b4cfb1876b307d42 (diff) | |
download | chilbert-ac65326242af579d6e1a7bd71730f1c78c8bde9b.tar.gz chilbert-ac65326242af579d6e1a7bd71730f1c78c8bde9b.tar.bz2 chilbert-ac65326242af579d6e1a7bd71730f1c78c8bde9b.zip |
Reorganize headers to make a clear public/private distinction
-rw-r--r-- | chilbert/BoundedBitVec.hpp | 25 | ||||
-rw-r--r-- | chilbert/DynamicBitVec.hpp | 16 | ||||
-rw-r--r-- | chilbert/SmallBitVec.hpp | 13 | ||||
-rw-r--r-- | chilbert/StaticBitVec.hpp | 20 | ||||
-rw-r--r-- | chilbert/chilbert.hpp (renamed from chilbert/Hilbert.hpp) | 2 | ||||
-rw-r--r-- | chilbert/chilbert.ipp (renamed from chilbert/Hilbert.ipp) | 4 | ||||
-rw-r--r-- | chilbert/detail/BitVecIndex.hpp (renamed from chilbert/BitVecIndex.hpp) | 2 | ||||
-rw-r--r-- | chilbert/detail/BitVecIterator.hpp (renamed from chilbert/BitVecIterator.hpp) | 4 | ||||
-rw-r--r-- | chilbert/detail/BitVecMask.hpp (renamed from chilbert/BitVecMask.hpp) | 2 | ||||
-rw-r--r-- | chilbert/detail/MultiBitVec.hpp (renamed from chilbert/MultiBitVec.hpp) | 12 | ||||
-rw-r--r-- | chilbert/detail/gray_code_rank.hpp (renamed from chilbert/GrayCodeRank.hpp) | 2 | ||||
-rw-r--r-- | chilbert/detail/operations.hpp (renamed from chilbert/Operations.hpp) | 6 | ||||
-rw-r--r-- | chilbert/detail/traits.hpp (renamed from chilbert/Traits.hpp) | 2 | ||||
-rw-r--r-- | chilbert/operators.hpp (renamed from chilbert/Operators.hpp) | 4 | ||||
-rw-r--r-- | test/test_bitvec.cpp | 10 | ||||
-rw-r--r-- | test/test_gray_code_rank.cpp | 19 | ||||
-rw-r--r-- | test/test_hilbert.cpp | 2 |
17 files changed, 92 insertions, 53 deletions
diff --git a/chilbert/BoundedBitVec.hpp b/chilbert/BoundedBitVec.hpp index 79912cc..fa414ca 100644 --- a/chilbert/BoundedBitVec.hpp +++ b/chilbert/BoundedBitVec.hpp @@ -19,11 +19,11 @@ #ifndef CHILBERT_BOUNDEDBITVEC_HPP #define CHILBERT_BOUNDEDBITVEC_HPP -#include "chilbert/BitVecIndex.hpp" -#include "chilbert/BitVecIterator.hpp" -#include "chilbert/BitVecMask.hpp" -#include "chilbert/MultiBitVec.hpp" -#include "chilbert/Operations.hpp" +#include "chilbert/detail/BitVecIndex.hpp" +#include "chilbert/detail/BitVecIterator.hpp" +#include "chilbert/detail/BitVecMask.hpp" +#include "chilbert/detail/MultiBitVec.hpp" +#include "chilbert/detail/operations.hpp" #include <algorithm> #include <array> @@ -42,12 +42,12 @@ namespace chilbert { * @tparam MaxN Maximum number of bits. */ template <size_t MaxN> -class BoundedBitVec : public MultiBitVec<BoundedBitVec<MaxN>> +class BoundedBitVec : public detail::MultiBitVec<BoundedBitVec<MaxN>> { public: - using Rack = typename MultiBitVec<BoundedBitVec<MaxN>>::Rack; + using Rack = typename detail::MultiBitVec<BoundedBitVec<MaxN>>::Rack; - using MultiBitVec<BoundedBitVec<MaxN>>::bits_per_rack; + using detail::MultiBitVec<BoundedBitVec<MaxN>>::bits_per_rack; BoundedBitVec() = default; @@ -95,6 +95,8 @@ private: size_t m_size; }; +namespace detail { + template <size_t MaxN> struct is_bitvec<BoundedBitVec<MaxN>> { @@ -105,16 +107,19 @@ template <size_t MaxN> void gray_code(BoundedBitVec<MaxN>& value) { - gray_code(static_cast<MultiBitVec<BoundedBitVec<MaxN>>&>(value)); + gray_code(static_cast<detail::MultiBitVec<BoundedBitVec<MaxN>>&>(value)); } template <size_t MaxN> void gray_code_inv(BoundedBitVec<MaxN>& value) { - gray_code_inv(static_cast<MultiBitVec<BoundedBitVec<MaxN>>&>(value)); + gray_code_inv( + static_cast<detail::MultiBitVec<BoundedBitVec<MaxN>>&>(value)); } +} // namespace detail + } // namespace chilbert #endif diff --git a/chilbert/DynamicBitVec.hpp b/chilbert/DynamicBitVec.hpp index 7372629..722b689 100644 --- a/chilbert/DynamicBitVec.hpp +++ b/chilbert/DynamicBitVec.hpp @@ -19,11 +19,11 @@ #ifndef CHILBERT_DYNAMICBITVEC_HPP #define CHILBERT_DYNAMICBITVEC_HPP -#include "chilbert/BitVecIndex.hpp" -#include "chilbert/BitVecIterator.hpp" -#include "chilbert/BitVecMask.hpp" -#include "chilbert/MultiBitVec.hpp" -#include "chilbert/Operations.hpp" +#include "chilbert/detail/BitVecIndex.hpp" +#include "chilbert/detail/BitVecIterator.hpp" +#include "chilbert/detail/BitVecMask.hpp" +#include "chilbert/detail/MultiBitVec.hpp" +#include "chilbert/detail/operations.hpp" #include <algorithm> #include <cstddef> @@ -38,7 +38,7 @@ namespace chilbert { * This uses dynamic allocation internally and can be constructed with any * size, assuming sufficient memory is available. */ -class DynamicBitVec : public MultiBitVec<DynamicBitVec> +class DynamicBitVec : public detail::MultiBitVec<DynamicBitVec> { public: struct RacksDeleter @@ -128,6 +128,8 @@ private: size_t m_size; }; +namespace detail { + template <> struct is_bitvec<DynamicBitVec> { @@ -148,6 +150,8 @@ gray_code_inv(DynamicBitVec& value) gray_code_inv(static_cast<MultiBitVec<DynamicBitVec>&>(value)); } +} // namespace detail + } // namespace chilbert #endif diff --git a/chilbert/SmallBitVec.hpp b/chilbert/SmallBitVec.hpp index 308d943..478cbc9 100644 --- a/chilbert/SmallBitVec.hpp +++ b/chilbert/SmallBitVec.hpp @@ -19,7 +19,7 @@ #ifndef CHILBERT_SMALLBITVEC_HPP #define CHILBERT_SMALLBITVEC_HPP -#include "chilbert/Operations.hpp" +#include "chilbert/detail/operations.hpp" #include <cassert> #include <climits> @@ -233,11 +233,14 @@ 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::find_first(m_rack)); + return static_cast<size_t>(detail::find_first(m_rack)); } /// Return the number of set bits - size_t count() const { return static_cast<size_t>(pop_count(m_rack)); } + size_t count() const + { + return static_cast<size_t>(detail::pop_count(m_rack)); + } /// Flip all bits (one's complement) SmallBitVec& flip() @@ -347,6 +350,8 @@ private: size_t m_size{}; }; +namespace detail { + template <> struct is_bitvec<SmallBitVec> { @@ -367,6 +372,8 @@ gray_code_inv(SmallBitVec& value) gray_code_inv<SmallBitVec::Rack>(value.rack()); } +} // namespace detail + } // namespace chilbert #endif diff --git a/chilbert/StaticBitVec.hpp b/chilbert/StaticBitVec.hpp index 66d136a..9aff3ad 100644 --- a/chilbert/StaticBitVec.hpp +++ b/chilbert/StaticBitVec.hpp @@ -19,11 +19,11 @@ #ifndef CHILBERT_STATICBITVEC_HPP #define CHILBERT_STATICBITVEC_HPP -#include "chilbert/BitVecIndex.hpp" -#include "chilbert/BitVecIterator.hpp" -#include "chilbert/BitVecMask.hpp" -#include "chilbert/MultiBitVec.hpp" -#include "chilbert/Operations.hpp" +#include "chilbert/detail/BitVecIndex.hpp" +#include "chilbert/detail/BitVecIterator.hpp" +#include "chilbert/detail/BitVecMask.hpp" +#include "chilbert/detail/MultiBitVec.hpp" +#include "chilbert/detail/operations.hpp" #include <algorithm> #include <array> @@ -43,12 +43,12 @@ namespace chilbert { * @tparam N Number of bits. */ template <size_t N> -class StaticBitVec : public MultiBitVec<StaticBitVec<N>> +class StaticBitVec : public detail::MultiBitVec<StaticBitVec<N>> { public: - using Rack = typename MultiBitVec<StaticBitVec<N>>::Rack; + using Rack = typename detail::MultiBitVec<StaticBitVec<N>>::Rack; - using MultiBitVec<StaticBitVec<N>>::bits_per_rack; + using detail::MultiBitVec<StaticBitVec<N>>::bits_per_rack; StaticBitVec() = default; @@ -91,6 +91,8 @@ private: std::array<Rack, num_racks()> m_racks{}; }; +namespace detail { + template <size_t N> struct is_bitvec<StaticBitVec<N>> { @@ -111,6 +113,8 @@ gray_code_inv(StaticBitVec<N>& value) gray_code_inv(static_cast<MultiBitVec<StaticBitVec<N>>&>(value)); } +} // namespace detail + } // namespace chilbert #endif diff --git a/chilbert/Hilbert.hpp b/chilbert/chilbert.hpp index 8db5b1c..2954cf3 100644 --- a/chilbert/Hilbert.hpp +++ b/chilbert/chilbert.hpp @@ -97,6 +97,6 @@ inline void compact_index_to_coords(P* const p, } // namespace chilbert -#include "chilbert/Hilbert.ipp" +#include "chilbert/chilbert.ipp" #endif diff --git a/chilbert/Hilbert.ipp b/chilbert/chilbert.ipp index 837375e..c4e8249 100644 --- a/chilbert/Hilbert.ipp +++ b/chilbert/chilbert.ipp @@ -21,10 +21,10 @@ #include "chilbert/BoundedBitVec.hpp" #include "chilbert/DynamicBitVec.hpp" -#include "chilbert/GrayCodeRank.hpp" -#include "chilbert/Hilbert.hpp" #include "chilbert/SmallBitVec.hpp" #include "chilbert/StaticBitVec.hpp" +#include "chilbert/chilbert.hpp" +#include "chilbert/detail/gray_code_rank.hpp" #include <cassert> #include <climits> diff --git a/chilbert/BitVecIndex.hpp b/chilbert/detail/BitVecIndex.hpp index 4038105..e7b385e 100644 --- a/chilbert/BitVecIndex.hpp +++ b/chilbert/detail/BitVecIndex.hpp @@ -24,6 +24,7 @@ #include <cstddef> namespace chilbert { +namespace detail { /// Index into a multi-rack bit vector template <class BitVec> @@ -44,6 +45,7 @@ struct BitVecIndex size_t bit; }; +} // namespace detail } // namespace chilbert #endif diff --git a/chilbert/BitVecIterator.hpp b/chilbert/detail/BitVecIterator.hpp index bbafd42..8902747 100644 --- a/chilbert/BitVecIterator.hpp +++ b/chilbert/detail/BitVecIterator.hpp @@ -19,11 +19,12 @@ #ifndef CHILBERT_BITVECITERATOR_HPP #define CHILBERT_BITVECITERATOR_HPP -#include "chilbert/BitVecMask.hpp" +#include "chilbert/detail/BitVecMask.hpp" #include <cstddef> namespace chilbert { +namespace detail { template <class BitVec> class BitVecIteratorBase : public BitVecMask<typename BitVec::Rack> @@ -93,6 +94,7 @@ private: } }; +} // namespace detail } // namespace chilbert #endif diff --git a/chilbert/BitVecMask.hpp b/chilbert/detail/BitVecMask.hpp index af98894..03eaf5f 100644 --- a/chilbert/BitVecMask.hpp +++ b/chilbert/detail/BitVecMask.hpp @@ -23,6 +23,7 @@ #include <cstddef> namespace chilbert { +namespace detail { /** Mask for a bit that can be incremented like an index. * @@ -67,6 +68,7 @@ struct BitVecMask Rack mask; }; +} // namespace detail } // namespace chilbert #endif diff --git a/chilbert/MultiBitVec.hpp b/chilbert/detail/MultiBitVec.hpp index 1401fd7..4bf5085 100644 --- a/chilbert/MultiBitVec.hpp +++ b/chilbert/detail/MultiBitVec.hpp @@ -19,8 +19,10 @@ #ifndef CHILBERT_MULTIBITVEC_HPP #define CHILBERT_MULTIBITVEC_HPP -#include "chilbert/BitVecIterator.hpp" -#include "chilbert/Operations.hpp" +#include "chilbert/detail/BitVecIndex.hpp" +#include "chilbert/detail/BitVecIterator.hpp" +#include "chilbert/detail/BitVecMask.hpp" +#include "chilbert/detail/operations.hpp" #include <cassert> #include <climits> @@ -28,6 +30,7 @@ #include <cstring> namespace chilbert { +namespace detail { template <class Derived> class MultiBitVec @@ -175,7 +178,7 @@ public: size_t find_first() const { for (size_t i = 0; i < num_racks(); ++i) { - const int j = chilbert::find_first(rack(i)); + const int j = chilbert::detail::find_first(rack(i)); if (j) { return (i * bits_per_rack) + static_cast<size_t>(j); } @@ -336,7 +339,7 @@ public: size_t data_size() const { return self()->data_size(); } private: - using Index = BitVecIndex<Derived>; + using Index = detail::BitVecIndex<Derived>; Derived* self() { return static_cast<Derived*>(this); } const Derived* self() const { return static_cast<const Derived*>(this); } @@ -374,6 +377,7 @@ gray_code_inv(MultiBitVec<Derived>& value) } } +} // namespace detail } // namespace chilbert #endif diff --git a/chilbert/GrayCodeRank.hpp b/chilbert/detail/gray_code_rank.hpp index d7fbc77..815519e 100644 --- a/chilbert/GrayCodeRank.hpp +++ b/chilbert/detail/gray_code_rank.hpp @@ -24,6 +24,7 @@ #include <numeric> namespace chilbert { +namespace detail { // This is the bulk of the cost in calculating // a Compact Hilbert Index. It compresses a previously @@ -175,6 +176,7 @@ extract_mask(const size_t* const ms, } while (j != d); } +} // namespace detail } // namespace chilbert #endif diff --git a/chilbert/Operations.hpp b/chilbert/detail/operations.hpp index 24474cc..94635b4 100644 --- a/chilbert/Operations.hpp +++ b/chilbert/detail/operations.hpp @@ -19,8 +19,8 @@ #ifndef CHILBERT_OPERATIONS_HPP #define CHILBERT_OPERATIONS_HPP -#include "chilbert/Operators.hpp" -#include "chilbert/Traits.hpp" +#include "chilbert/detail/traits.hpp" +#include "chilbert/operators.hpp" #include <cassert> #include <climits> @@ -29,6 +29,7 @@ #include <type_traits> namespace chilbert { +namespace detail { /// Reset all bits in `field` template <typename T> @@ -161,6 +162,7 @@ gray_code_inv(T& value) } } +} // namespace detail } // namespace chilbert #endif diff --git a/chilbert/Traits.hpp b/chilbert/detail/traits.hpp index 0c7807d..0cb0f03 100644 --- a/chilbert/Traits.hpp +++ b/chilbert/detail/traits.hpp @@ -20,6 +20,7 @@ #define CHILBERT_TRAITS_HPP namespace chilbert { +namespace detail { /// Member `value` is true iff T is a chilbert bitset template <class T> @@ -32,6 +33,7 @@ struct is_bitvec template <class T> static constexpr bool is_bitvec_v = is_bitvec<T>::value; +} // namespace detail } // namespace chilbert #endif diff --git a/chilbert/Operators.hpp b/chilbert/operators.hpp index 683c792..efad7f4 100644 --- a/chilbert/Operators.hpp +++ b/chilbert/operators.hpp @@ -19,13 +19,15 @@ #ifndef CHILBERT_OPERATORS_HPP #define CHILBERT_OPERATORS_HPP -#include "chilbert/Traits.hpp" +#include "chilbert/detail/traits.hpp" #include <iostream> #include <type_traits> namespace chilbert { +using detail::is_bitvec_v; + template <class T> std::enable_if_t<is_bitvec_v<T>, T> operator&(const T& lhs, const T& rhs) { diff --git a/test/test_bitvec.cpp b/test/test_bitvec.cpp index 1596042..bd944b5 100644 --- a/test/test_bitvec.cpp +++ b/test/test_bitvec.cpp @@ -252,13 +252,13 @@ test_gray_code(Context& ctx) { const T v = make_random_bitvec<T, N>(ctx); T r = v; - gray_code(r); + chilbert::detail::gray_code(r); if (N > 0) { assert(N == 1 || r == (v ^ (v >> 1))); T s = r; - gray_code_inv(s); + chilbert::detail::gray_code_inv(s); assert(s == v); } } @@ -271,11 +271,11 @@ test_comparison(Context&) T b = make_zero_bitvec<T, N>(); for (size_t bit = 1; bit < N; ++bit) { - set_bit(a, bit, 1); + chilbert::detail::set_bit(a, bit, 1); for (size_t i = 0; i < bit; ++i) { - set_bit(a, i, rand() % 2 == 0); - set_bit(b, i, rand() % 2 == 0); + chilbert::detail::set_bit(a, i, rand() % 2 == 0); + chilbert::detail::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 0c06a33..9c903c1 100644 --- a/test/test_gray_code_rank.cpp +++ b/test/test_gray_code_rank.cpp @@ -21,9 +21,9 @@ #include "chilbert/BoundedBitVec.hpp" #include "chilbert/DynamicBitVec.hpp" -#include "chilbert/GrayCodeRank.hpp" #include "chilbert/SmallBitVec.hpp" #include "chilbert/StaticBitVec.hpp" +#include "chilbert/detail/gray_code_rank.hpp" #include <algorithm> #include <array> @@ -39,7 +39,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::extract_mask(ms.data(), D, d, step, mask, b); + chilbert::detail::extract_mask(ms.data(), D, d, step, mask, b); assert(b == mask.count()); @@ -75,21 +75,21 @@ test_gray_code_rank(Context& ctx) const auto b = make_random_bitvec<T, D>(ctx); auto ga = a; - gray_code(ga); + chilbert::detail::gray_code(ga); auto gb = b; - gray_code(gb); + chilbert::detail::gray_code(gb); // Calculate gray code ranks auto ra = make_zero_bitvec<T, D>(); - chilbert::gray_code_rank(mask, ga, D, ra); + chilbert::detail::gray_code_rank(mask, ga, D, ra); auto rb = make_zero_bitvec<T, D>(); - chilbert::gray_code_rank(mask, gb, D, rb); + chilbert::detail::gray_code_rank(mask, gb, D, rb); // Ensure ranks have at most mask.count() bits auto max = make_zero_bitvec<T, D>(); - set_bit(max, mask.count(), 1); + chilbert::detail::set_bit(max, mask.count(), 1); assert(ra < max); assert(rb < max); @@ -102,11 +102,12 @@ 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>(); - gray_code_rank_inv(mask, pat, ra, D, mask.count(), gag_out, ga_out); + chilbert::detail::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; - gray_code(gag_check); + chilbert::detail::gray_code(gag_check); assert(gag_check == gag_out); } } diff --git a/test/test_hilbert.cpp b/test/test_hilbert.cpp index a217dc2..307dbae 100644 --- a/test/test_hilbert.cpp +++ b/test/test_hilbert.cpp @@ -21,9 +21,9 @@ #include "chilbert/BoundedBitVec.hpp" #include "chilbert/DynamicBitVec.hpp" -#include "chilbert/Hilbert.hpp" #include "chilbert/SmallBitVec.hpp" #include "chilbert/StaticBitVec.hpp" +#include "chilbert/chilbert.hpp" #include <gmpxx.h> |