9#include <clingo/util/small_vector.hh>
11namespace CppClingo::Util {
45 if (idx_ == it_->first) {
68 iterator(interval_iterator it,
size_t idx,
size_t start) : it_{it}, idx_{idx}, start_{start} {}
70 interval_iterator it_;
77 if (values_.
empty()) {
80 auto &[r, s] = values_.
back();
81 auto l = values_.
size() > 1 ? values_[values_.
size() - 2].first :
size_t{0};
82 if (s +
static_cast<T
>(r - l) == value) {
101 assert(index <
size() && last_ < values_.
size());
102 auto l = last_ > 0 ? values_[last_ - 1].first :
size_t{0};
103 auto r = values_[last_].first;
105 auto ib = index < l ? values_.
begin() : values_.
begin() + last_;
106 auto ie = index < r ? values_.
begin() + last_ + 1 : values_.
end();
107 auto it = std::upper_bound(ib, ie, index, [](
auto const &a,
auto const &b) {
return a < b.first; });
108 last_ =
static_cast<size_t>(std::distance(values_.
begin(), it));
109 auto start = last_ > 0 ? values_[last_ - 1].first :
size_t{0};
110 return it->second +
static_cast<T
>(index - start);
115 [[nodiscard]]
auto find(T x)
const ->
size_t {
120 for (
auto const &[r, s] : values_) {
121 auto e = s +
static_cast<T
>(r - l);
122 if (s <= x && x < e) {
123 return l +
static_cast<size_t>(x - s);
130 [[nodiscard]]
auto size() const ->
size_t {
return empty() ? 0 : values_.
back().first; }
132 [[nodiscard]]
auto empty() const ->
bool {
return values_.
empty(); }
140 size_t mutable last_ = 0;
Const iterator for index sequence.
Definition index_sequence.hh:22
auto operator!=(const iterator &other) const -> bool
Compare two iterators.
Definition index_sequence.hh:63
void pointer
The pointer type.
Definition index_sequence.hh:34
auto operator*() const -> reference
Get the current value.
Definition index_sequence.hh:40
std::forward_iterator_tag iterator_category
The iterator category.
Definition index_sequence.hh:26
iterator()=default
Construct an end iterator.
T value_type
The value type.
Definition index_sequence.hh:28
auto operator++() -> iterator &
Increment the iterator.
Definition index_sequence.hh:43
auto operator++(int) -> iterator
Post increment the iterator.
Definition index_sequence.hh:53
T reference
The reference type.
Definition index_sequence.hh:32
auto operator==(const iterator &other) const -> bool
Compare two iterators.
Definition index_sequence.hh:60
std::ptrdiff_t difference_type
The difference type.
Definition index_sequence.hh:30
Container to store integer sequences.
Definition index_sequence.hh:19
auto operator[](size_t index) const -> T
Get the i-th integer in the sequence.
Definition index_sequence.hh:100
void assign(T s, T e)
Set the sequence to the interval [s, e).
Definition index_sequence.hh:91
auto end() const -> iterator
Get an iterator to the end of the sequence.
Definition index_sequence.hh:136
auto find(T x) const -> size_t
Get the index of the value in the sequence.
Definition index_sequence.hh:115
auto empty() const -> bool
Check whether the sequence is empty.
Definition index_sequence.hh:132
void add(T value)
Add an integer to the sequence.
Definition index_sequence.hh:76
auto begin() const -> iterator
Get an iterator to the beginning of the sequence.
Definition index_sequence.hh:134
auto size() const -> size_t
Get the number of indices in the sequence.
Definition index_sequence.hh:130
A vector that misuses the begin, end and capacity pointers to store elements.
Definition small_vector.hh:26
auto cend() const -> const_iterator
Get a const iterator to the end of the vector.
Definition small_vector.hh:171
auto cbegin() const -> const_iterator
Get a const iterator to the beginning of the vector.
Definition small_vector.hh:154
auto begin() -> iterator
Get an iterator to the beginning of the vector.
Definition small_vector.hh:145
void emplace_back(U &&...args)
Emplace an element after the last element.
Definition small_vector.hh:285
auto end() -> iterator
Get an iterator to the end of the vector.
Definition small_vector.hh:157
auto back() -> reference
Get the last element in the vector.
Definition small_vector.hh:225
auto empty() const -> bool
Check if the vector is empty.
Definition small_vector.hh:130
auto size() const -> size_t
Get the size of the vector.
Definition small_vector.hh:122
void clear() noexcept
Clear the vector.
Definition small_vector.hh:314