9#ifndef FORTRAN_COMMON_INTERVAL_H_
10#define FORTRAN_COMMON_INTERVAL_H_
26 constexpr Interval(
const A &s, std::size_t n = 1) : start_{s}, size_{n} {}
27 constexpr Interval(A &&s, std::size_t n = 1)
28 : start_{std::move(s)}, size_{n} {}
34 constexpr bool operator<(
const Interval &that)
const {
35 return start_ < that.start_ ||
36 (start_ == that.start_ && size_ < that.size_);
38 constexpr bool operator<=(
const Interval &that)
const {
39 return start_ < that.start_ ||
40 (start_ == that.start_ && size_ <= that.size_);
42 constexpr bool operator==(
const Interval &that)
const {
43 return start_ == that.start_ && size_ == that.size_;
45 constexpr bool operator!=(
const Interval &that)
const {
46 return !(*
this == that);
48 constexpr bool operator>=(
const Interval &that)
const {
49 return !(*
this < that);
51 constexpr bool operator>(
const Interval &that)
const {
52 return !(*
this <= that);
55 constexpr const A &start()
const {
return start_; }
56 constexpr std::size_t size()
const {
return size_; }
57 constexpr bool empty()
const {
return size_ == 0; }
59 constexpr bool Contains(
const A &x)
const {
60 return start_ <= x && x < start_ + size_;
62 constexpr bool Contains(
const Interval &that)
const {
63 return Contains(that.start_) && Contains(that.start_ + (that.size_ - 1));
65 constexpr bool IsDisjointWith(
const Interval &that)
const {
66 return that.NextAfter() <= start_ || NextAfter() <= that.start_;
68 constexpr bool ImmediatelyPrecedes(
const Interval &that)
const {
69 return NextAfter() == that.start_;
72 size_ = (that.start_ + that.size_) - start_;
74 bool AnnexIfPredecessor(
const Interval &that) {
75 if (ImmediatelyPrecedes(that)) {
81 void ExtendToCover(
const Interval &that) {
84 }
else if (that.size_ != 0) {
85 const auto end{std::max(NextAfter(), that.NextAfter())};
86 start_ = std::min(start_, that.start_);
91 std::size_t MemberOffset(
const A &x)
const {
95 A OffsetMember(std::size_t n)
const {
100 constexpr A Last()
const {
return start_ + (size_ - 1); }
101 constexpr A NextAfter()
const {
return start_ + size_; }
102 constexpr Interval Prefix(std::size_t n)
const {
103 return {start_, std::min(size_, n)};
105 Interval Suffix(std::size_t n)
const {
106 n = std::min(n, size_);
107 return {start_ + n, size_ - n};
111 if (that.NextAfter() <= start_) {
113 }
else if (that.start_ <= start_) {
114 auto skip{start_ - that.start_};
115 return {start_, std::min(size_, that.size_ - skip)};
116 }
else if (NextAfter() <= that.start_) {
119 auto skip{that.start_ - start_};
120 return {that.start_, std::min(that.size_, size_ - skip)};
126 std::size_t size_{0};
Definition: interval.h:22
Definition: bit-population-count.h:20