remove hash_map/hash_set; replace with std::unordered_map|set

This commit is contained in:
Laurent Perron
2017-04-27 14:14:05 +02:00
parent bb865b6667
commit 4db7d3bc4e
63 changed files with 219 additions and 631 deletions

View File

@@ -468,7 +468,7 @@ bool MPSolver::SupportsProblemType(OptimizationProblemType problem_type) {
}
MPVariable* MPSolver::LookupVariableOrNull(const std::string& var_name) const {
hash_map<std::string, int>::const_iterator it =
std::unordered_map<std::string, int>::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<std::string, int>::const_iterator it =
std::unordered_map<std::string, int>::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<const MPVariable*, int> var_to_index;
std::unordered_map<const MPVariable*, int> 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

View File

@@ -590,14 +590,14 @@ class MPSolver {
// The vector of variables in the problem.
std::vector<MPVariable*> variables_;
// A map from a variable's name to its index in variables_.
hash_map<std::string, int> variable_name_to_index_;
std::unordered_map<std::string, int> variable_name_to_index_;
// Whether constraints have been extracted to the underlying interface.
std::vector<bool> variable_is_extracted_;
// The vector of constraints in the problem.
std::vector<MPConstraint*> constraints_;
// A map from a constraint's name to its index in constraints_.
hash_map<std::string, int> constraint_name_to_index_;
std::unordered_map<std::string, int> constraint_name_to_index_;
// Whether constraints have been extracted to the underlying interface.
std::vector<bool> 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<const MPVariable*, double> {
class CoeffMap : public std::unordered_map<const MPVariable*, double> {
public:
explicit CoeffMap(int num_buckets)
#if !defined(_MSC_VER) // Visual C++ doesn't support this constructor
: hash_map<const MPVariable*, double>(num_buckets)
: std::unordered_map<const MPVariable*, double>(num_buckets)
#endif // _MSC_VER
{
}

View File

@@ -55,7 +55,7 @@ class NameManager {
std::string MakeUniqueName(const std::string& name);
private:
hash_set<std::string> names_set_;
std::unordered_set<std::string> names_set_;
int last_n_;
};