aboutsummaryrefslogtreecommitdiffstats
path: root/include/chilbert/detail/gray_code_rank.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/chilbert/detail/gray_code_rank.hpp')
-rw-r--r--include/chilbert/detail/gray_code_rank.hpp220
1 files changed, 110 insertions, 110 deletions
diff --git a/include/chilbert/detail/gray_code_rank.hpp b/include/chilbert/detail/gray_code_rank.hpp
index b6811ff..a326617 100644
--- a/include/chilbert/detail/gray_code_rank.hpp
+++ b/include/chilbert/detail/gray_code_rank.hpp
@@ -30,7 +30,7 @@ namespace detail {
// a Compact Hilbert Index. It compresses a previously
// calculated index when provided the rotation
// at each level of precision.
-template <class H, class HC>
+template<class H, class HC>
inline void
compact_index(const size_t* const ms,
const size_t* const ds,
@@ -39,60 +39,60 @@ compact_index(const size_t* const ms,
H& h,
HC& hc)
{
- assert(h.size() >= n * m);
- assert(hc.size() >= std::accumulate(ms, ms + n, size_t(0)));
-
- reset_bits(hc);
-
- auto hm = h.mask(0);
- auto hcm = hc.mask(0);
-
- // Run through the levels of precision
- for (size_t i = 0; i < m; ++i) {
- // Run through the dimensions
- size_t j = ds[i];
- do {
- // This dimension contributes a bit?
- if (ms[j] > i) {
- if (h.test(hm)) {
- hc.set(hcm);
- }
- ++hcm;
- }
-
- if (++j == n) {
- j = 0;
- }
- ++hm;
- } while (j != ds[i]);
- }
+ assert(h.size() >= n * m);
+ assert(hc.size() >= std::accumulate(ms, ms + n, size_t(0)));
+
+ reset_bits(hc);
+
+ auto hm = h.mask(0);
+ auto hcm = hc.mask(0);
+
+ // Run through the levels of precision
+ for (size_t i = 0; i < m; ++i) {
+ // Run through the dimensions
+ size_t j = ds[i];
+ do {
+ // This dimension contributes a bit?
+ if (ms[j] > i) {
+ if (h.test(hm)) {
+ hc.set(hcm);
+ }
+ ++hcm;
+ }
+
+ if (++j == n) {
+ j = 0;
+ }
+ ++hm;
+ } while (j != ds[i]);
+ }
}
-template <class I>
+template<class I>
inline void
gray_code_rank(const I& mask, const I& gi, const size_t n, I& r)
{
- assert(mask.size() == n);
- assert(gi.size() == n);
- assert(r.size() == n);
-
- r.reset();
-
- auto mi = mask.begin();
- auto gii = gi.begin();
- auto ri = r.begin();
-
- for (size_t i = 0; i < n; ++i, ++mi, ++gii) {
- if (*mi) {
- if (*gii) {
- ri.set();
- }
- ++ri;
- }
- }
+ assert(mask.size() == n);
+ assert(gi.size() == n);
+ assert(r.size() == n);
+
+ r.reset();
+
+ auto mi = mask.begin();
+ auto gii = gi.begin();
+ auto ri = r.begin();
+
+ for (size_t i = 0; i < n; ++i, ++mi, ++gii) {
+ if (*mi) {
+ if (*gii) {
+ ri.set();
+ }
+ ++ri;
+ }
+ }
}
-template <class I>
+template<class I>
inline void
gray_code_rank_inv(const I& mask,
const I& ptrn,
@@ -102,51 +102,51 @@ gray_code_rank_inv(const I& mask,
I& g,
I& gi)
{
- assert(mask.size() == n);
- assert(ptrn.size() == n);
- assert(r.size() == n);
- assert(g.size() == n);
- assert(gi.size() == n);
-
- g.reset();
- gi.reset();
-
- auto m = mask.mask(n - 1);
- auto ri = r.begin(b - 1);
-
- typename I::Rack gi0 = 0;
- typename I::Rack gi1 = 0;
- typename I::Rack g0 = 0;
-
- for (size_t i = 0; i < n; ++i) {
- if (mask.test(m)) { // Unconstrained bit
- gi1 = gi0;
- gi0 = *ri;
- g0 = gi0 ^ gi1;
- if (gi0) {
- gi.set(m);
- }
- if (g0) {
- g.set(m);
- }
- --ri;
- } else { // Constrained bit
- g0 = (ptrn.test(m) > 0);
- gi1 = gi0;
- gi0 = g0 ^ gi1;
- if (gi0) {
- gi.set(m);
- }
- if (g0) {
- g.set(m);
- }
- }
-
- --m;
- }
+ assert(mask.size() == n);
+ assert(ptrn.size() == n);
+ assert(r.size() == n);
+ assert(g.size() == n);
+ assert(gi.size() == n);
+
+ g.reset();
+ gi.reset();
+
+ auto m = mask.mask(n - 1);
+ auto ri = r.begin(b - 1);
+
+ typename I::Rack gi0 = 0;
+ typename I::Rack gi1 = 0;
+ typename I::Rack g0 = 0;
+
+ for (size_t i = 0; i < n; ++i) {
+ if (mask.test(m)) { // Unconstrained bit
+ gi1 = gi0;
+ gi0 = *ri;
+ g0 = gi0 ^ gi1;
+ if (gi0) {
+ gi.set(m);
+ }
+ if (g0) {
+ g.set(m);
+ }
+ --ri;
+ } else { // Constrained bit
+ g0 = (ptrn.test(m) > 0);
+ gi1 = gi0;
+ gi0 = g0 ^ gi1;
+ if (gi0) {
+ gi.set(m);
+ }
+ if (g0) {
+ g.set(m);
+ }
+ }
+
+ --m;
+ }
}
-template <class I>
+template<class I>
inline void
extract_mask(const size_t* const ms,
const size_t n,
@@ -155,25 +155,25 @@ extract_mask(const size_t* const ms,
I& mask,
size_t& b)
{
- assert(d < n);
- assert(mask.size() == n);
-
- mask.reset();
- b = 0;
-
- auto mi = mask.begin();
- size_t j = d; // #D j = (d==n-1) ? 0 : d+1;
- do {
- if (ms[j] > i) {
- mi.set();
- ++b;
- }
-
- ++mi;
- if (++j == n) {
- j = 0;
- }
- } while (j != d);
+ assert(d < n);
+ assert(mask.size() == n);
+
+ mask.reset();
+ b = 0;
+
+ auto mi = mask.begin();
+ size_t j = d; // #D j = (d==n-1) ? 0 : d+1;
+ do {
+ if (ms[j] > i) {
+ mi.set();
+ ++b;
+ }
+
+ ++mi;
+ if (++j == n) {
+ j = 0;
+ }
+ } while (j != d);
}
} // namespace detail