Allow sequentially layed out arrays to be indexed

If we want to index into two arrays that has been concatenated (for
instance oil phase pressure continuously, then water phase pressure
continuously), then this variant (courtesy of @bska) will cover both
variants (intermixed striding (where offset < stride) and sequentially
striding (where offset > stride)).
This commit is contained in:
Roland Kaufmann
2013-11-28 11:10:52 +01:00
parent a997c17a51
commit 039e549033

View File

@@ -40,7 +40,6 @@
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/filesystem.hpp> // path
#include <cstdlib> // div
#include <ctime> // mktime
#include <forward_list>
#include <memory> // unique_ptr
@@ -211,15 +210,13 @@ private:
// don't jump out of the set when trying to
assert(stride > 0 && stride < num - offset);
// number of (strided) entries it will provide. it is assumed that the
// data is organized into a number of records, each with equal number
// of items (the stride), and that the offset *always* can be used to
// index into such a record. if we wanted to support a partial record
// at the end, then we should add one if the offset is less-or-equal
// to the remainder.
const div_t d = std::div (data.size (), stride);
assert (d.rem == 0);
return d.quot;
// number of (strided) entries it will provide. the last item
// in the array is num - 1. the last strided item we can pick
// (from recs number of records) is (recs - 1) * stride + offset,
// which must be <= num - 1. we are interesting in the maximum
// case where it holds to equals. rearranging the above gives us:
const int recs = (num - 1 - offset) / stride + 1;
return recs;
}
};