14#ifndef OR_TOOLS_MATH_OPT_CORE_MODEL_SUMMARY_H_
15#define OR_TOOLS_MATH_OPT_CORE_MODEL_SUMMARY_H_
18#include <initializer_list>
24#include "absl/container/flat_hash_map.h"
25#include "absl/strings/string_view.h"
45 IdNameBiMap(std::initializer_list<std::pair<int64_t, absl::string_view>> ids);
49 inline void Insert(int64_t
id, std::string
name);
52 inline void Erase(int64_t
id);
54 inline bool HasId(int64_t
id)
const;
56 inline bool Empty()
const;
57 inline int Size()
const;
66 return nonempty_name_to_id_;
73 absl::flat_hash_map<absl::string_view, int64_t> nonempty_name_to_id_;
86 if (!id_to_name_.empty()) {
89 const auto [it, success] = id_to_name_.emplace(
id, std::move(
name));
90 CHECK(success) <<
"id: " << id;
91 const absl::string_view name_view(it->second);
92 if (!name_view.empty()) {
98 const auto it = id_to_name_.find(
id);
99 CHECK(it != id_to_name_.end()) << id;
100 const absl::string_view name_view(it->second);
101 if (!name_view.empty()) {
102 CHECK_EQ(1, nonempty_name_to_id_.erase(name_view))
103 <<
"name: " << name_view <<
" id: " << id;
105 id_to_name_.erase(it);
108 return id_to_name_.contains(
id);
112 return nonempty_name_to_id_.contains(
name);
121 return id_to_name_.back().first;
#define CHECK_EQ(val1, val2)
#define CHECK_GT(val1, val2)
bool HasName(absl::string_view name) const
bool HasId(int64_t id) const
int64_t LargestId() const
const gtl::linked_hash_map< int64_t, std::string > & id_to_name() const
void Insert(int64_t id, std::string name)
const absl::flat_hash_map< absl::string_view, int64_t > & nonempty_name_to_id() const
void InsertOrDie(Collection *const collection, const typename Collection::value_type &value)
Collection of objects used to extend the Constraint Solver library.
IdNameBiMap linear_constraints