Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
|
#include <model_summary.h>
Public Member Functions | |
IdNameBiMap (bool check_names=true) | |
IdNameBiMap (const IdNameBiMap &other) | |
IdNameBiMap & | operator= (const IdNameBiMap &other) |
IdNameBiMap (IdNameBiMap &&other)=default | |
IdNameBiMap & | operator= (IdNameBiMap &&other)=default |
IdNameBiMap (std::initializer_list< std::pair< int64_t, absl::string_view > > ids) | |
absl::Status | Insert (int64_t id, std::string name) |
absl::Status | Erase (int64_t id) |
Removes the given id, or returns an error if id is not present. | |
bool | HasId (int64_t id) const |
bool | HasName (absl::string_view name) const |
Will always return false if name is empty or if check_names was false. | |
bool | Empty () const |
int | Size () const |
int64_t | next_free_id () const |
absl::Status | SetNextFreeId (int64_t new_next_free_id) |
const gtl::linked_hash_map< int64_t, std::string > & | id_to_name () const |
Iteration order is in increasing id order. | |
const std::optional< absl::flat_hash_map< absl::string_view, int64_t > > & | nonempty_name_to_id () const |
Is std::nullopt if check_names was false at construction. | |
absl::Status | BulkUpdate (absl::Span< const int64_t > deleted_ids, absl::Span< const int64_t > new_ids, absl::Span< const std::string *const > names) |
Maintains a bidirectional mapping between names and ids, e.g. as used for variables and linear constraints.
The following invariants are enforced:
Definition at line 50 of file model_summary.h.
|
inlineexplicit |
If check_names=false, the names need not be unique and the reverse mapping of name to id is not available.
Definition at line 54 of file model_summary.h.
operations_research::math_opt::IdNameBiMap::IdNameBiMap | ( | const IdNameBiMap & | other | ) |
Needs a custom copy constructor/assign because absl::string_view to internal data is held as a member. No custom move is needed.
Definition at line 70 of file model_summary.cc.
|
default |
operations_research::math_opt::IdNameBiMap::IdNameBiMap | ( | std::initializer_list< std::pair< int64_t, absl::string_view > > | ids | ) |
This constructor CHECKs that the input ids are sorted in increasing order. This constructor is expected to be used only for unit tests of validation code.
Definition at line 62 of file model_summary.cc.
absl::Status operations_research::math_opt::IdNameBiMap::BulkUpdate | ( | absl::Span< const int64_t > | deleted_ids, |
absl::Span< const int64_t > | new_ids, | ||
absl::Span< const std::string *const > | names ) |
Definition at line 95 of file model_summary.cc.
|
inline |
Definition at line 209 of file model_summary.h.
|
inline |
Removes the given id, or returns an error if id is not present.
CHECK OK, name_view being in nonempty_name_to_id_ when the above is met is a class invariant.
Definition at line 179 of file model_summary.h.
|
inline |
Definition at line 196 of file model_summary.h.
|
inline |
Will always return false if name is empty or if check_names was false.
Definition at line 199 of file model_summary.h.
|
inline |
Iteration order is in increasing id order.
Definition at line 102 of file model_summary.h.
|
inline |
Inserts the provided id and associate the provided name to it.
An error is returned if:
As a side effect it updates next_free_id to id + 1.
Inline function implementations
larger than everything in the map.
Definition at line 152 of file model_summary.h.
|
inline |
The next id that has never been used (0 initially since ids are non-negative).
Definition at line 213 of file model_summary.h.
|
inline |
Is std::nullopt if check_names was false at construction.
Definition at line 108 of file model_summary.h.
IdNameBiMap & operations_research::math_opt::IdNameBiMap::operator= | ( | const IdNameBiMap & | other | ) |
non nullopt nonempty_name_to_id_.
Definition at line 72 of file model_summary.cc.
|
default |
|
inline |
Updates next_free_id(). Succeeds when the provided id is greater than every exiting id and is non-negative.
Definition at line 215 of file model_summary.h.
|
inline |
Definition at line 211 of file model_summary.h.