aboutsummaryrefslogtreecommitdiffstats
path: root/chilbert/GrayCodeRank.hpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-08-11 22:40:03 +0200
committerDavid Robillard <d@drobilla.net>2018-09-29 14:46:25 +0200
commit50145430b5fb08802bc22a6ae06351a11a091c60 (patch)
tree4ba0d1c8c5b76e7608fbd8ffbc985ba8a9f09622 /chilbert/GrayCodeRank.hpp
parentdf0d52f4bd78c2197a88a805a1dd402978df3290 (diff)
downloadchilbert-50145430b5fb08802bc22a6ae06351a11a091c60.tar.gz
chilbert-50145430b5fb08802bc22a6ae06351a11a091c60.tar.bz2
chilbert-50145430b5fb08802bc22a6ae06351a11a091c60.zip
Clean up types and fix every even remotely reasonable warning
Diffstat (limited to 'chilbert/GrayCodeRank.hpp')
-rw-r--r--chilbert/GrayCodeRank.hpp65
1 files changed, 41 insertions, 24 deletions
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 <cassert>
+#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 <class H, class HC>
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 <class I>
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 <class I>
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<intptr_t>(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 <class I>
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;