17 #ifndef OR_TOOLS_MATH_OPT_CPP_ID_SET_H_
18 #define OR_TOOLS_MATH_OPT_CPP_ID_SET_H_
20 #include <initializer_list>
24 #include "absl/container/flat_hash_set.h"
25 #include "absl/log/check.h"
81 return lhs.storage_iterator_ == rhs.storage_iterator_;
85 return lhs.storage_iterator_ != rhs.storage_iterator_;
93 typename StorageType::const_iterator storage_iterator);
95 const IdSet* set_ =
nullptr;
96 typename StorageType::const_iterator storage_iterator_;
105 template <
typename InputIt>
106 inline IdSet(InputIt first, InputIt last);
107 inline IdSet(std::initializer_list<value_type> ilist);
118 bool empty()
const {
return set_.empty(); }
123 inline std::pair<const_iterator, bool>
insert(
const K& k);
124 template <
typename InputIt>
125 inline void insert(InputIt first, InputIt last);
126 inline void insert(std::initializer_list<value_type> ilist);
128 inline std::pair<const_iterator, bool>
emplace(
const K& k);
134 inline void erase(const_iterator pos);
135 inline const_iterator
erase(const_iterator first, const_iterator last);
140 inline bool contains(
const K& k)
const;
141 inline const_iterator
find(
const K& k)
const;
142 inline std::pair<const_iterator, const_iterator>
equal_range(
149 return lhs.storage_ == rhs.storage_ && lhs.set_ == rhs.set_;
152 return !(lhs == rhs);
159 inline void CheckModel(
const K& k)
const;
163 inline void CheckOrSetModel(
const K& k);
174 template <
typename K>
187 template <
typename K>
190 return K(set_->storage_, *storage_iterator_);
193 template <
typename K>
199 template <
typename K>
205 template <
typename K>
212 template <
typename K>
214 const IdSet* set,
typename StorageType::const_iterator storage_iterator)
215 : set_(set), storage_iterator_(std::move(storage_iterator)) {}
221 template <
typename K>
223 : storage_(values.
empty() ? nullptr :
storage), set_(std::move(values)) {
225 CHECK(storage_ !=
nullptr);
229 template <
typename K>
230 template <
typename InputIt>
235 template <
typename K>
240 template <
typename K>
245 template <
typename K>
250 template <
typename K>
255 template <
typename K>
260 template <
typename K>
266 template <
typename K>
272 template <
typename K>
273 template <
typename InputIt>
275 for (InputIt it = first; it != last; ++it) {
280 template <
typename K>
282 insert(ilist.begin(), ilist.end());
285 template <
typename K>
289 auto initial_ret = set_.emplace(k.typed_id());
290 return std::make_pair(
const_iterator(
this, std::move(initial_ret.first)),
294 template <
typename K>
297 const size_type ret = set_.erase(k.typed_id());
304 template <
typename K>
306 set_.erase(pos.storage_iterator_);
312 template <
typename K>
315 auto ret = set_.erase(first.storage_iterator_, last.storage_iterator_);
322 template <
typename K>
325 swap(storage_, other.storage_);
326 swap(set_, other.set_);
329 template <
typename K>
332 return set_.count(k.typed_id());
335 template <
typename K>
338 return set_.contains(k.typed_id());
341 template <
typename K>
347 template <
typename K>
350 const auto it = find(k);
357 template <
typename K>
360 CHECK(storage_ ==
nullptr || storage_ == k.storage())
364 template <
typename K>
365 void IdSet<K>::CheckOrSetModel(
const K& k) {
367 if (storage_ ==
nullptr) {
368 storage_ = k.storage();
friend bool operator!=(const const_iterator &lhs, const const_iterator &rhs)
IdSet::const_reference reference
IdSet::difference_type difference_type
IdSet::const_pointer pointer
IdSet::value_type value_type
std::forward_iterator_tag iterator_category
const_reference operator*() const
friend bool operator==(const const_iterator &lhs, const const_iterator &rhs)
internal::ArrowOperatorProxy< reference > operator->() const
const_iterator & operator++()
size_type count(const K &k) const
void reserve(size_type count)
absl::flat_hash_set< IdType > StorageType
const_iterator end() const
std::pair< const_iterator, bool > emplace(const K &k)
bool contains(const K &k) const
const_iterator cend() const
typename StorageType::size_type size_type
const_iterator begin() const
std::pair< const_iterator, const_iterator > equal_range(const K &k) const
typename K::IdType IdType
size_type erase(const K &k)
friend bool operator==(const IdSet &lhs, const IdSet &rhs)
std::pair< const_iterator, bool > insert(const K &k)
const ModelStorage * storage() const
const_iterator cbegin() const
const StorageType & raw_set() const
typename StorageType::difference_type difference_type
const_iterator find(const K &k) const
friend bool operator!=(const IdSet &lhs, const IdSet &rhs)
constexpr absl::string_view kKeyHasNullModelStorage
constexpr absl::string_view kObjectsFromOtherModelStorage
void swap(IdMap< K, V > &a, IdMap< K, V > &b)
void swap(IdSet< K > &a, IdSet< K > &b)
Collection of objects used to extend the Constraint Solver library.
std::optional< int64_t > end