14#ifndef OR_TOOLS_UTIL_SORTED_INTERVAL_LIST_H_
15#define OR_TOOLS_UTIL_SORTED_INTERVAL_LIST_H_
25#include "absl/container/inlined_vector.h"
26#include "absl/types/span.h"
37 DLOG_IF(DFATAL, s > e) <<
"Invalid ClosedInterval(" << s <<
", " << e
55 return H::combine(std::move(h), interval.
start, interval.
end);
64 const std::vector<ClosedInterval>& intervals);
75 absl::Span<const ClosedInterval> intervals);
98 intervals_ = other.intervals_;
103 Domain(
Domain&& other) noexcept : intervals_(std::move(other.intervals_)) {}
107 intervals_ = std::move(other.intervals_);
113 explicit Domain(int64_t value);
119 Domain(int64_t left, int64_t right);
148 absl::Span<const int64_t> flat_intervals);
162 const std::vector<std::vector<int64_t> >& intervals);
194 const absl::InlinedVector<ClosedInterval, 1>& intervals)
195 : value_(intervals.empty() ? int64_t{0} : intervals.
front().start),
196 it_(intervals.
begin()),
197 end_(intervals.
end()) {}
202 if (value_ == it_->end) {
204 if (it_ != end_) value_ = it_->start;
211 absl::InlinedVector<ClosedInterval, 1>::const_iterator
end)
const {
217 absl::InlinedVector<ClosedInterval, 1>::const_iterator it_;
218 absl::InlinedVector<ClosedInterval, 1>::const_iterator end_;
222 absl::InlinedVector<ClosedInterval, 1>::const_iterator
end()
const {
225 const absl::InlinedVector<ClosedInterval, 1>&
intervals;
229 absl::InlinedVector<ClosedInterval, 1>::const_iterator
end()
const {
236 return {std::move(this->intervals_)};
248 int64_t
Size()
const;
255 if (intervals_.size() == 1) {
256 return intervals_[0].end == intervals_[0].start + 1;
257 }
else if (intervals_.size() == 2) {
258 return intervals_[0].end == intervals_[0].start &&
259 intervals_[1].end == intervals_[1].start;
321 int64_t
Distance(int64_t value)
const;
477 return intervals_ == other.intervals_;
481 return intervals_ != other.intervals_;
484 template <
typename H>
486 return H::combine(std::move(h), domain.intervals_);
498 absl::InlinedVector<ClosedInterval, 1>::const_iterator
begin()
const {
499 return intervals_.begin();
501 absl::InlinedVector<ClosedInterval, 1>::const_iterator
end()
const {
502 return intervals_.end();
507 void NegateInPlace();
511 static constexpr int kDomainComplexityLimit = 100;
518 absl::InlinedVector<ClosedInterval, 1> intervals_;
541 return a.
start != b.start ? a.
start < b.start : a.
end < b.end;
550 const std::vector<ClosedInterval>& intervals);
560 const std::vector<int64_t>& ends);
562 const std::vector<int>& ends);
599 const std::vector<int64_t>& ends);
601 const std::vector<int>& ends);
639 void clear() { intervals_.clear(); }
641 intervals_.swap(other.intervals_);
646 void InsertAll(
const std::vector<T>& starts,
const std::vector<T>& ends);
DomainIterator(const absl::InlinedVector< ClosedInterval, 1 > &intervals)
int64_t operator*() const
bool operator!=(absl::InlinedVector< ClosedInterval, 1 >::const_iterator end) const
Domain SimplifyUsingImpliedDomain(const Domain &implied_domain) const
static Domain FromVectorIntervals(const std::vector< std::vector< int64_t > > &intervals)
DomainIteratorBeginEndWithOwnership Values() const &&
Domain(Domain &&other) noexcept
Move constructor.
Domain MultiplicationBy(int64_t coeff, bool *exact=nullptr) const
static Domain FromValues(std::vector< int64_t > values)
bool operator<(const Domain &other) const
friend H AbslHashValue(H h, const Domain &domain)
int64_t ValueAtOrAfter(int64_t input) const
Domain(const Domain &other)
Copy constructor (mandatory as we define the move constructor).
std::vector< int64_t > FlattenedIntervals() const
Domain SquareSuperset() const
Domain IntersectionWith(const Domain &domain) const
Domain QuadraticSuperset(int64_t a, int64_t b, int64_t c, int64_t d) const
static Domain FromIntervals(absl::Span< const ClosedInterval > intervals)
Domain ContinuousMultiplicationBy(int64_t coeff) const
bool Contains(int64_t value) const
DomainIteratorBeginEnd Values() const &
Domain PositiveModuloBySuperset(const Domain &modulo) const
Domain AdditionWith(const Domain &domain) const
bool IsIncludedIn(const Domain &domain) const
static Domain FromFlatIntervals(const std::vector< int64_t > &flat_intervals)
int64_t SmallestValue() const
Domain()
By default, Domain will be empty.
int64_t FixedValue() const
Domain DivisionBy(int64_t coeff) const
int64_t Distance(int64_t value) const
std::string ToString() const
Domain & operator=(const Domain &other)
Copy operator (mandatory as we define the move operator).
static Domain AllValues()
static Domain FromFlatSpanOfIntervals(absl::Span< const int64_t > flat_intervals)
absl::InlinedVector< ClosedInterval, 1 >::const_iterator end() const
Domain PositiveDivisionBySuperset(const Domain &divisor) const
Domain RelaxIfTooComplex() const
absl::InlinedVector< ClosedInterval, 1 >::const_iterator begin() const
Domain UnionWith(const Domain &domain) const
ClosedInterval back() const
Domain Complement() const
bool operator==(const Domain &other) const
Domain & operator=(Domain &&other) noexcept
Move operator.
ClosedInterval operator[](int i) const
Domain PartAroundZero() const
ClosedInterval front() const
Domain InverseMultiplicationBy(int64_t coeff) const
int64_t ValueAtOrBefore(int64_t input) const
bool operator!=(const Domain &other) const
bool HasTwoValues() const
int64_t ClosestValue(int64_t wanted) const
void InsertIntervals(const std::vector< int64_t > &starts, const std::vector< int64_t > &ends)
SortedDisjointIntervalList()
Iterator LastIntervalLessOrEqual(int64_t value) const
std::string DebugString() const
Iterator InsertInterval(int64_t start, int64_t end)
const ClosedInterval & last() const
ConstIterator begin() const
SortedDisjointIntervalList BuildComplementOnInterval(int64_t start, int64_t end)
IntervalSet::const_iterator ConstIterator
void swap(SortedDisjointIntervalList &other)
std::set< ClosedInterval, IntervalComparator > IntervalSet
IntervalSet::iterator Iterator
Iterator FirstIntervalGreaterOrEqual(int64_t value) const
ConstIterator end() const
Iterator GrowRightByOne(int64_t value, int64_t *newly_covered)
In SWIG mode, we don't want anything besides these top-level includes.
int64_t SumOfKMinValueInDomain(const Domain &domain, int k)
Returns the sum of smallest k values in the domain.
std::ostream & operator<<(std::ostream &out, const Assignment &assignment)
bool IntervalsAreSortedAndNonAdjacent(absl::Span< const ClosedInterval > intervals)
int64_t SumOfKMaxValueInDomain(const Domain &domain, int k)
Returns the sum of largest k values in the domain.
static int input(yyscan_t yyscanner)
std::string DebugString() const
bool operator==(const ClosedInterval &other) const
friend H AbslHashValue(H h, const ClosedInterval &interval)
ClosedInterval(int64_t s, int64_t e)
bool operator<(const ClosedInterval &other) const
absl::InlinedVector< ClosedInterval, 1 >::const_iterator end() const
absl::InlinedVector< ClosedInterval, 1 > intervals
DomainIterator begin() const
absl::InlinedVector< ClosedInterval, 1 >::const_iterator end() const
DomainIterator begin() const
const absl::InlinedVector< ClosedInterval, 1 > & intervals
bool operator()(const ClosedInterval &a, const ClosedInterval &b) const