14#ifndef OR_TOOLS_MATH_OPT_CPP_ID_SET_H_
15#define OR_TOOLS_MATH_OPT_CPP_ID_SET_H_
17#include <initializer_list>
22#include "absl/container/flat_hash_set.h"
78 return lhs.storage_iterator_ == rhs.storage_iterator_;
82 return lhs.storage_iterator_ != rhs.storage_iterator_;
90 typename StorageType::const_iterator storage_iterator);
92 const IdSet* set_ =
nullptr;
93 typename StorageType::const_iterator storage_iterator_;
102 template <
typename InputIt>
103 inline IdSet(InputIt first, InputIt last);
104 inline IdSet(std::initializer_list<value_type> ilist);
115 bool empty()
const {
return set_.empty(); }
120 inline std::pair<const_iterator, bool>
insert(
const K& k);
121 template <
typename InputIt>
122 inline void insert(InputIt first, InputIt last);
123 inline void insert(std::initializer_list<value_type> ilist);
125 inline std::pair<const_iterator, bool>
emplace(
const K& k);
128 inline int erase(
const K& k);
131 inline void erase(const_iterator pos);
132 inline const_iterator
erase(const_iterator first, const_iterator last);
137 inline bool contains(
const K& k)
const;
138 inline const_iterator
find(
const K& k)
const;
139 inline std::pair<const_iterator, const_iterator>
equal_range(
146 return lhs.storage_ == rhs.storage_ && lhs.set_ == rhs.set_;
149 return !(lhs == rhs);
156 inline void CheckModel(
const K& k)
const;
160 inline void CheckOrSetModel(
const K& k);
187 return K(set_->storage_, *storage_iterator_);
211 const IdSet* set,
typename StorageType::const_iterator storage_iterator)
212 : set_(set), storage_iterator_(
std::move(storage_iterator)) {}
220 : storage_(
storage), set_(
std::move(values)) {
222 CHECK(storage_ !=
nullptr);
227template <
typename InputIt>
270template <
typename InputIt>
272 for (InputIt it = first; it != last; ++it) {
279 insert(ilist.begin(), ilist.end());
286 auto initial_ret = set_.emplace(k.typed_id());
287 return std::make_pair(
const_iterator(
this, std::move(initial_ret.first)),
294 const int ret = set_.erase(k.typed_id());
303 set_.erase(pos.storage_iterator_);
312 auto ret = set_.erase(first.storage_iterator_, last.storage_iterator_);
322 swap(storage_, other.storage_);
323 swap(set_, other.set_);
329 return set_.count(k.typed_id());
335 return set_.contains(k.typed_id());
347 const auto it = find(k);
357 CHECK(storage_ ==
nullptr || storage_ == k.storage())
362void IdSet<K>::CheckOrSetModel(
const K& k) {
364 if (storage_ ==
nullptr) {
365 storage_ = k.storage();
#define CHECK_EQ(val1, val2)
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)
const StorageType & raw_set() const
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
friend bool operator==(const IdSet &lhs, const IdSet &rhs)
std::pair< const_iterator, bool > insert(const K &k)
const_iterator cbegin() const
typename StorageType::difference_type difference_type
const_iterator find(const K &k) const
friend bool operator!=(const IdSet &lhs, const IdSet &rhs)
const ModelStorage * storage() const
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