From b5954ef2de4f205108be0cf5a06f88540194bed9 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 19 Aug 2018 14:58:14 +0200 Subject: Tighten up size constraints --- chilbert/GrayCodeRank.hpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'chilbert/GrayCodeRank.hpp') diff --git a/chilbert/GrayCodeRank.hpp b/chilbert/GrayCodeRank.hpp index adb953a..1e3895f 100644 --- a/chilbert/GrayCodeRank.hpp +++ b/chilbert/GrayCodeRank.hpp @@ -21,6 +21,7 @@ #include #include +#include namespace chilbert { @@ -37,6 +38,9 @@ compactIndex(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))); + resetBits(hc); auto hm = h.mask(0); @@ -67,6 +71,10 @@ template inline void grayCodeRank(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(); @@ -93,13 +101,15 @@ grayCodeRankInv(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(); - assert(ptrn.size() == mask.size()); - assert(g.size() == mask.size()); - assert(gi.size() == mask.size()); - auto m = mask.mask(n - 1); auto ri = r.begin(b - 1); @@ -145,6 +155,7 @@ extractMask(const size_t* const ms, size_t& b) { assert(0 <= d && d < n); + assert(mask.size() == n); mask.reset(); b = 0; -- cgit v1.2.1