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.model_ == rhs.model_ && lhs.set_ == rhs.set_;
149 return !(lhs == rhs);
156 inline void CheckModel(
const K& k)
const;
160 inline void CheckOrSetModel(
const K& k);
171 template <
typename K>
184 template <
typename K>
187 return K(set_->model_, *storage_iterator_);
190 template <
typename K>
196 template <
typename K>
202 template <
typename K>
209 template <
typename K>
211 const IdSet* set,
typename StorageType::const_iterator storage_iterator)
212 : set_(set), storage_iterator_(std::move(storage_iterator)) {}
218 template <
typename K>
220 : model_(
model), set_(std::move(values)) {
222 CHECK(model_ !=
nullptr);
226 template <
typename K>
227 template <
typename InputIt>
232 template <
typename K>
237 template <
typename K>
242 template <
typename K>
247 template <
typename K>
252 template <
typename K>
257 template <
typename K>
263 template <
typename K>
269 template <
typename K>
270 template <
typename InputIt>
272 for (InputIt it = first; it != last; ++it) {
277 template <
typename K>
279 insert(ilist.begin(), ilist.end());
282 template <
typename K>
286 auto initial_ret = set_.emplace(k.typed_id());
287 return std::make_pair(
const_iterator(
this, std::move(initial_ret.first)),
291 template <
typename K>
294 const int ret = set_.erase(k.typed_id());
301 template <
typename K>
303 set_.erase(pos.storage_iterator_);
309 template <
typename K>
312 auto ret = set_.erase(first.storage_iterator_, last.storage_iterator_);
319 template <
typename K>
322 swap(model_, other.model_);
323 swap(set_, other.set_);
326 template <
typename K>
329 return set_.count(k.typed_id());
332 template <
typename K>
335 return set_.contains(k.typed_id());
338 template <
typename K>
344 template <
typename K>
347 const auto it = find(k);
354 template <
typename K>
357 CHECK(model_ ==
nullptr || model_ == k.model())
361 template <
typename K>
362 void IdSet<K>::CheckOrSetModel(
const K& k) {
364 if (model_ ==
nullptr) {
374 #endif // OR_TOOLS_MATH_OPT_CPP_ID_SET_H_
const_iterator find(const K &k) const
IdSet::difference_type difference_type
constexpr absl::string_view kObjectsFromOtherIndexedModel
friend bool operator==(const const_iterator &lhs, const const_iterator &rhs)
bool contains(const K &k) const
size_type count(const K &k) const
void swap(IdMap< K, V > &a, IdMap< K, V > &b)
std::pair< const_iterator, const_iterator > equal_range(const K &k) const
typename StorageType::difference_type difference_type
typename StorageType::size_type size_type
IdSet::const_pointer pointer
const_iterator cbegin() const
const StorageType & raw_set() const
IdSet::const_reference reference
absl::flat_hash_set< IdType > StorageType
const_iterator & operator++()
internal::ArrowOperatorProxy< reference > operator->() const
std::pair< const_iterator, bool > emplace(const K &k)
const_iterator begin() const
IndexedModel * model() const
constexpr absl::string_view kKeyHasNullIndexedModel
std::forward_iterator_tag iterator_category
#define CHECK_EQ(val1, val2)
std::pair< const_iterator, bool > insert(const K &k)
void reserve(size_type count)
const_iterator cend() const
const_iterator end() const
friend bool operator==(const IdSet &lhs, const IdSet &rhs)
IdSet::value_type value_type
friend bool operator!=(const const_iterator &lhs, const const_iterator &rhs)
Collection of objects used to extend the Constraint Solver library.
typename K::IdType IdType
friend bool operator!=(const IdSet &lhs, const IdSet &rhs)
const_reference operator *() const
void swap(IdSet< K > &a, IdSet< K > &b)