 |
OR-Tools
8.0
|
Go to the documentation of this file.
16 #ifndef OR_TOOLS_UTIL_VECTOR_MAP_H_
17 #define OR_TOOLS_UTIL_VECTOR_MAP_H_
21 #include "absl/container/flat_hash_map.h"
34 int Add(
const T& element) {
35 int current_index =
Index(element);
36 if (current_index != -1) {
39 const int index = list_.size();
40 CHECK_EQ(
index, map_.size());
41 list_.push_back(element);
42 map_[element] =
index;
48 void Add(
const std::vector<T>& elements) {
49 for (
int i = 0; i < elements.size(); ++i) {
61 int Index(
const T& element)
const {
74 CHECK_LT(
index, list_.size());
81 int size()
const {
return list_.size(); }
90 const std::vector<T>&
list()
const {
return list_; }
112 std::vector<T> list_;
113 absl::flat_hash_map<T, int> map_;
117 #endif // OR_TOOLS_UTIL_VECTOR_MAP_H_
void Add(const std::vector< T > &elements)
const T & const_reference
int Index(const T &element) const
const_iterator begin() const
const T & operator[](int index) const
const Collection::value_type::second_type & FindWithDefault(const Collection &collection, const typename Collection::value_type::first_type &key, const typename Collection::value_type::second_type &value)
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...
const_reverse_iterator rbegin() const
const T & Element(int index) const
ptrdiff_t difference_type
const Collection::value_type::second_type & FindOrDie(const Collection &collection, const typename Collection::value_type::first_type &key)
static const size_type npos
const std::vector< T > & list() const
const_iterator end() const
int IndexOrDie(const T &element) const
bool Contains(const T &element) const
std::reverse_iterator< const_iterator > const_reverse_iterator
int Add(const T &element)
const_reverse_iterator rend() const
bool ContainsKey(const Collection &collection, const Key &key)