diff --git a/examples/cpp/acp_challenge.cc b/examples/cpp/acp_challenge.cc index 8ca7d336bb..4d819cf01c 100644 --- a/examples/cpp/acp_challenge.cc +++ b/examples/cpp/acp_challenge.cc @@ -210,7 +210,7 @@ class RandomIntervalLns : public BaseLns { break; } case 3: { - hash_set to_release; + std::unordered_set to_release; while (to_release.size() < num_product_) { to_release.insert(rand_.Uniform(item_to_product_.back() + 1)); } @@ -328,7 +328,7 @@ class NRandomSwaps : public IntVarLocalSearchOperator { // Make a neighbor assigning one variable to its target value. virtual bool MakeOneNeighbor() { const int num_swaps = rand_.Uniform(num_swaps_ - 1) + 2; - hash_set inserted; + std::unordered_set inserted; for (int i = 0; i < num_swaps; ++i) { int index1 = rand_.Uniform(Size()); while (ContainsKey(inserted, index1)) { @@ -778,7 +778,7 @@ void Solve(const std::string& filename, const std::string& solution_file) { solver.MakeIsEqualCstVar(products[0], -1))); // Redundant due date constraints on non variables. - hash_set due_date_set(due_dates.begin(), due_dates.end()); + std::unordered_set due_date_set(due_dates.begin(), due_dates.end()); for (const int due_date : due_date_set) { std::vector outside; int inside_count = 0; diff --git a/examples/cpp/dimacs_assignment.cc b/examples/cpp/dimacs_assignment.cc index 8e4a9981aa..29ea802e22 100644 --- a/examples/cpp/dimacs_assignment.cc +++ b/examples/cpp/dimacs_assignment.cc @@ -91,8 +91,8 @@ CostValue BuildAndSolveHungarianInstance( hungarian_cost[tail][head] = cost; } } - hash_map result; - hash_map wish_this_could_be_null; + std::unordered_map result; + std::unordered_map wish_this_could_be_null; WallTimer timer; VLOG(1) << "Beginning Hungarian method."; timer.Start(); diff --git a/examples/cpp/fap_parser.cc b/examples/cpp/fap_parser.cc index d107022a3c..da30ec180d 100644 --- a/examples/cpp/fap_parser.cc +++ b/examples/cpp/fap_parser.cc @@ -190,7 +190,7 @@ void ParametersParser::Parse() { void FindComponents(const std::vector& constraints, const std::map& variables, const int maximum_variable_id, - hash_map* components) { + std::unordered_map* components) { std::vector in_component(maximum_variable_id + 1, -1); int constraint_index = 0; for (const FapConstraint& constraint : constraints) { @@ -297,7 +297,7 @@ void ParseInstance(const std::string& data_directory, bool find_components, std::map* variables, std::vector* constraints, std::string* objective, std::vector* frequencies, - hash_map* components) { + std::unordered_map* components) { CHECK_NOTNULL(variables); CHECK_NOTNULL(constraints); CHECK_NOTNULL(objective); diff --git a/examples/cpp/fap_parser.h b/examples/cpp/fap_parser.h index bafc4df3e3..87976e0264 100644 --- a/examples/cpp/fap_parser.h +++ b/examples/cpp/fap_parser.h @@ -234,7 +234,7 @@ class ParametersParser { void FindComponents(const std::vector& constraints, const std::map& variables, const int maximum_variable_id, - hash_map* components); + std::unordered_map* components); // Function that computes the impact of a constraint. int EvaluateConstraintImpact(const std::map& variables, @@ -246,6 +246,6 @@ void ParseInstance(const std::string& data_directory, bool find_components, std::map* variables, std::vector* constraints, std::string* objective, std::vector* frequencies, - hash_map* components); + std::unordered_map* components); } // namespace operations_research #endif // OR_TOOLS_EXAMPLES_FAP_PARSER_H_ diff --git a/examples/cpp/frequency_assignment_problem.cc b/examples/cpp/frequency_assignment_problem.cc index 8772668158..430ede4e71 100644 --- a/examples/cpp/frequency_assignment_problem.cc +++ b/examples/cpp/frequency_assignment_problem.cc @@ -331,7 +331,7 @@ bool ConstraintImpactComparator(FapConstraint constraint1, } int64 ValueEvaluator( - hash_map>* value_evaluator_map, + std::unordered_map>* value_evaluator_map, int64 variable_index, int64 value) { CHECK_NOTNULL(value_evaluator_map); // Evaluate the choice. Smaller ranking denotes a better choice. @@ -344,7 +344,7 @@ int64 ValueEvaluator( } // Update the history of assigned values and their rankings of each variable. - hash_map>::iterator it; + std::unordered_map>::iterator it; int64 new_value = value; int64 new_ranking = ranking; if ((it = value_evaluator_map->find(variable_index)) != @@ -579,7 +579,7 @@ void HardFapSolver(const std::map& data_variables, ChooseVariableStrategy(&variable_strategy); // Choose the value selection strategy. DecisionBuilder* db; - hash_map> history; + std::unordered_map> history; if (FLAGS_value_evaluator == "value_evaluator") { LOG(INFO) << "Using ValueEvaluator for value selection strategy."; Solver::IndexEvaluator2 index_evaluator2 = [&history](int64 var, @@ -864,7 +864,7 @@ int main(int argc, char** argv) { std::vector constraints; std::string objective; std::vector values; - hash_map components; + std::unordered_map components; operations_research::ParseInstance(FLAGS_directory, FLAGS_find_components, &variables, &constraints, &objective, &values, &components); diff --git a/examples/cpp/global_arith.cc b/examples/cpp/global_arith.cc index 182d2952be..66216e8275 100644 --- a/examples/cpp/global_arith.cc +++ b/examples/cpp/global_arith.cc @@ -36,14 +36,14 @@ class SubstitutionMap { } void ProcessAllSubstitutions(Callback3* const hook) { - for (hash_map::const_iterator it = substitutions_.begin(); + for (std::unordered_map::const_iterator it = substitutions_.begin(); it != substitutions_.end(); ++it) { hook->Run(it->first, it->second.var_index, it->second.offset); } } private: - hash_map substitutions_; + std::unordered_map substitutions_; }; // ----- Bounds ----- @@ -90,7 +90,7 @@ class BoundsStore { : initial_bounds_(initial_bounds) {} void SetRange(int var_index, int64 lb, int64 ub) { - hash_map::iterator it = modified_bounds_.find(var_index); + std::unordered_map::iterator it = modified_bounds_.find(var_index); if (it == modified_bounds_.end()) { Bounds new_bounds(lb, ub); const Bounds& initial = (*initial_bounds_)[var_index]; @@ -107,14 +107,14 @@ class BoundsStore { modified_bounds_.clear(); } - const hash_map& modified_bounds() const { + const std::unordered_map& modified_bounds() const { return modified_bounds_; } vector* initial_bounds() const { return initial_bounds_; } void Apply() { - for (hash_map::const_iterator it = modified_bounds_.begin(); + for (std::unordered_map::const_iterator it = modified_bounds_.begin(); it != modified_bounds_.end(); ++it) { (*initial_bounds_)[it->first] = it->second; @@ -123,7 +123,7 @@ class BoundsStore { private: vector* initial_bounds_; - hash_map modified_bounds_; + std::unordered_map modified_bounds_; }; // ----- ArithmeticConstraint ----- @@ -193,7 +193,7 @@ class ArithmeticPropagator : PropagationBaseObject { const vector vars() const { return vars_; } int VarIndex(IntVar* const var) { - hash_map::const_iterator it = var_map_.find(var); + std::unordered_map::const_iterator it = var_map_.find(var); if (it == var_map_.end()) { const int index = var_map_.size(); var_map_[var] = index; @@ -236,12 +236,12 @@ class ArithmeticPropagator : PropagationBaseObject { private: Demon* const demon_; vector vars_; - hash_map var_map_; + std::unordered_map var_map_; vector constraints_; vector bounds_; vector > dependencies_; // from var indices to constraints. SubstitutionMap substitution_map_; - hash_set protected_constraints_; + std::unordered_set protected_constraints_; }; // ----- Custom Constraints ----- @@ -261,9 +261,9 @@ class RowConstraint : public ArithmeticConstraint { } virtual void Replace(int to_replace, int var, int64 offset) { - hash_map::iterator find_other = coefficients_.find(to_replace); + std::unordered_map::iterator find_other = coefficients_.find(to_replace); if (find_other != coefficients_.end()) { - hash_map::iterator find_var = coefficients_.find(var); + std::unordered_map::iterator find_var = coefficients_.find(var); const int64 other_coefficient = find_other->second; if (lb_ != kint64min) { lb_ += other_coefficient * offset; @@ -286,7 +286,7 @@ class RowConstraint : public ArithmeticConstraint { virtual bool Deduce(ArithmeticPropagator* const propagator) const { // Deduce Simple translation from one var to another. if (lb_ == ub_ && coefficients_.size() == 2) { - hash_map::const_iterator it = coefficients_.begin(); + std::unordered_map::const_iterator it = coefficients_.begin(); const int var1 = it->first; const int64 coeff1 = it->second; ++it; @@ -308,7 +308,7 @@ class RowConstraint : public ArithmeticConstraint { virtual string DebugString() const { string output = "("; bool first = true; - for (hash_map::const_iterator it = coefficients_.begin(); + for (std::unordered_map::const_iterator it = coefficients_.begin(); it != coefficients_.end(); ++it) { if (it->second != 0) { @@ -344,7 +344,7 @@ class RowConstraint : public ArithmeticConstraint { return output; } private: - hash_map coefficients_; + std::unordered_map coefficients_; int64 lb_; int64 ub_; }; @@ -562,7 +562,7 @@ void GlobalArithmeticConstraint::Add(ConstraintRef ref) { } int GlobalArithmeticConstraint::VarIndex(IntVar* const var) { - hash_map::const_iterator it = var_indices_.find(var); + std::unordered_map::const_iterator it = var_indices_.find(var); if (it == var_indices_.end()) { const int new_index = var_indices_.size(); var_indices_.insert(make_pair(var, new_index)); diff --git a/examples/cpp/global_arith.h b/examples/cpp/global_arith.h index bd0f1811f7..2732464f19 100644 --- a/examples/cpp/global_arith.h +++ b/examples/cpp/global_arith.h @@ -92,7 +92,7 @@ class GlobalArithmeticConstraint : public Constraint { ConstraintRef Store(ArithmeticConstraint* const constraint); scoped_ptr propagator_; - hash_map var_indices_; + std::unordered_map var_indices_; vector constraints_; }; diff --git a/examples/cpp/jobshop_earlytardy.cc b/examples/cpp/jobshop_earlytardy.cc index dfdf447742..8f75c68437 100644 --- a/examples/cpp/jobshop_earlytardy.cc +++ b/examples/cpp/jobshop_earlytardy.cc @@ -92,7 +92,7 @@ class TimePlacement : public DecisionBuilder { virtual Decision* Next(Solver* const solver) { mp_solver_.Clear(); std::vector > all_vars; - hash_map mapping; + std::unordered_map mapping; const double infinity = mp_solver_.infinity(); all_vars.resize(all_sequences_.size()); diff --git a/examples/cpp/network_routing.cc b/examples/cpp/network_routing.cc index 702da28e70..414beb4680 100644 --- a/examples/cpp/network_routing.cc +++ b/examples/cpp/network_routing.cc @@ -147,13 +147,8 @@ class NetworkRoutingData { int num_nodes_; int max_capacity_; int fixed_charge_cost_; -#if defined(_MSC_VER) - hash_map, int, PairIntHasher> all_arcs_; - hash_map, int, PairIntHasher> all_demands_; -#else - hash_map, int> all_arcs_; - hash_map, int> all_demands_; -#endif + std::unordered_map, int> all_arcs_; + std::unordered_map, int> all_demands_; }; // ----- Data Generation ----- @@ -231,8 +226,8 @@ class NetworkRoutingDataBuilder { AddEdge(i, j); } - hash_set to_complete; - hash_set not_full; + std::unordered_set to_complete; + std::unordered_set not_full; for (int i = 0; i < num_backbones; ++i) { if (degrees_[i] < min_backbone_degree) { to_complete.insert(i); @@ -356,7 +351,7 @@ struct Demand { class NetworkRoutingSolver { public: - typedef hash_set OnePath; + typedef std::unordered_set OnePath; NetworkRoutingSolver() : arcs_data_(3), num_nodes_(-1) {} @@ -403,7 +398,7 @@ class NetworkRoutingSolver { // This method will fill the all_paths_ data structure. all_paths // contains, for each demand, a vector of possible paths, stored as - // a hash_set of arc indices. + // a std::unordered_set of arc indices. int ComputeAllPaths(int extra_hops, int max_paths) { int num_paths = 0; for (int demand_index = 0; demand_index < demands_array_.size(); @@ -614,7 +609,7 @@ class NetworkRoutingSolver { bool NextFragment() override { // First we select a set of arcs to release. - hash_set arcs_to_release; + std::unordered_set arcs_to_release; if (arc_wrappers_.size() <= fragment_size_) { // There are not enough used arcs, we will release all of them. for (int index = 0; index < arc_wrappers_.size(); ++index) { diff --git a/ortools/base/base.i b/ortools/base/base.i index e376bc468f..761579a748 100644 --- a/ortools/base/base.i +++ b/ortools/base/base.i @@ -44,13 +44,7 @@ %{ #include -#ifdef __GNUC__ -#include -#include -#else -#include -#include -#endif +#include #include #include #include @@ -123,14 +117,14 @@ } %typemap(in,numinputs=0) std::vector* OUTPUT (std::vector temp), - hash_set* OUTPUT (hash_set temp), + std::unordered_set* OUTPUT (std::unordered_set temp), std::set* OUTPUT (std::set temp) { $1 = &temp; } %typemap(argout) std::vector* OUTPUT, std::set* OUTPUT, - hash_set* OUTPUT { + std::unordered_set* OUTPUT { %append_output(list_output_helper($1, &py_converter)); } %typemap(out) std::vector { @@ -249,13 +243,7 @@ COPY_TYPEMAPS(uint64, Fprint); #ifdef SWIGJAVA %{ #include -#ifdef __GNUC__ -#include -#include -#else -#include -#include -#endif +#include #include #include #include @@ -379,13 +367,7 @@ COPY_TYPEMAPS(unsigned long long, uint64); %include "enumsimple.swg" %{ #include -#ifdef __GNUC__ -#include -#include -#else -#include -#include -#endif +#include #include #include #include diff --git a/ortools/base/hash.h b/ortools/base/hash.h index 05ed7e9202..0447290b96 100644 --- a/ortools/base/hash.h +++ b/ortools/base/hash.h @@ -14,17 +14,8 @@ #ifndef OR_TOOLS_BASE_HASH_H_ #define OR_TOOLS_BASE_HASH_H_ -// Hash maps and hash sets are compiler dependent. -#if defined(__GNUC__) && !defined(STLPORT) -#include -#include -namespace operations_research { -using namespace __gnu_cxx; // NOLINT -} // namespace operations_research -#else -#include -#include -#endif +#include +#include #include #include @@ -119,19 +110,8 @@ inline uint64 Hash64NumWithSeed(uint64 num, uint64 c) { } } // namespace operations_research -// -------------------------------------------------------------------------- -// GNU C++ port, with or without STLport. -// -------------------------------------------------------------------------- -#ifdef __GNUC__ -// hash namespace -#if defined(__GNUC__) && defined(STLPORT) -#define HASH_NAMESPACE std -#elif defined(__GNUC__) && !defined(STLPORT) -#define HASH_NAMESPACE __gnu_cxx -#endif - -// Support a few hash<> operators, in the hash namespace. -namespace HASH_NAMESPACE { +// Support a few hash<> operators, in the std namespace. +namespace std { template struct hash> { size_t operator()(const std::pair& p) const { @@ -145,41 +125,6 @@ struct hash> { } }; -template -struct hash { - size_t operator()(T* x) const { return reinterpret_cast(x); } -}; - -// hash and hash are already defined with STLport. -#ifndef STLPORT -template <> -struct hash { - size_t operator()(int64 x) const { return static_cast(x); } -}; - -template <> -struct hash { - size_t operator()(uint64 x) const { return static_cast(x); } -}; - -template <> -struct hash { - size_t operator()(const std::string& x) const { - size_t hash = 0; - int c; - const char* s = x.c_str(); - while ((c = *s++)) { // Extra () to remove a warning on Windows. - hash = ((hash << 5) + hash) ^ c; - } - return hash; - } -}; - -template <> -struct hash { - size_t operator()(const std::string& x) const { return hash()(x); } -}; - template struct hash> { public: @@ -199,258 +144,7 @@ struct hash> { static const size_t bucket_size = 4; // These are required by MSVC. static const size_t min_buckets = 8; // 4 and 8 are defaults. }; -#endif // STLPORT -} // namespace HASH_NAMESPACE - -using HASH_NAMESPACE::hash; -using HASH_NAMESPACE::hash_map; -using HASH_NAMESPACE::hash_set; -#endif // __GNUC__ - -#undef HASH_NAMESPACE - -// -------------------------------------------------------------------------- -// Microsoft Visual C++ port -// -------------------------------------------------------------------------- -#ifdef _MSC_VER -// TODO(user): Nuke this section and merge with the gcc version. -// The following class defines a hash function for std::pair. -template -class TypedIntHasher : public stdext::hash_compare { - public: - size_t operator()(const T& a) const { return static_cast(a.value()); } - bool operator()(const T& a1, const T& a2) const { - return a1.value() < a2.value(); - } -}; - -class PairInt64Hasher : public stdext::hash_compare> { - public: - size_t operator()(const std::pair& a) const { - uint64 x = a.first; - uint64 y = GG_ULONGLONG(0xe08c1d668b756f82); - uint64 z = a.second; - operations_research::mix(x, y, z); - return z; - } - bool operator()(const std::pair& a1, - const std::pair& a2) const { - return a1.first < a2.first || - (a1.first == a2.first && a1.second < a2.second); - } -}; - -class PairIntHasher : public stdext::hash_compare> { - public: - size_t operator()(const std::pair& a) const { - uint32 x = a.first; - uint32 y = 0x9e3779b9UL; - uint32 z = a.second; - operations_research::mix(x, y, z); - return z; - } - bool operator()(const std::pair& a1, - const std::pair& a2) const { - return a1.first < a2.first || - (a1.first == a2.first && a1.second < a2.second); - } -}; - -class PairPairInt64Hasher - : public stdext::hash_compare, int64>> { - public: - size_t operator()(const std::pair, int64>& a) const { - uint64 x = a.first.first; - uint64 y = a.first.second; - uint64 z = a.second; - operations_research::mix(x, y, z); - return z; - } - bool operator()(const std::pair, int64>& a1, - const std::pair, int64>& a2) const { - return a1.first.first < a2.first.first || - (a1.first.first == a2.first.first && - a1.first.second < a2.first.second) || - (a1.first.first == a2.first.first && - a1.first.second == a2.first.second && a1.second < a2.second); - } -}; - -// The following class defines a hash function for std::pair. -class PairIntInt64Hasher : public stdext::hash_compare> { - public: - size_t operator()(const std::pair& a) const { - uint64 x = a.first; - uint64 y = GG_ULONGLONG(0xe08c1d668b756f82); - uint64 z = a.second; - operations_research::mix(x, y, z); - return z; - } - bool operator()(const std::pair& a1, - const std::pair& a2) const { - return a1.first < a2.first || - (a1.first == a2.first && a1.second < a2.second); - } -}; - -// The following class defines a hash function for std::pair. -#if defined(_WIN64) -template -class PairPointerIntHasher : public stdext::hash_compare> { - public: - size_t operator()(const std::pair& a) const { - uint64 x = reinterpret_cast(a.first); - uint64 y = GG_ULONGLONG(0xe08c1d668b756f82); - uint64 z = static_cast(a.second); - operations_research::mix(x, y, z); - return z; - } - bool operator()(const std::pair& a1, - const std::pair& a2) const { - return a1.first < a2.first || - (a1.first == a2.first && a1.second < a2.second); - } -}; - -template -class PairPointerIntTypeHasher : public stdext::hash_compare> { - public: - size_t operator()(const std::pair& a) const { - uint64 x = reinterpret_cast(a.first); - uint64 y = GG_ULONGLONG(0xe08c1d668b756f82); - uint64 z = static_cast(a.second.Value()); - operations_research::mix(x, y, z); - return z; - } - bool operator()(const std::pair& a1, - const std::pair& a2) const { - return a1.first < a2.first || - (a1.first == a2.first && a1.second < a2.second); - } -}; -#else -template -class PairPointerIntHasher : public stdext::hash_compare> { - public: - size_t operator()(const std::pair& a) const { - uint32 x = reinterpret_cast(a.first); - uint32 y = 0x9e3779b9UL; - uint32 z = static_cast(a.second); - operations_research::mix(x, y, z); - return z; - } - bool operator()(const std::pair& a1, - const std::pair& a2) const { - return a1.first < a2.first || - (a1.first == a2.first && a1.second < a2.second); - } -}; - -template -class PairPointerIntTypeHasher : public stdext::hash_compare> { - public: - size_t operator()(const std::pair& a) const { - uint32 x = reinterpret_cast(a.first); - uint32 y = 0x9e3779b9UL; - uint32 z = static_cast(a.second.Value()); - operations_research::mix(x, y, z); - return z; - } - bool operator()(const std::pair& a1, - const std::pair& a2) const { - return a1.first < a2.first || - (a1.first == a2.first && a1.second < a2.second); - } -}; -#endif - -template -struct StdArrayHasher : public stdext::hash_compare> { - public: - size_t operator()(const std::array& t) const { - uint64 current = 71; - for (int index = 0; index < N; ++index) { - const T& elem = t[index]; - const uint64 new_hash = hash()(elem); - current = operations_research::Hash64NumWithSeed(current, new_hash); - } - return current; - } - // Less than operator for MSVC. - bool operator()(const std::array& a, const std::array& b) const { - return a < b; - } - static const size_t bucket_size = 4; // These are required by MSVC. - static const size_t min_buckets = 8; // 4 and 8 are defaults. -}; - -#if defined(_MSC_VER) -namespace stdext { -template <> -inline size_t hash_value>( - const std::pair& a) { - PairInt64Hasher pairInt64Hasher; - return pairInt64Hasher(a); -} -} // namespace stdext -#endif // _MSC_VER - -using std::hash; -using stdext::hash_map; -using stdext::hash_set; -#endif // _MSC_VER +} // namespace std #endif // SWIG - -#if !defined(STLPORT) -// Support a few hash<> operators, in the std namespace. -namespace std { -template -struct hash> { - size_t operator()(const pair& p) const { - size_t h1 = hash()(p.first); - size_t h2 = hash()(p.second); - // The decision below is at compile time - return (sizeof(h1) <= sizeof(uint32)) - ? // NOLINT - operations_research::Hash32NumWithSeed(h1, h2) - : operations_research::Hash64NumWithSeed(h1, h2); - } -}; - -template <> -struct hash { - size_t operator()(const string& x) const { - size_t hash = 0; - int c; - const char* s = x.c_str(); - while ((c = *s++)) { // Extra () to remove a warning on Windows. - hash = ((hash << 5) + hash) ^ c; - } - return hash; - } -}; - -template -struct hash> { - public: - size_t operator()(const array& t) const { - uint64 current = 71; - for (int index = 0; index < N; ++index) { - const T& elem = t[index]; - const uint64 new_hash = hash()(elem); - current = operations_research::Hash64NumWithSeed(current, new_hash); - } - return current; - } - // Less than operator for MSVC. - bool operator()(const array& a, const array& b) const { - return a < b; - } - static const size_t bucket_size = 4; // These are required by MSVC. - static const size_t min_buckets = 8; // 4 and 8 are defaults. -}; -} // namespace std -#endif // !STLPORT - #endif // OR_TOOLS_BASE_HASH_H_ diff --git a/ortools/base/int_type.h b/ortools/base/int_type.h index 899eed1850..d7ba11a7d4 100755 --- a/ortools/base/int_type.h +++ b/ortools/base/int_type.h @@ -86,7 +86,7 @@ // the stored value into protocol buffer fields and using it as printf args. // // The class also defines a hash functor that allows the IntType to be used -// as key to hashable containers such as hash_map and hash_set. +// as key to hashable containers such as std::unordered_{map|set}. // // We suggest using the IntTypeIndexedContainer wrapper around STL // std::vector (see int_type_indexed_std::vector.h) if an IntType is intended @@ -327,28 +327,6 @@ INT_TYPE_COMPARISON_OP(>); // NOLINT INT_TYPE_COMPARISON_OP(>=); // NOLINT #undef INT_TYPE_COMPARISON_OP -// Allows it to be used as a key to hashable containers. -#if !defined(SWIG) && !defined(STLPORT) && !defined(_MSC_VER) -namespace __gnu_cxx { -template -struct hash > { - size_t operator()(const IntType& idx) const { - return static_cast(idx.value()); - } -}; -} // namespace __gnu_cxx -#endif // !defined(_MSC_VER) && !defined(SWIG) && !defined(STLPORT) - -#if defined(_MSC_VER) && !defined(SWIG) -#include -namespace stdext { -template -inline size_t hash_value(const IntType& idx) { - return static_cast(idx.value()); -} -} // namespace stdext -#endif // _MSC_VER - namespace std { template struct hash > { diff --git a/ortools/base/map_util.h b/ortools/base/map_util.h index 2c3efa5dc8..f77b9cc507 100644 --- a/ortools/base/map_util.h +++ b/ortools/base/map_util.h @@ -19,7 +19,7 @@ namespace operations_research { -// Perform a lookup in a map or hash_map. +// Perform a lookup in a map or std::unordered_map. // If the key is present in the map then the value associated with that // key is returned, otherwise the value passed as a default is returned. template @@ -34,7 +34,7 @@ const typename Collection::value_type::second_type& FindWithDefault( return it->second; } -// Perform a lookup in a map or hash_map. +// Perform a lookup in a map or std::unordered_map. // If the key is present a const pointer to the associated value is returned, // otherwise a NULL pointer is returned. template @@ -48,7 +48,7 @@ const typename Collection::value_type::second_type* FindOrNull( return &it->second; } -// Perform a lookup in a map or hash_map. +// Perform a lookup in a map or std::unordered_map. // Same as above but the returned pointer is not const and can be used to change // the stored value. template @@ -62,7 +62,7 @@ typename Collection::value_type::second_type* FindOrNull( return &it->second; } -// Perform a lookup in a map or hash_map whose values are pointers. +// Perform a lookup in a map or std::unordered_map whose values are pointers. // If the key is present a const pointer to the associated value is returned, // otherwise a NULL pointer is returned. // This function does not distinguish between a missing key and a key mapped @@ -78,7 +78,7 @@ const typename Collection::value_type::second_type FindPtrOrNull( return it->second; } -// Change the value associated with a particular key in a map or hash_map. +// Change the value associated with a particular key in a map or std::unordered_map. // If the key is not present in the map the key and value are inserted, // otherwise the value is updated to be a copy of the value provided. // True indicates that an insert took place, false indicates an update. @@ -95,7 +95,7 @@ bool InsertOrUpdate(Collection* const collection, const Key& key, return true; } -// Insert a new key and value into a map or hash_map. +// Insert a new key and value into a map or std::unordered_map. // If the key is not present in the map the key and value are // inserted, otherwise nothing happens. True indicates that an insert // took place, false indicates the key was already present. @@ -107,8 +107,8 @@ bool InsertIfNotPresent(Collection* const collection, const Key& key, return ret.second; } -// Inserts a new std::pair into a map or hash_map. -// Insert a new key into a set or hash_set. +// Inserts a new std::pair into a map or std::unordered_map. +// Insert a new key into a set or std::unordered_set. // Dies if the key is already present. template void InsertOrDie(Collection* const collection, @@ -116,7 +116,7 @@ void InsertOrDie(Collection* const collection, CHECK(collection->insert(value).second) << "duplicate value: " << value; } -// Inserts a new key/value into a map or hash_map. +// Inserts a new key/value into a map or std::unordered_map. // Dies if the key is already present. template void InsertOrDie(Collection* const collection, @@ -127,7 +127,7 @@ void InsertOrDie(Collection* const collection, << "duplicate key: " << key; } -// Perform a lookup in map or hash_map. +// Perform a lookup in map or std::unordered_map. // If the key is present and value is non-NULL then a copy of the value // associated with the key is made into *value. Returns whether key was present. template @@ -143,7 +143,8 @@ bool FindCopy(const Collection& collection, const Key& key, return true; } -// Test to see if a set, map, hash_set or hash_map contains a particular key. +// Test to see if a set, map, std::unordered_set or std::unordered_map +// contains a particular key. // Returns true if the key is in the collection. template bool ContainsKey(const Collection& collection, const Key& key) { @@ -160,7 +161,7 @@ const typename Collection::value_type::second_type& FindOrDie( return it->second; } -// Lookup a key in a map or hash_map, insert it if it is not present. +// Lookup a key in a map or std::unordered_map, insert it if it is not present. // Returns a reference to the value associated with the key. template typename Collection::value_type::second_type& LookupOrInsert( diff --git a/ortools/base/stl_util.h b/ortools/base/stl_util.h index 348479ef97..92b483765e 100644 --- a/ortools/base/stl_util.h +++ b/ortools/base/stl_util.h @@ -25,7 +25,7 @@ namespace operations_research { // NOTE: for these three functions, we could just implement a DeleteObject // functor and then call for_each() on the range and functor, but this // requires us to pull in all of algorithm.h, which seems expensive. -// For hash_[multi]set, it is important that this deletes behind the iterator +// For tmp_potential_repairs_; NonOrderedSetHasher constraint_set_hasher_; - hash_map> hash_to_potential_repairs_; + std::unordered_map> hash_to_potential_repairs_; DISALLOW_COPY_AND_ASSIGN(AssignmentAndConstraintFeasibilityMaintainer); }; @@ -611,12 +611,7 @@ class LocalSearchAssignmentIterator { // Ideally, this should be related to the maximum number of decision in the // LS, but that requires templating the whole LS optimizer. bool use_transposition_table_; -#if defined(_MSC_VER) - hash_set, - StdArrayHasher> transposition_table_; -#else - hash_set> transposition_table_; -#endif + std::unordered_set> transposition_table_; bool use_potential_one_flip_repairs_; diff --git a/ortools/constraint_solver/assignment.cc b/ortools/constraint_solver/assignment.cc index 47cdb0c049..90a54cac56 100644 --- a/ortools/constraint_solver/assignment.cc +++ b/ortools/constraint_solver/assignment.cc @@ -380,7 +380,7 @@ void SequenceVarElement::SetUnperformed(const std::vector& unperformed) { } bool SequenceVarElement::CheckClassInvariants() { - hash_set visited; + std::unordered_set visited; for (const int forward_sequence : forward_sequence_) { if (ContainsKey(visited, forward_sequence)) { return false; @@ -444,7 +444,7 @@ namespace { template void IdToElementMap(AssignmentContainer* container, - hash_map* id_to_element_map) { + std::unordered_map* id_to_element_map) { CHECK(id_to_element_map != nullptr); id_to_element_map->clear(); for (int i = 0; i < container->Size(); ++i) { @@ -464,7 +464,7 @@ void IdToElementMap(AssignmentContainer* container, } template -void LoadElement(const hash_map& id_to_element_map, +void LoadElement(const std::unordered_map& id_to_element_map, const P& proto) { const std::string& var_id = proto.var_id(); CHECK(!var_id.empty()); @@ -516,7 +516,7 @@ void RealLoad(const AssignmentProto& assignment_proto, } } if (!fast_load) { - hash_map id_to_element_map; + std::unordered_map id_to_element_map; IdToElementMap(container, &id_to_element_map); for (int i = 0; i < (assignment_proto.*GetSize)(); ++i) { LoadElement(id_to_element_map, diff --git a/ortools/constraint_solver/collect_variables.cc b/ortools/constraint_solver/collect_variables.cc index 7e12f050a3..30a8f68206 100644 --- a/ortools/constraint_solver/collect_variables.cc +++ b/ortools/constraint_solver/collect_variables.cc @@ -82,7 +82,7 @@ class CollectVariablesVisitor : public ModelParser { } else if (type_name.compare(ModelVisitor::kAllowedAssignments) == 0) { const IntTupleSet& matrix = Top()->FindIntegerMatrixArgumentOrDie(ModelVisitor::kTuplesArgument); - std::vector > counters(matrix.Arity()); + std::vector > counters(matrix.Arity()); for (int i = 0; i < matrix.NumTuples(); ++i) { for (int j = 0; j < matrix.Arity(); ++j) { counters[j].insert(matrix.Value(i, j)); @@ -204,13 +204,13 @@ class CollectVariablesVisitor : public ModelParser { std::vector* const secondaries_; std::vector* const sequences_; std::vector* const intervals_; - // These hash_set can't easily hold const IntVar*, because they + // These std::unordered_set can't easily hold const IntVar*, because they // ultimately serve as containers of mutable IntVar. - hash_set primary_set_; - hash_set secondary_set_; - hash_set ignored_set_; - hash_set sequence_set_; - hash_set interval_set_; + std::unordered_set primary_set_; + std::unordered_set secondary_set_; + std::unordered_set ignored_set_; + std::unordered_set sequence_set_; + std::unordered_set interval_set_; }; } // namespace diff --git a/ortools/constraint_solver/constraint_solver.h b/ortools/constraint_solver/constraint_solver.h index 824a4a538c..03c9947488 100644 --- a/ortools/constraint_solver/constraint_solver.h +++ b/ortools/constraint_solver/constraint_solver.h @@ -2397,7 +2397,7 @@ class Solver { #if !defined(SWIG) // Compute the number of constraints a variable is attached to. ModelVisitor* MakeVariableDegreeVisitor( - hash_map* const map); + std::unordered_map* const map); #endif // ----- Symmetry Breaking ----- @@ -3126,9 +3126,9 @@ class Solver { const std::string name_; const ConstraintSolverParameters parameters_; - hash_map propagation_object_names_; - hash_map cast_information_; - hash_set cast_constraints_; + std::unordered_map propagation_object_names_; + std::unordered_map cast_information_; + std::unordered_set cast_constraints_; const std::string empty_name_; std::unique_ptr queue_; std::unique_ptr trail_; @@ -3169,10 +3169,10 @@ class Solver { int num_int_vars_; // Support for model loading. - hash_map expression_builders_; - hash_map constraint_builders_; - hash_map interval_builders_; - hash_map sequence_builders_; + std::unordered_map expression_builders_; + std::unordered_map constraint_builders_; + std::unordered_map interval_builders_; + std::unordered_map sequence_builders_; std::unique_ptr model_loader_; std::unique_ptr model_cache_; @@ -4983,7 +4983,7 @@ class AssignmentContainer { } // The == should be order-independent EnsureMapIsUpToDate(); - // Do not use the hash_map::== operator! It does not just compare content, + // Do not use the std::unordered_map::== operator! It does not just compare content, // but also how the map is hashed (e.g., number of buckets). This is not // what we want. for (const E& element : container.elements_) { @@ -5000,8 +5000,8 @@ class AssignmentContainer { private: void EnsureMapIsUpToDate() const { - hash_map* map = - const_cast*>(&elements_map_); + std::unordered_map* map = + const_cast*>(&elements_map_); for (int i = map->size(); i < elements_.size(); ++i) { (*map)[elements_[i].Var()] = i; } @@ -5027,7 +5027,7 @@ class AssignmentContainer { } std::vector elements_; - hash_map elements_map_; + std::unordered_map elements_map_; }; // ----- Assignment ----- diff --git a/ortools/constraint_solver/constraint_solveri.h b/ortools/constraint_solver/constraint_solveri.h index 852bac5192..4928923deb 100644 --- a/ortools/constraint_solver/constraint_solveri.h +++ b/ortools/constraint_solver/constraint_solveri.h @@ -1997,15 +1997,15 @@ class ArgumentHolder { private: std::string type_name_; - hash_map integer_argument_; - hash_map > integer_array_argument_; - hash_map matrix_argument_; - hash_map integer_expression_argument_; - hash_map interval_argument_; - hash_map sequence_argument_; - hash_map > integer_variable_array_argument_; - hash_map > interval_array_argument_; - hash_map > sequence_array_argument_; + std::unordered_map integer_argument_; + std::unordered_map > integer_array_argument_; + std::unordered_map matrix_argument_; + std::unordered_map integer_expression_argument_; + std::unordered_map interval_argument_; + std::unordered_map sequence_argument_; + std::unordered_map > integer_variable_array_argument_; + std::unordered_map > interval_array_argument_; + std::unordered_map > sequence_array_argument_; }; // Model Parser diff --git a/ortools/constraint_solver/default_search.cc b/ortools/constraint_solver/default_search.cc index 5433726f38..e24ad8d9b6 100644 --- a/ortools/constraint_solver/default_search.cc +++ b/ortools/constraint_solver/default_search.cc @@ -643,7 +643,7 @@ class ImpactRecorder : public SearchMonitor { int current_var_; int64 current_value_; FindVar find_var_; - hash_map var_map_; + std::unordered_map var_map_; bool init_done_; DISALLOW_COPY_AND_ASSIGN(ImpactRecorder); @@ -896,7 +896,7 @@ class RestartMonitor : public SearchMonitor { // if the nogood contains both x == 3 and x != 4, we can simplify // to keep only x == 3. - hash_set positive_variable; + std::unordered_set positive_variable; for (SimpleRevFIFO::Iterator it(&choices_); it.ok(); ++it) { const ChoiceInfo& choice = *it; if (choice.left()) { diff --git a/ortools/constraint_solver/demon_profiler.cc b/ortools/constraint_solver/demon_profiler.cc index e09e2327e8..75222afffa 100644 --- a/ortools/constraint_solver/demon_profiler.cc +++ b/ortools/constraint_solver/demon_profiler.cc @@ -268,7 +268,7 @@ class DemonProfiler : public PropagationMonitor { if (file::Open(filename, "w", &file, file::Defaults()).ok()) { file::WriteString(file, model, file::Defaults()).IgnoreError(); std::vector to_sort; - for (hash_map::const_iterator it = + for (std::unordered_map::const_iterator it = constraint_map_.begin(); it != constraint_map_.end(); ++it) { const Constraint* const ct = it->first; @@ -420,9 +420,9 @@ class DemonProfiler : public PropagationMonitor { Constraint* active_constraint_; Demon* active_demon_; const int64 start_time_ns_; - hash_map constraint_map_; - hash_map demon_map_; - hash_map > demons_per_constraint_; + std::unordered_map constraint_map_; + std::unordered_map demon_map_; + std::unordered_map > demons_per_constraint_; }; void Solver::ExportProfilingOverview(const std::string& filename) { diff --git a/ortools/constraint_solver/diffn.cc b/ortools/constraint_solver/diffn.cc index 0a393df067..fe10ed9a45 100644 --- a/ortools/constraint_solver/diffn.cc +++ b/ortools/constraint_solver/diffn.cc @@ -289,7 +289,7 @@ class Diffn : public Constraint { const bool strict_; const int64 size_; Demon* delayed_demon_; - hash_set to_propagate_; + std::unordered_set to_propagate_; std::vector neighbors_; uint64 fail_stamp_; }; diff --git a/ortools/constraint_solver/expr_array.cc b/ortools/constraint_solver/expr_array.cc index dbd196fdde..7d236742f5 100644 --- a/ortools/constraint_solver/expr_array.cc +++ b/ortools/constraint_solver/expr_array.cc @@ -2378,7 +2378,7 @@ class PositiveBooleanScalProdEqCst : public Constraint { class ExprLinearizer : public ModelParser { public: explicit ExprLinearizer( - hash_map* const variables_to_coefficients) + std::unordered_map* const variables_to_coefficients) : variables_to_coefficients_(variables_to_coefficients), constant_(0) {} ~ExprLinearizer() override {} @@ -2639,7 +2639,7 @@ class ExprLinearizer : public ModelParser { // We do need a IntVar* as key, and not const IntVar*, because clients of this // class typically iterate over the map keys and use them as mutable IntVar*. - hash_map* const variables_to_coefficients_; + std::unordered_map* const variables_to_coefficients_; std::vector multipliers_; int64 constant_; }; @@ -2677,7 +2677,7 @@ void DeepLinearize(Solver* const solver, const std::vector& pre_vars, } if (need_linearization) { // Instrospect the variables to simplify the sum. - hash_map variables_to_coefficients; + std::unordered_map variables_to_coefficients; ExprLinearizer linearizer(&variables_to_coefficients); for (int i = 0; i < pre_vars.size(); ++i) { linearizer.Visit(pre_vars[i], pre_coefs[i]); @@ -3201,7 +3201,7 @@ IntExpr* MakeScalProdFct(Solver* solver, const std::vector& pre_vars, } IntExpr* MakeSumFct(Solver* solver, const std::vector& pre_vars) { - hash_map variables_to_coefficients; + std::unordered_map variables_to_coefficients; ExprLinearizer linearizer(&variables_to_coefficients); for (int i = 0; i < pre_vars.size(); ++i) { linearizer.Visit(pre_vars[i], 1); diff --git a/ortools/constraint_solver/expr_cst.cc b/ortools/constraint_solver/expr_cst.cc index f5bf30572c..5a7b72482d 100644 --- a/ortools/constraint_solver/expr_cst.cc +++ b/ortools/constraint_solver/expr_cst.cc @@ -1410,7 +1410,7 @@ class IsMemberCt : public Constraint { } IntVar* const var_; - hash_set values_as_set_; + std::unordered_set values_as_set_; std::vector values_; IntVar* const boolvar_; int support_; diff --git a/ortools/constraint_solver/hybrid.cc b/ortools/constraint_solver/hybrid.cc index 521ed9c3f6..1211a38734 100644 --- a/ortools/constraint_solver/hybrid.cc +++ b/ortools/constraint_solver/hybrid.cc @@ -114,7 +114,7 @@ class SimplexConnection : public SearchMonitor { // ----- Useful typedefs ----- -typedef hash_map ExprTranslation; +typedef std::unordered_map ExprTranslation; #define IS_TYPE(type, tag) type.compare(ModelVisitor::tag) == 0 diff --git a/ortools/constraint_solver/io.cc b/ortools/constraint_solver/io.cc index f14564e563..771acec8f6 100644 --- a/ortools/constraint_solver/io.cc +++ b/ortools/constraint_solver/io.cc @@ -154,16 +154,16 @@ class FirstPassVisitor : public ModelVisitor { } // Export - const hash_map& expression_map() const { + const std::unordered_map& expression_map() const { return expression_map_; } - const hash_map& interval_map() const { + const std::unordered_map& interval_map() const { return interval_map_; } - const hash_map& sequence_map() const { + const std::unordered_map& sequence_map() const { return sequence_map_; } - const hash_map& delegate_map() const { + const std::unordered_map& delegate_map() const { return delegate_map_; } const std::vector& expression_list() const { @@ -230,10 +230,10 @@ class FirstPassVisitor : public ModelVisitor { } const std::string filename_; - hash_map expression_map_; - hash_map interval_map_; - hash_map sequence_map_; - hash_map delegate_map_; + std::unordered_map expression_map_; + std::unordered_map interval_map_; + std::unordered_map sequence_map_; + std::unordered_map delegate_map_; std::vector expression_list_; std::vector constraint_list_; std::vector interval_list_; @@ -401,15 +401,15 @@ class ArgumentHolder { private: std::string type_name_; - hash_map integer_expression_argument_; - hash_map integer_argument_; - hash_map interval_argument_; - hash_map sequence_argument_; - hash_map> integer_array_argument_; - hash_map>> integer_matrix_argument_; - hash_map> integer_variable_array_argument_; - hash_map> interval_array_argument_; - hash_map> sequence_array_argument_; + std::unordered_map integer_expression_argument_; + std::unordered_map integer_argument_; + std::unordered_map interval_argument_; + std::unordered_map sequence_argument_; + std::unordered_map> integer_array_argument_; + std::unordered_map>> integer_matrix_argument_; + std::unordered_map> integer_variable_array_argument_; + std::unordered_map> interval_array_argument_; + std::unordered_map> sequence_array_argument_; }; // ----- Second Pass Visitor ----- @@ -812,10 +812,10 @@ class SecondPassVisitor : public ModelVisitor { return FindOrDie(sequence_map_, sequence); } - hash_map expression_map_; - hash_map interval_map_; - hash_map sequence_map_; - hash_map delegate_map_; + std::unordered_map expression_map_; + std::unordered_map interval_map_; + std::unordered_map sequence_map_; + std::unordered_map delegate_map_; std::vector expression_list_; std::vector constraint_list_; std::vector interval_list_; diff --git a/ortools/constraint_solver/local_search.cc b/ortools/constraint_solver/local_search.cc index bf6221efd0..5bd4e30a7f 100644 --- a/ortools/constraint_solver/local_search.cc +++ b/ortools/constraint_solver/local_search.cc @@ -569,7 +569,7 @@ void PathOperator::InitializePathStarts() { // path starts (there could be fewer if a new path was made empty, or more // if nodes were added to a formerly empty path). int new_index = 0; - hash_set found_bases; + std::unordered_set found_bases; for (int i = 0; i < path_starts_.size(); ++i) { int index = new_index; // Note: old and new path starts are sorted by construction. @@ -1367,7 +1367,7 @@ bool TSPLns::MakeNeighbor() { } // Randomly select break nodes (final nodes of a meta-node, after which // an arc is relaxed. - hash_set breaks_set; + std::unordered_set breaks_set; // Always add base node to break nodes (diversification) breaks_set.insert(base_node); while (breaks_set.size() < tsp_size_) { @@ -1533,7 +1533,7 @@ class LinKernighan : public PathOperator { Solver::IndexEvaluator3 const evaluator_; NearestNeighbors neighbors_; - hash_set marked_; + std::unordered_set marked_; const bool topt_; }; diff --git a/ortools/constraint_solver/resource.cc b/ortools/constraint_solver/resource.cc index c157cae73e..592c0f2d2d 100644 --- a/ortools/constraint_solver/resource.cc +++ b/ortools/constraint_solver/resource.cc @@ -1653,7 +1653,7 @@ class EdgeFinder : public Constraint { // Stack of updates to the new start min to do. std::vector> start_min_update_; - typedef hash_map UpdateMap; + typedef std::unordered_map UpdateMap; // update_map_[d][i] is an integer such that if a task // whose demand is d cannot end before by_end_max_[i], then it cannot start diff --git a/ortools/constraint_solver/routing.cc b/ortools/constraint_solver/routing.cc index 36459b2bc3..fad171d859 100644 --- a/ortools/constraint_solver/routing.cc +++ b/ortools/constraint_solver/routing.cc @@ -67,16 +67,6 @@ DEFINE_int64(sweep_sectors, 1, // TODO(user): Move most of the following settings to a model parameter // proto. -#if defined(_MSC_VER) -namespace stdext { -template <> -size_t hash_value( - const operations_research::RoutingModel::NodeIndex& a) { - return a.value(); -} -} // namespace stdext -#endif // _MSC_VER - namespace operations_research { namespace { @@ -548,11 +538,7 @@ RoutingModel::RoutingModel( solver_.reset(new Solver("Routing", solver_parameters)); InitializeBuilders(solver_.get()); CHECK_EQ(vehicles, start_ends.size()); -#if defined(_MSC_VER) - std::unordered_set> depot_set; -#else std::unordered_set> depot_set; -#endif for (const std::pair start_end : start_ends) { depot_set.insert(start_end.first); depot_set.insert(start_end.second); @@ -604,11 +590,7 @@ RoutingModel::RoutingModel(int nodes, int vehicles, InitializeBuilders(solver_.get()); CHECK_EQ(vehicles, starts.size()); CHECK_EQ(vehicles, ends.size()); -#if defined(_MSC_VER) - std::unordered_set> depot_set; -#else std::unordered_set> depot_set; -#endif std::vector> start_ends(starts.size()); for (int i = 0; i < starts.size(); ++i) { depot_set.insert(starts[i]); @@ -1472,13 +1454,8 @@ void RoutingModel::SetStartEnd( const std::vector>& start_ends) { CHECK_EQ(start_ends.size(), vehicles_); const int size = Size(); -#if defined(_MSC_VER) - std::unordered_set> starts; - std::unordered_set> ends; -#else std::unordered_set> starts; std::unordered_set> ends; -#endif for (const std::pair start_end : start_ends) { const NodeIndex start = start_end.first; const NodeIndex end = start_end.second; @@ -1499,11 +1476,7 @@ void RoutingModel::SetStartEnd( ++index; } } -#if defined(_MSC_VER) - std::unordered_set> node_set; -#else std::unordered_set> node_set; -#endif index_to_vehicle_.resize(size + vehicles_, kUnassigned); for (int i = 0; i < vehicles_; ++i) { const NodeIndex start = start_ends[i].first; diff --git a/ortools/constraint_solver/routing.h b/ortools/constraint_solver/routing.h index d1ce0be04b..d0d4d9f757 100644 --- a/ortools/constraint_solver/routing.h +++ b/ortools/constraint_solver/routing.h @@ -1752,7 +1752,7 @@ class SweepArranger { // build delta assigment representing possible extensions to the current // solution and validate them with filters. // The tricky bit comes from using the assignment and filter APIs in a way -// which avoids the lazy creation of internal hash_maps between variables +// which avoids the lazy creation of internal std::unordered_maps between variables // and indices. // Generic filter-based decision builder applied to IntVars. diff --git a/ortools/constraint_solver/routing_search.cc b/ortools/constraint_solver/routing_search.cc index 66769168eb..f9f23c9139 100644 --- a/ortools/constraint_solver/routing_search.cc +++ b/ortools/constraint_solver/routing_search.cc @@ -1878,11 +1878,7 @@ void GlobalCheapestInsertionFilteredDecisionBuilder::UpdatePickupPositions( // the entries which are being kept and must be updated. using Pair = std::pair; using Insertion = std::pair; -#if defined(_MSC_VER) - std::unordered_set existing_insertions; -#else std::unordered_set> existing_insertions; -#endif std::vector to_remove; for (PairEntry* const pair_entry : pickup_to_entries->at(pickup_insert_after)) { @@ -1982,11 +1978,7 @@ void GlobalCheapestInsertionFilteredDecisionBuilder::UpdateDeliveryPositions( // the entries which are being kept and must be updated. using Pair = std::pair; using Insertion = std::pair; -#if defined(_MSC_VER) - std::unordered_set existing_insertions; -#else std::unordered_set> existing_insertions; -#endif std::vector to_remove; for (PairEntry* const pair_entry : delivery_to_entries->at(delivery_insert_after)) { diff --git a/ortools/constraint_solver/sat_constraint.h b/ortools/constraint_solver/sat_constraint.h index 0492c8633c..c651c1af16 100644 --- a/ortools/constraint_solver/sat_constraint.h +++ b/ortools/constraint_solver/sat_constraint.h @@ -126,7 +126,7 @@ class BooleanVariableManager { sat::SatSolver* solver_; std::vector registered_int_vars_; std::vector associated_variables_; - hash_map registration_index_map_; + std::unordered_map registration_index_map_; ITIVector> variable_meaning_; DISALLOW_COPY_AND_ASSIGN(BooleanVariableManager); }; diff --git a/ortools/constraint_solver/sched_search.cc b/ortools/constraint_solver/sched_search.cc index d84a4b06ef..ac514a8d62 100644 --- a/ortools/constraint_solver/sched_search.cc +++ b/ortools/constraint_solver/sched_search.cc @@ -105,7 +105,7 @@ void SequenceVar::HorizonRange(int64* const hmin, int64* const hmax) const { void SequenceVar::ActiveHorizonRange(int64* const hmin, int64* const hmax) const { - hash_set decided; + std::unordered_set decided; for (int i = 0; i < intervals_.size(); ++i) { if (intervals_[i]->CannotBePerformed()) { decided.insert(i); @@ -190,7 +190,7 @@ void SequenceVar::ComputePossibleFirstsAndLasts( std::vector* const possible_lasts) { possible_firsts->clear(); possible_lasts->clear(); - hash_set to_check; + std::unordered_set to_check; for (int i = 0; i < intervals_.size(); ++i) { if (intervals_[i]->MayBePerformed()) { to_check.insert(i); diff --git a/ortools/constraint_solver/search.cc b/ortools/constraint_solver/search.cc index 4ea8a827a5..2f5aa42980 100644 --- a/ortools/constraint_solver/search.cc +++ b/ortools/constraint_solver/search.cc @@ -3131,7 +3131,7 @@ int64 GuidedLocalSearchPenaltiesTable::Value(const Arc& arc) const { } } -// Sparse GLS penalties implementation using a hash_map to store penalties. +// Sparse GLS penalties implementation using a std::unordered_map to store penalties. class GuidedLocalSearchPenaltiesMap : public GuidedLocalSearchPenalties { public: @@ -3144,11 +3144,7 @@ class GuidedLocalSearchPenaltiesMap : public GuidedLocalSearchPenalties { private: Bitmap penalized_; -#if defined(_MSC_VER) - hash_map penalties_; -#else - hash_map penalties_; -#endif + std::unordered_map penalties_; }; GuidedLocalSearchPenaltiesMap::GuidedLocalSearchPenaltiesMap(int size) @@ -3208,7 +3204,7 @@ class GuidedLocalSearch : public Metaheuristic { int64 assignment_penalized_value_; int64 old_penalized_value_; const std::vector vars_; - hash_map indices_; + std::unordered_map indices_; const double penalty_factor_; std::unique_ptr penalties_; std::unique_ptr current_penalized_values_; diff --git a/ortools/constraint_solver/table.cc b/ortools/constraint_solver/table.cc index e708f526f3..d17c0c2b3a 100644 --- a/ortools/constraint_solver/table.cc +++ b/ortools/constraint_solver/table.cc @@ -249,7 +249,7 @@ class BasePositiveTableConstraint : public Constraint { class PositiveTableConstraint : public BasePositiveTableConstraint { public: - typedef hash_map> ValueBitset; + typedef std::unordered_map> ValueBitset; PositiveTableConstraint(Solver* const s, const std::vector& vars, const IntTupleSet& tuples) diff --git a/ortools/constraint_solver/tree_monitor.cc b/ortools/constraint_solver/tree_monitor.cc index 43aae2d8c3..2b27cbe6aa 100644 --- a/ortools/constraint_solver/tree_monitor.cc +++ b/ortools/constraint_solver/tree_monitor.cc @@ -180,7 +180,7 @@ class TreeDecisionVisitor : public DecisionVisitor { // not support this. class TreeMonitor : public SearchMonitor { public: - typedef hash_map IntVarMap; + typedef std::unordered_map IntVarMap; TreeMonitor(Solver* const solver, const IntVar* const* vars, int size, const std::string& filename_tree, const std::string& filename_visualizer); @@ -236,7 +236,7 @@ class TreeMonitor : public SearchMonitor { const std::string filename_visualizer_; int id_counter_; std::string last_decision_; - hash_map last_value_; + std::unordered_map last_value_; std::string last_variable_; int64 min_; int64 max_; @@ -314,7 +314,7 @@ class TreeNode { // Adds a new child, initializes it and returns the corresponding pointer. bool AddChild(int id, const std::string& name, - hash_map const& last_value, bool is_final_node, + std::unordered_map const& last_value, bool is_final_node, TreeMonitor::IntVarMap const& vars, TreeNode** child) { CHECK(child != nullptr); diff --git a/ortools/constraint_solver/utilities.cc b/ortools/constraint_solver/utilities.cc index 5afff79c5f..2b2ba42f70 100644 --- a/ortools/constraint_solver/utilities.cc +++ b/ortools/constraint_solver/utilities.cc @@ -689,9 +689,9 @@ class ModelStatisticsVisitor : public ModelVisitor { extension_types_[extension_type]++; } - hash_map constraint_types_; - hash_map expression_types_; - hash_map extension_types_; + std::unordered_map constraint_types_; + std::unordered_map expression_types_; + std::unordered_map extension_types_; int num_constraints_; int num_variables_; int num_expressions_; @@ -699,14 +699,14 @@ class ModelStatisticsVisitor : public ModelVisitor { int num_intervals_; int num_sequences_; int num_extensions_; - hash_set already_visited_; + std::unordered_set already_visited_; }; // ---------- Variable Degree Visitor --------- class VariableDegreeVisitor : public ModelVisitor { public: - explicit VariableDegreeVisitor(hash_map* const map) + explicit VariableDegreeVisitor(std::unordered_map* const map) : map_(map) {} ~VariableDegreeVisitor() override {} @@ -797,7 +797,7 @@ class VariableDegreeVisitor : public ModelVisitor { object->Accept(this); } - hash_map* const map_; + std::unordered_map* const map_; }; } // namespace @@ -810,7 +810,7 @@ ModelVisitor* Solver::MakeStatisticsModelVisitor() { } ModelVisitor* Solver::MakeVariableDegreeVisitor( - hash_map* const map) { + std::unordered_map* const map) { return RevAlloc(new VariableDegreeVisitor(map)); } diff --git a/ortools/flatzinc/sat_fz_solver.cc b/ortools/flatzinc/sat_fz_solver.cc index 40f3d153e2..e83349a3d7 100644 --- a/ortools/flatzinc/sat_fz_solver.cc +++ b/ortools/flatzinc/sat_fz_solver.cc @@ -48,8 +48,8 @@ struct SatModel { // A flatzinc Boolean variable can appear in both maps if a constraint needs // its integer representation as a 0-1 variable. Such an IntegerVariable is // created lazily by LookupVar() when a constraint is requesting it. - hash_map var_map; - hash_map bool_map; + std::unordered_map var_map; + std::unordered_map bool_map; // Utility functions to convert an fz::Argument to sat::IntegerVariable(s). IntegerVariable LookupConstant(int64 value); @@ -686,7 +686,7 @@ void ImpliesEquality(bool reverse_implication, Literal r, IntegerVariable a, return; } - hash_map> by_value; + std::unordered_map> by_value; for (const auto p : m->FullEncoding(a)) { by_value[p.value].push_back(p.literal); } @@ -1314,7 +1314,7 @@ void SolveWithSat(const fz::Model& fz_model, const fz::FlatzincParameters& p, m.model.SetSingleton(std::move(time_limit)); // Process the bool_not constraints to avoid creating extra Boolean variables. - hash_map not_map; + std::unordered_map not_map; for (fz::Constraint* ct : fz_model.constraints()) { if (ct != nullptr && ct->active && (ct->type == "bool_not" || ct->type == "bool_ne")) { diff --git a/ortools/graph/BUILD b/ortools/graph/BUILD index 741318bd09..5a272b75e2 100644 --- a/ortools/graph/BUILD +++ b/ortools/graph/BUILD @@ -219,7 +219,6 @@ cc_library( # ":graph", # "//ortools/base", # "//ortools/base:adjustable_priority_queue", -# "//ortools/base:dense_hash_map", # "//ortools/base:file", # "//ortools/base:map_util", # "//ortools/base:stl_util", diff --git a/ortools/graph/astar.cc b/ortools/graph/astar.cc index 75d46c94e7..826f4fe5b2 100644 --- a/ortools/graph/astar.cc +++ b/ortools/graph/astar.cc @@ -83,8 +83,8 @@ class AStarSP { std::unique_ptr predecessor_; AdjustablePriorityQueue frontier_; std::vector elements_; - hash_set not_visited_; - hash_set added_to_the_frontier_; + std::unordered_set not_visited_; + std::unordered_set added_to_the_frontier_; }; void AStarSP::Initialize() { @@ -114,7 +114,7 @@ int AStarSP::SelectClosestNode(int64* distance) { } void AStarSP::Update(int node) { - for (hash_set::const_iterator it = not_visited_.begin(); + for (std::unordered_set::const_iterator it = not_visited_.begin(); it != not_visited_.end(); ++it) { const int other_node = *it; const int64 graph_node_i = graph_(node, other_node); diff --git a/ortools/graph/cliques.cc b/ortools/graph/cliques.cc index 50a7db5f6d..b3b377eebc 100644 --- a/ortools/graph/cliques.cc +++ b/ortools/graph/cliques.cc @@ -218,11 +218,7 @@ class FindAndEliminate { std::function graph_; int node_count_; std::function&)> callback_; -#if defined(_MSC_VER) - hash_set, PairIntHasher> visited_; -#else - hash_set > visited_; -#endif + std::unordered_set > visited_; }; } // namespace diff --git a/ortools/graph/connectivity.h b/ortools/graph/connectivity.h index eaa8f6caab..6c3ec7aba9 100644 --- a/ortools/graph/connectivity.h +++ b/ortools/graph/connectivity.h @@ -57,7 +57,7 @@ namespace operations_research { // } // // Group the nodes in the same connected component together. // // group[class_number][i] contains the i-th node in group class_number. -// hash_map > group(num_connected_components); +// std::unordered_map > group(num_connected_components); // for (int node = 0; node < num_nodes; ++node) { // group[components.GetClassRepresentative(node)].push_back(node); // } diff --git a/ortools/graph/dijkstra.cc b/ortools/graph/dijkstra.cc index f607056548..e6a065966d 100644 --- a/ortools/graph/dijkstra.cc +++ b/ortools/graph/dijkstra.cc @@ -71,8 +71,8 @@ class DijkstraSP { std::unique_ptr predecessor_; AdjustablePriorityQueue frontier_; std::vector elements_; - hash_set not_visited_; - hash_set added_to_the_frontier_; + std::unordered_set not_visited_; + std::unordered_set added_to_the_frontier_; }; void DijkstraSP::Initialize() { @@ -100,7 +100,7 @@ int DijkstraSP::SelectClosestNode(int64* distance) { } void DijkstraSP::Update(int node) { - for (hash_set::const_iterator it = not_visited_.begin(); + for (std::unordered_set::const_iterator it = not_visited_.begin(); it != not_visited_.end(); ++it) { const int other_node = *it; const int64 graph_node_i = graph_(node, other_node); diff --git a/ortools/graph/util.h b/ortools/graph/util.h index a37174a003..0828eec263 100644 --- a/ortools/graph/util.h +++ b/ortools/graph/util.h @@ -213,7 +213,7 @@ std::unique_ptr RemoveSelfArcsAndDuplicateArcs(const Graph& graph) { std::unique_ptr g(new Graph(graph.num_nodes(), graph.num_arcs())); typedef typename Graph::ArcIndex ArcIndex; typedef typename Graph::NodeIndex NodeIndex; - hash_set> arcs; + std::unordered_set> arcs; for (const NodeIndex tail : graph.AllNodes()) { for (const ArcIndex arc : graph.OutgoingArcs(tail)) { const NodeIndex head = graph.Head(arc); @@ -266,7 +266,7 @@ template std::vector ComputeOnePossibleReverseArcMapping(const Graph& graph, bool die_if_not_symmetric) { std::vector reverse_arc(graph.num_arcs(), -1); - hash_multimap, /*arc index*/ int> + std::unordered_multimap, /*arc index*/ int> arc_map; for (int arc = 0; arc < graph.num_arcs(); ++arc) { const int tail = graph.Tail(arc); diff --git a/ortools/linear_solver/linear_solver.cc b/ortools/linear_solver/linear_solver.cc index b4ecf4de1a..32fc76f51e 100644 --- a/ortools/linear_solver/linear_solver.cc +++ b/ortools/linear_solver/linear_solver.cc @@ -468,7 +468,7 @@ bool MPSolver::SupportsProblemType(OptimizationProblemType problem_type) { } MPVariable* MPSolver::LookupVariableOrNull(const std::string& var_name) const { - hash_map::const_iterator it = + std::unordered_map::const_iterator it = variable_name_to_index_.find(var_name); if (it == variable_name_to_index_.end()) return nullptr; return variables_[it->second]; @@ -476,7 +476,7 @@ MPVariable* MPSolver::LookupVariableOrNull(const std::string& var_name) const { MPConstraint* MPSolver::LookupConstraintOrNull(const std::string& constraint_name) const { - hash_map::const_iterator it = + std::unordered_map::const_iterator it = constraint_name_to_index_.find(constraint_name); if (it == constraint_name_to_index_.end()) return nullptr; return constraints_[it->second]; @@ -663,7 +663,7 @@ void MPSolver::ExportModelToProto(MPModelProto* output_model) const { // This step is needed as long as the variable indices are given by the // underlying solver at the time of model extraction. // TODO(user): remove this step. - hash_map var_to_index; + std::unordered_map var_to_index; for (int j = 0; j < variables_.size(); ++j) { var_to_index[variables_[j]] = j; } @@ -1606,4 +1606,3 @@ int MPSolverParameters::GetIntegerParam(MPSolverParameters::IntegerParam param) } // namespace operations_research - diff --git a/ortools/linear_solver/linear_solver.h b/ortools/linear_solver/linear_solver.h index ea2ff44376..3bbcb73719 100644 --- a/ortools/linear_solver/linear_solver.h +++ b/ortools/linear_solver/linear_solver.h @@ -590,14 +590,14 @@ class MPSolver { // The vector of variables in the problem. std::vector variables_; // A map from a variable's name to its index in variables_. - hash_map variable_name_to_index_; + std::unordered_map variable_name_to_index_; // Whether constraints have been extracted to the underlying interface. std::vector variable_is_extracted_; // The vector of constraints in the problem. std::vector constraints_; // A map from a constraint's name to its index in constraints_. - hash_map constraint_name_to_index_; + std::unordered_map constraint_name_to_index_; // Whether constraints have been extracted to the underlying interface. std::vector constraint_is_extracted_; @@ -636,11 +636,11 @@ inline std::ostream& operator<<(std::ostream& os, // The data structure used to store the coefficients of the contraints and of // the objective. Also define a type to facilitate iteration over them with: // for (CoeffEntry entry : coefficients_) { ... } -class CoeffMap : public hash_map { +class CoeffMap : public std::unordered_map { public: explicit CoeffMap(int num_buckets) #if !defined(_MSC_VER) // Visual C++ doesn't support this constructor - : hash_map(num_buckets) + : std::unordered_map(num_buckets) #endif // _MSC_VER { } diff --git a/ortools/linear_solver/model_exporter.cc b/ortools/linear_solver/model_exporter.cc index db74152d0e..99125dc338 100644 --- a/ortools/linear_solver/model_exporter.cc +++ b/ortools/linear_solver/model_exporter.cc @@ -55,7 +55,7 @@ class NameManager { std::string MakeUniqueName(const std::string& name); private: - hash_set names_set_; + std::unordered_set names_set_; int last_n_; }; diff --git a/ortools/lp_data/lp_data.cc b/ortools/lp_data/lp_data.cc index 9d6d809221..ff0909c55b 100644 --- a/ortools/lp_data/lp_data.cc +++ b/ortools/lp_data/lp_data.cc @@ -202,7 +202,7 @@ RowIndex LinearProgram::CreateNewConstraint() { } ColIndex LinearProgram::FindOrCreateVariable(const std::string& variable_id) { - const hash_map::iterator it = + const std::unordered_map::iterator it = variable_table_.find(variable_id); if (it != variable_table_.end()) { return it->second; @@ -215,7 +215,7 @@ ColIndex LinearProgram::FindOrCreateVariable(const std::string& variable_id) { } RowIndex LinearProgram::FindOrCreateConstraint(const std::string& constraint_id) { - const hash_map::iterator it = + const std::unordered_map::iterator it = constraint_table_.find(constraint_id); if (it != constraint_table_.end()) { return it->second; @@ -975,7 +975,7 @@ void LinearProgram::DeleteColumns(const DenseBooleanRow& columns_to_delete) { variable_names_.resize(new_index, ""); // Remove the id of the deleted columns and adjust the index of the other. - hash_map::iterator it = variable_table_.begin(); + std::unordered_map::iterator it = variable_table_.begin(); while (it != variable_table_.end()) { const ColIndex col = it->second; if (col >= columns_to_delete.size() || !columns_to_delete[col]) { @@ -1079,7 +1079,7 @@ void LinearProgram::DeleteRows(const DenseBooleanColumn& row_to_delete) { matrix_.DeleteRows(new_index, permutation); // Remove the id of the deleted rows and adjust the index of the other. - hash_map::iterator it = constraint_table_.begin(); + std::unordered_map::iterator it = constraint_table_.begin(); while (it != constraint_table_.end()) { const RowIndex row = it->second; if (permutation[row] != kInvalidRow) { diff --git a/ortools/lp_data/lp_data.h b/ortools/lp_data/lp_data.h index a7545702b7..410dc45acc 100644 --- a/ortools/lp_data/lp_data.h +++ b/ortools/lp_data/lp_data.h @@ -92,10 +92,10 @@ class LinearProgram { // // Note that these ids are NOT copied over by the Populate*() functions. // - // TODO(user): Move these and the two corresponding hash_table into a new + // TODO(user): Move these and the two corresponding std::unordered_table into a new // LinearProgramBuilder class to simplify the code of some functions like // DeleteColumns() here and make the behavior on copy clear? or simply remove - // them as it is almost as easy to maintain a hash_table on the client side. + // them as it is almost as easy to maintain a std::unordered_table on the client side. ColIndex FindOrCreateVariable(const std::string& variable_id); RowIndex FindOrCreateConstraint(const std::string& constraint_id); @@ -538,10 +538,10 @@ class LinearProgram { mutable std::vector non_binary_variables_list_; // Map used to find the index of a variable based on its id. - hash_map variable_table_; + std::unordered_map variable_table_; // Map used to find the index of a constraint based on its id. - hash_map constraint_table_; + std::unordered_map constraint_table_; // Offset of the objective, i.e. value of the objective when all variables // are set to zero. diff --git a/ortools/lp_data/mps_reader.h b/ortools/lp_data/mps_reader.h index 20418e1e04..aedf38ba97 100644 --- a/ortools/lp_data/mps_reader.h +++ b/ortools/lp_data/mps_reader.h @@ -207,16 +207,16 @@ class MPSReader { SectionId section_; // Maps section mnemonic --> section id. - hash_map section_name_to_id_map_; + std::unordered_map section_name_to_id_map_; // Maps row type mnemonic --> row type id. - hash_map row_name_to_id_map_; + std::unordered_map row_name_to_id_map_; // Maps bound type mnemonic --> bound type id. - hash_map bound_name_to_id_map_; + std::unordered_map bound_name_to_id_map_; // Set of bound type mnemonics that constrain variables to be integer. - hash_set integer_type_names_set_; + std::unordered_set integer_type_names_set_; // The current line number in the file being parsed. int64 line_num_; diff --git a/ortools/sat/boolean_problem.cc b/ortools/sat/boolean_problem.cc index b916a537b6..7df48321f0 100644 --- a/ortools/sat/boolean_problem.cc +++ b/ortools/sat/boolean_problem.cc @@ -321,7 +321,7 @@ std::string LinearBooleanProblemToCnfString(const LinearBooleanProblem& problem) const int first_slack_variable = problem.original_num_variables(); // This will contains the objective. - hash_map literal_to_weight; + std::unordered_map literal_to_weight; std::vector> non_slack_objective; // This will be the weight of the "hard" clauses in the wcnf format. It must @@ -432,11 +432,7 @@ class IdGenerator { } private: -#if defined(_MSC_VER) - hash_map, int, PairIntInt64Hasher> id_map_; -#else - hash_map, int> id_map_; -#endif + std::unordered_map, int> id_map_; }; } // namespace. diff --git a/ortools/sat/clause.h b/ortools/sat/clause.h index bdde9d2c57..7b23ece1b0 100644 --- a/ortools/sat/clause.h +++ b/ortools/sat/clause.h @@ -288,11 +288,7 @@ class BinaryClauseManager { void ClearNewlyAdded() { newly_added_.clear(); } private: -#if defined(_MSC_VER) - hash_set, PairIntHasher> set_; -#else - hash_set> set_; -#endif + std::unordered_set> set_; std::vector newly_added_; DISALLOW_COPY_AND_ASSIGN(BinaryClauseManager); }; diff --git a/ortools/sat/cp_constraints.cc b/ortools/sat/cp_constraints.cc index af2d6f43af..981a79f200 100644 --- a/ortools/sat/cp_constraints.cc +++ b/ortools/sat/cp_constraints.cc @@ -187,7 +187,7 @@ void AllDifferentBoundsPropagator::RegisterWith( std::function AllDifferent( const std::vector& vars) { return [=](Model* model) { - hash_set fixed_values; + std::unordered_set fixed_values; // First, we fully encode all the given integer variables. IntegerEncoder* encoder = model->GetOrCreate(); @@ -205,7 +205,7 @@ std::function AllDifferent( // Then we construct a mapping value -> List of literal each indicating // that a given variable takes this value. - hash_map> value_to_literals; + std::unordered_map> value_to_literals; for (const IntegerVariable var : vars) { if (!encoder->VariableIsFullyEncoded(var)) continue; for (const auto& entry : encoder->FullDomainEncoding(var)) { @@ -244,7 +244,7 @@ CircuitPropagator::CircuitPropagator( prev_.resize(num_nodes_, -1); next_literal_.resize(num_nodes_); self_arcs_.resize(num_nodes_); - hash_map literal_to_watch_index; + std::unordered_map literal_to_watch_index; const VariablesAssignment& assignment = trail->Assignment(); for (int tail = 0; tail < num_nodes_; ++tail) { self_arcs_[tail] = graph[tail][tail]; diff --git a/ortools/sat/integer.cc b/ortools/sat/integer.cc index 63ed8a607b..6cc9fa8dba 100644 --- a/ortools/sat/integer.cc +++ b/ortools/sat/integer.cc @@ -46,7 +46,7 @@ void IntegerEncoder::FullyEncodeVariable(IntegerVariable i_var, // these intersection should happen in the presolve. if (ContainsKey(full_encoding_index_, i_var)) { int num_fixed = 0; - hash_set to_interset(values.begin(), values.end()); + std::unordered_set to_interset(values.begin(), values.end()); const std::vector& encoding = FullDomainEncoding(i_var); for (const ValueLiteralPair& p : encoding) { if (!ContainsKey(to_interset, p.value)) { diff --git a/ortools/sat/integer.h b/ortools/sat/integer.h index 643c8a1a0c..966b683b3e 100644 --- a/ortools/sat/integer.h +++ b/ortools/sat/integer.h @@ -264,7 +264,7 @@ class IntegerEncoder { // Returns the set of variable encoded as the keys in a map. The map values // only have an internal meaning. The set of encoded variables is returned // with this "weird" api for efficiency. - const hash_map& GetFullyEncodedVariables() const { + const std::unordered_map& GetFullyEncodedVariables() const { return full_encoding_index_; } @@ -330,7 +330,7 @@ class IntegerEncoder { // Full domain encoding. The map contains the index in full_encoding_ of // the fully encoded variable. Each entry in full_encoding_ is sorted by // IntegerValue and contains the encoding of one IntegerVariable. - hash_map full_encoding_index_; + std::unordered_map full_encoding_index_; std::vector> full_encoding_; DISALLOW_COPY_AND_ASSIGN(IntegerEncoder); @@ -564,7 +564,7 @@ class IntegerTrail : public SatPropagator { // Used by GetOrCreateConstantIntegerVariable() to return already created // constant variables that share the same value. - hash_map constant_map_; + std::unordered_map constant_map_; // The integer trail. It always start by num_vars sentinel values with the // level 0 bounds (in one to one correspondance with vars_). @@ -599,20 +599,20 @@ class IntegerTrail : public SatPropagator { int64 num_encoded_variables_ = 0; std::vector tmp_literals_reason_; RevGrowingMultiMap watched_min_; - RevMap> current_min_; + RevMap> current_min_; // This is only filled for variables with a domain more complex than a single // interval of values. All intervals are stored in a vector, and we keep // indices to the current interval of the lower bound, and to the end index // which is exclusive. // - // TODO(user): Avoid using hash_map here and above, a simple vector should + // TODO(user): Avoid using std::unordered_map here and above, a simple vector should // be more efficient. Except if there is really little variables like this. // // TODO(user): We could share the std::vector entry between a // variable and its negations instead of having duplicates. - RevMap> var_to_current_lb_interval_index_; - hash_map var_to_end_interval_index_; // const entries. + RevMap> var_to_current_lb_interval_index_; + std::unordered_map var_to_end_interval_index_; // const entries. std::vector all_intervals_; // const entries. // Temporary data used by MergeReasonInto(). @@ -939,7 +939,7 @@ class LiteralViews { } private: - hash_map literal_index_to_integer_; + std::unordered_map literal_index_to_integer_; Model* model_; }; diff --git a/ortools/sat/linear_programming_constraint.h b/ortools/sat/linear_programming_constraint.h index f70b5d0e40..3be12a88f2 100644 --- a/ortools/sat/linear_programming_constraint.h +++ b/ortools/sat/linear_programming_constraint.h @@ -147,7 +147,7 @@ class LinearProgrammingConstraint : public PropagatorInterface { // both are used in IncrementalPropagate() and Propagate() calls; // integer_variable_to_index_ is used to find which mirroring variable's // coefficient must be modified on SetCoefficient(). - hash_map integer_variable_to_index_; + std::unordered_map integer_variable_to_index_; std::vector integer_variables_; std::vector mirror_lp_variables_; diff --git a/ortools/sat/pb_constraint.h b/ortools/sat/pb_constraint.h index 8afe88dacc..64ccbbe1be 100644 --- a/ortools/sat/pb_constraint.h +++ b/ortools/sat/pb_constraint.h @@ -636,7 +636,7 @@ class PbConstraints : public SatPropagator { // Pointers to the constraints grouped by their hash. // This is used to find duplicate constraints by AddConstraint(). - hash_map> + std::unordered_map> possible_duplicates_; // Helper to enqueue propagated literals on the trail and store their reasons. diff --git a/ortools/sat/sat_solver.h b/ortools/sat/sat_solver.h index d8a8927a83..0202fcf447 100644 --- a/ortools/sat/sat_solver.h +++ b/ortools/sat/sat_solver.h @@ -673,7 +673,7 @@ class SatSolver { int32 lbd = 0; bool protected_during_next_cleanup = false; }; - hash_map clauses_info_; + std::unordered_map clauses_info_; // Internal propagators. We keep them here because we need more than the // SatPropagator interface for them. diff --git a/ortools/sat/simplification.h b/ortools/sat/simplification.h index d50dba3cd0..76d8940c77 100644 --- a/ortools/sat/simplification.h +++ b/ortools/sat/simplification.h @@ -275,11 +275,7 @@ class SatPresolver { // Temporary data for SimpleBva(). std::set m_lit_; std::vector m_cls_; -#if defined(_MSC_VER) - hash_map, TypedIntHasher> p_; -#else - hash_map> p_; -#endif + std::unordered_map> p_; std::vector tmp_new_clause_; // List of clauses on which we need to call ProcessClauseToSimplifyOthers(). diff --git a/ortools/sat/table.cc b/ortools/sat/table.cc index 802870fb23..5ed57c376f 100644 --- a/ortools/sat/table.cc +++ b/ortools/sat/table.cc @@ -41,8 +41,8 @@ std::vector> Transpose( } // Converts the vector representation returned by FullDomainEncoding() to a map. -hash_map GetEncoding(IntegerVariable var, Model* model) { - hash_map encoding; +std::unordered_map GetEncoding(IntegerVariable var, Model* model) { + std::unordered_map encoding; IntegerEncoder* encoder = model->GetOrCreate(); for (const auto& entry : encoder->FullDomainEncoding(var)) { encoding[entry.value] = entry.literal; @@ -89,10 +89,10 @@ void FilterValues(IntegerVariable var, Model* model, // map. void ProcessOneColumn(const std::vector& line_literals, const std::vector& values, - const hash_map& encoding, + const std::unordered_map& encoding, Model* model) { CHECK_EQ(line_literals.size(), values.size()); - hash_map> value_to_list_of_line_literals; + std::unordered_map> value_to_list_of_line_literals; // If a value is false (i.e not possible), then the tuple with this value // is false too (i.e not possible). @@ -168,7 +168,7 @@ std::function TableConstraint( // Fully encode the variables using all the values appearing in the tuples. IntegerEncoder* encoder = model->GetOrCreate(); - hash_map encoding; + std::unordered_map encoding; const std::vector> tr_tuples = Transpose(new_tuples); for (int i = 0; i < n; ++i) { @@ -198,7 +198,7 @@ std::function LiteralTableConstraint( CHECK_EQ(tuple_size, literal_tuples[i].size()); } - hash_map> line_literals_per_literal; + std::unordered_map> line_literals_per_literal; for (int i = 0; i < num_tuples; ++i) { const LiteralIndex selected_index = line_literals[i].Index(); for (const Literal l : literal_tuples[i]) { @@ -254,7 +254,7 @@ std::function TransitionConstraint( } // Construct a table with the possible values of each vars. - std::vector> possible_values(n); + std::vector> possible_values(n); const VariablesAssignment& assignment = model->GetOrCreate()->Assignment(); for (int time = 0; time < n; ++time) { @@ -309,9 +309,9 @@ std::function TransitionConstraint( // initial state, and at time n we should be in one of the final states. We // don't need to create Booleans at at time when there is just one possible // state (like at time zero). - hash_map encoding; - hash_map in_encoding; - hash_map out_encoding; + std::unordered_map encoding; + std::unordered_map in_encoding; + std::unordered_map out_encoding; for (int time = 0; time < n; ++time) { // All these vector have the same size. We will use them to enforce a // local table constraint representing one step of the automata at the diff --git a/ortools/util/rev.h b/ortools/util/rev.h index d45cf42029..3b1a45fd7a 100644 --- a/ortools/util/rev.h +++ b/ortools/util/rev.h @@ -220,7 +220,7 @@ class RevGrowingMultiMap : ReversibleInterface { // TODO(user): use inlined vectors. Another datastructure that may be more // efficient is to use a linked list inside added_keys_ for the values sharing // the same key. - hash_map> map_; + std::unordered_map> map_; // Backtracking data. std::vector added_keys_; diff --git a/ortools/util/tuple_set.h b/ortools/util/tuple_set.h index e003f9a1b8..758c169ab2 100644 --- a/ortools/util/tuple_set.h +++ b/ortools/util/tuple_set.h @@ -125,7 +125,7 @@ class IntTupleSet { // Maps a tuple's fingerprint to the list of tuples with this // fingerprint, represented by their start index in the // flat_tuples_ vector. - hash_map > tuple_fprint_to_index_; + std::unordered_map > tuple_fprint_to_index_; }; // Used to represent a light representation of a tuple. @@ -359,7 +359,7 @@ inline int IntTupleSet::NumDifferentValuesInColumn(int col) const { if (col < 0 || col >= data_->Arity()) { return 0; } - hash_set values; + std::unordered_set values; for (int i = 0; i < data_->NumTuples(); ++i) { values.insert(data_->Value(i, col)); } diff --git a/ortools/util/vector_map.h b/ortools/util/vector_map.h index a074047521..69101c6de9 100644 --- a/ortools/util/vector_map.h +++ b/ortools/util/vector_map.h @@ -106,7 +106,7 @@ class VectorMap { private: std::vector list_; - hash_map map_; + std::unordered_map map_; }; } // namespace operations_research