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
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_);
119 Domain(int64_t left, int64_t right);
142 absl::Span<const int64_t> flat_intervals);
150 const std::vector<std::vector<int64_t> >& intervals);
179 const absl::InlinedVector<ClosedInterval, 1>& intervals)
180 : value_(intervals.empty() ? int64_t{0} : intervals.
front().
start),
181 it_(intervals.
begin()),
182 end_(intervals.
end()) {}
187 if (value_ == it_->end) {
189 if (it_ != end_) value_ = it_->start;
196 absl::InlinedVector<ClosedInterval, 1>::const_iterator
end)
const {
202 absl::InlinedVector<ClosedInterval, 1>::const_iterator it_;
203 absl::InlinedVector<ClosedInterval, 1>::const_iterator end_;
207 absl::InlinedVector<ClosedInterval, 1>::const_iterator
end()
const {
210 const absl::InlinedVector<ClosedInterval, 1>&
intervals;
214 absl::InlinedVector<ClosedInterval, 1>::const_iterator
end()
const {
221 return {std::move(this->intervals_)};
233 int64_t
Size()
const;
240 if (intervals_.size() == 1) {
241 return intervals_[0].end == intervals_[0].start + 1;
242 }
else if (intervals_.size() == 2) {
243 return intervals_[0].end == intervals_[0].start &&
244 intervals_[1].end == intervals_[1].start;
457 return intervals_ == other.intervals_;
461 return intervals_ != other.intervals_;
464 template <
typename H>
466 return H::combine(std::move(h), domain.intervals_);
478 absl::InlinedVector<ClosedInterval, 1>::const_iterator
begin()
const {
479 return intervals_.begin();
481 absl::InlinedVector<ClosedInterval, 1>::const_iterator
end()
const {
482 return intervals_.end();
487 void NegateInPlace();
491 static constexpr int kDomainComplexityLimit = 100;
498 absl::InlinedVector<ClosedInterval, 1> intervals_;
501std::ostream&
operator<<(std::ostream& out,
const Domain& domain);
521 return a.start !=
b.start ?
a.start <
b.start :
a.end <
b.end;
530 const std::vector<ClosedInterval>& intervals);
540 const std::vector<int64_t>& ends);
542 const std::vector<int>& ends);
579 const std::vector<int64_t>& ends);
581 const std::vector<int>& ends);
619 void clear() { intervals_.clear(); }
621 intervals_.swap(other.intervals_);
626 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
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
IntervalSet::iterator Iterator
Iterator InsertInterval(int64_t start, int64_t end)
const ClosedInterval & last() const
ConstIterator begin() const
SortedDisjointIntervalList BuildComplementOnInterval(int64_t start, int64_t end)
void swap(SortedDisjointIntervalList &other)
IntervalSet::const_iterator ConstIterator
Iterator FirstIntervalGreaterOrEqual(int64_t value) const
ConstIterator end() const
std::set< ClosedInterval, IntervalComparator > IntervalSet
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