From 50145430b5fb08802bc22a6ae06351a11a091c60 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 11 Aug 2018 22:40:03 +0200 Subject: Clean up types and fix every even remotely reasonable warning --- chilbert/GrayCodeRank.hpp | 65 ++++++++++++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 24 deletions(-) (limited to 'chilbert/GrayCodeRank.hpp') diff --git a/chilbert/GrayCodeRank.hpp b/chilbert/GrayCodeRank.hpp index 3083489..7bbfa69 100644 --- a/chilbert/GrayCodeRank.hpp +++ b/chilbert/GrayCodeRank.hpp @@ -24,6 +24,13 @@ #include +#define MODSPLIT(r, b, k) \ + { \ + b = (k); \ + r = b / FBV_BITS; \ + b -= r * FBV_BITS; \ + } + namespace chilbert { // This is the bulk of the cost in calculating @@ -32,17 +39,22 @@ namespace chilbert { // at each level of precision. template inline void -compactIndex(const int* ms, const int* ds, int n, int m, H& h, HC& hc) +compactIndex(const size_t* const ms, + const size_t* const ds, + const size_t n, + const size_t m, + H& h, + HC& hc) { hc = 0; - int hi = 0; - int hci = 0; + size_t hi = 0; + size_t hci = 0; // Run through the levels of precision - for (int i = 0; i < m; i++) { + for (size_t i = 0; i < m; i++) { // Run through the dimensions - int j = ds[i]; + size_t j = ds[i]; do { // This dimension contributes a bit? if (ms[j] > i) { @@ -62,7 +74,7 @@ compactIndex(const int* ms, const int* ds, int n, int m, H& h, HC& hc) template inline void -grayCodeRank(const I& mask, const I& gi, int n, I& r) +grayCodeRank(const I& mask, const I& gi, const size_t n, I& r) { r.reset(); @@ -70,7 +82,7 @@ grayCodeRank(const I& mask, const I& gi, int n, I& r) FBV_UINT jm = 1; int ir = 0; FBV_UINT im = 1; - for (int i = 0; i < n; ++i) { + for (size_t i = 0; i < n; ++i) { if (mask.racks()[ir] & im) { if (gi.racks()[ir] & im) { r.racks()[jr] |= jm; @@ -92,26 +104,26 @@ grayCodeRank(const I& mask, const I& gi, int n, I& r) template inline void -grayCodeRankInv(const I& mask, - const I& ptrn, - const I& r, - int n, - int b, - I& g, - I& gi) +grayCodeRankInv(const I& mask, + const I& ptrn, + const I& r, + const size_t n, + const size_t b, + I& g, + I& gi) { g.reset(); gi.reset(); - int ir, jr; + size_t ir, jr; FBV_UINT im, jm; - int i = n - 1; - BBV_MODSPLIT(ir, im, i); + intptr_t i = static_cast(n - 1); + MODSPLIT(ir, im, (n - 1)); im = (FBV1 << im); - int j = b - 1; - BBV_MODSPLIT(jr, jm, j); + size_t j = b - 1; + MODSPLIT(jr, jm, j); jm = (FBV1 << jm); FBV_UINT gi0, gi1, g0; @@ -131,7 +143,7 @@ grayCodeRankInv(const I& mask, } jm >>= 1; if (jm == 0) { - jm = ((FBV_UINT)1) << (FBV_BITS - 1); + jm = (FBV_UINT{1}) << (FBV_BITS - 1); --jr; } } else { @@ -148,7 +160,7 @@ grayCodeRankInv(const I& mask, im >>= 1; if (im == 0) { - im = ((FBV_UINT)1) << (FBV_BITS - 1); + im = (FBV_UINT{1}) << (FBV_BITS - 1); --ir; } } @@ -156,7 +168,12 @@ grayCodeRankInv(const I& mask, template inline void -extractMask(const int* ms, int n, int d, int i, I& mask, int& b) +extractMask(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); @@ -164,8 +181,8 @@ extractMask(const int* ms, int n, int d, int i, I& mask, int& b) b = 0; FBV_UINT jm = 1; - int jr = 0; - int j = d; // #D j = (d==n-1) ? 0 : d+1; + size_t jr = 0; + size_t j = d; // #D j = (d==n-1) ? 0 : d+1; do { if (ms[j] > i) { mask.racks()[jr] |= jm; -- cgit v1.2.1