8 #include <boost/range/irange.hpp>
9 #include <boost/iterator/iterator_facade.hpp>
10 #include <boost/utility/enable_if.hpp>
11 #include <boost/type_traits/is_integral.hpp>
12 #include <boost/preprocessor/repetition.hpp>
14 #include <boost/fusion/include/size.hpp>
15 #include <boost/fusion/include/at_c.hpp>
16 #include <util/misc/assert.h>
24 boost::iterator_range<boost::range_detail::integer_iterator<int64_t> >
31 typedef boost::iterator_range<
32 boost::range_detail::integer_iterator<int64_t> > iterator_range;
37 explicit range(int64_t size = 0)
38 : iterator_range(int64_t(0), size) {}
40 range(int64_t begin, int64_t end)
41 : iterator_range(begin, end) {}
43 int64_t size()
const {
44 return end() - begin();
47 bool test(int64_t value)
const {
48 return ((*this->begin() <= value) && (value < *this->end()));
55 os << *r.begin() <<
":" << *r.end();
59 inline bool operator==(
const range &a,
const range &b) {
60 return (a.begin() == b.begin() && a.end() == b.end());
63 inline range intersection(
const range &a,
const range &b) {
64 int64_t begin = std::max(*a.begin(), *b.begin());
65 int64_t end = std::min(*a.end(), *b.end());
66 return (begin < end) ? range(begin, end) : range();
71 return intersection(a,b);
78 size_t m = R.size()%N;
79 size_t b = R.size()/N;
80 int64_t r = *R.begin();
81 for (
size_t i = 0; i < m; ++i) {
82 v.push_back(
range(r, r+b+1));
85 for (
size_t i = m; i < N; ++i) {
86 v.push_back(
range(r, r+b));
89 MPQC_ASSERT(r == *R.end());
96 return std::vector<range>(1, r);
97 std::vector<range> blocks;
98 for (int64_t i = *r.begin(); i < *r.end(); i += N) {
99 blocks.push_back(
range(i, std::min<int64_t>(i+N, *r.end())));
106 size_t nb = (r.size() + N-1)/N;
112 inline std::ostream&
operator<<(std::ostream &os,
const std::vector<range> &r) {
114 for (
int i = 0; i < r.size(); ++i) {
129 typename boost::enable_if<boost::is_integral<R>, range>::type
143 struct Range : boost::iterator_range<It>
145 typedef boost::iterator_range<It> iterator_range;
146 Range(It begin, It end) : iterator_range(begin, end) {}
156 #endif // MPQC_RANGE_HPP