Google OR-Tools: ortools/base/map_util.h Source File
14#ifndef ORTOOLS_BASE_MAP_UTIL_H_
15#define ORTOOLS_BASE_MAP_UTIL_H_
21namespace gtl {
35template <typename Collection, typename KeyType = MapUtilKeyT<Collection>>
37 const Collection& collection, const KeyType& key,
39 typename Collection::const_iterator it = collection.find(key);
49template <class Collection, typename KeyType = MapUtilKeyT<Collection>>
65const typename Collection::value_type::second_type* FindOrNull(
66 const Collection& collection,
67 const typename Collection::value_type::first_type& key) {
68 typename Collection::const_iterator it = collection.find(key);
79typename Collection::value_type::second_type* FindOrNull(
81 const typename Collection::value_type::first_type& key) {
82 typename Collection::iterator it = collection.find(key);
94const typename Collection::value_type::second_type FindPtrOrNull(
95 const Collection& collection,
96 const typename Collection::value_type::first_type& key) {
97 typename Collection::const_iterator it = collection.find(key);
109template <class Collection, class Key, class Value>
112 std::pair<typename Collection::iterator, bool> ret =
113 collection->insert(typename Collection::value_type(key, value));
126template <class Collection>
128 const typename Collection::value_type& value) {
129 std::pair<typename Collection::iterator, bool> ret =
138template <class Collection, class Key, class Value>
141 std::pair<typename Collection::iterator, bool> ret =
142 collection->insert(typename Collection::value_type(key, value));
149template <class Collection>
158template <class Collection>
160 const typename Collection::value_type& value) {
161 CHECK(collection->insert(value).second) << "duplicate value: " << value;
166template <class Collection>
168 const typename Collection::value_type::first_type& key,
169 const typename Collection::value_type::second_type& data) {
170 typedef typename Collection::value_type value_type;
171 CHECK(collection->insert(value_type(key, data)).second)
177template <typename Collection>
179 const typename Collection::value_type::first_type& key) {
180 auto [it, did_insert] = collection->insert(typename Collection::value_type(
181 key, typename Collection::value_type::second_type()));
189template <class Collection, class Key, class Value>
190bool FindCopy(const Collection& collection, const Key& key,
192 typename Collection::const_iterator it = collection.find(key);
204template <class Collection, class Key>
205bool ContainsKey(const Collection& collection, const Key& key) {
206 typename Collection::const_iterator it = collection.find(key);
210template <class Collection>
211const typename Collection::value_type::second_type& FindOrDie(
212 const Collection& collection,
213 const typename Collection::value_type::first_type& key) {
214 typename Collection::const_iterator it = collection.find(key);
215 CHECK(it != collection.end()) << "Map key not found: " << key;
220template <class Collection>
222 const Collection& collection,
223 const typename Collection::value_type::first_type& key) {
224 typename Collection::const_iterator it = collection.find(key);
230template <class Collection>
233 const typename Collection::value_type::first_type& key) {
234 typename Collection::iterator it = collection.find(key);
241template <class Collection>
243 Collection* const collection,
244 const typename Collection::value_type::first_type& key,
245 const typename Collection::value_type::second_type& value) {
246 std::pair<typename Collection::iterator, bool> ret =
247 collection->insert(typename Collection::value_type(key, value));
typename MapUtilValueT< M >::second_type MapUtilMappedT
Definition map_util.h:27
const Collection::value_type::second_type FindPtrOrNull(const Collection &collection, const typename Collection::value_type::first_type &key)
Definition map_util.h:94
bool InsertOrUpdate(Collection *const collection, const Key &key, const Value &value)
Definition map_util.h:110
void InsertOrDieNoPrint(Collection *const collection, const typename Collection::value_type &value)
Definition map_util.h:150
typename MapUtilValueT< M >::first_type MapUtilKeyT
Definition map_util.h:25
bool InsertIfNotPresent(Collection *const collection, const typename Collection::value_type &value)
Definition map_util.h:127
Collection::value_type::second_type & LookupOrInsert(Collection *const collection, const typename Collection::value_type::first_type &key, const typename Collection::value_type::second_type &value)
Definition map_util.h:242
typename M::value_type MapUtilValueT
Definition map_util.h:23
void InsertOrDie(Collection *const collection, const typename Collection::value_type &value)
Definition map_util.h:159
bool FindCopy(const Collection &collection, const Key &key, Value *const value)
Definition map_util.h:190
const Collection::value_type::second_type & FindOrDie(const Collection &collection, const typename Collection::value_type::first_type &key)
Definition map_util.h:211
const Collection::value_type::second_type & FindOrDieNoPrint(const Collection &collection, const typename Collection::value_type::first_type &key)
Definition map_util.h:221
const Collection::value_type::second_type * FindOrNull(const Collection &collection, const typename Collection::value_type::first_type &key)
Definition map_util.h:65
bool ContainsKey(const Collection &collection, const Key &key)
Definition map_util.h:205
auto & InsertKeyOrDie(Collection *const collection, const typename Collection::value_type::first_type &key)
Definition map_util.h:178
const MapUtilMappedT< Collection > & FindWithDefault(const Collection &collection, const KeyType &key, const MapUtilMappedT< Collection > &value)
Definition map_util.h:36