Simplify CellInstance hash function and use template argument for unordered_map

This commit is contained in:
Paul Romano 2020-01-10 06:54:05 -06:00
parent 9787e9e8c0
commit 37eaaabd6c
2 changed files with 4 additions and 14 deletions

View file

@ -300,28 +300,18 @@ struct CellInstance {
gsl::index index_cell;
gsl::index instance;
};
} // namespace openmc
namespace std {
template<>
struct hash<openmc::CellInstance> {
// Taken from https://stackoverflow.com/a/17017281
std::size_t operator()(const openmc::CellInstance& k) const
struct CellInstanceHash {
std::size_t operator()(const CellInstance& k) const
{
std::size_t res = 17;
res = 31 * res + std::hash<gsl::index>()(k.index_cell);
res = 31 * res + std::hash<gsl::index>()(k.instance);
return res;
return 4096*k.index_cell + k.instance;
}
};
} // namespace std
//==============================================================================
// Non-member functions
//==============================================================================
namespace openmc {
void read_cells(pugi::xml_node node);
#ifdef DAGMC

View file

@ -55,7 +55,7 @@ private:
std::vector<CellInstance> cell_instances_;
//! A map from cell/instance indices to filter bin indices.
std::unordered_map<CellInstance, gsl::index> map_;
std::unordered_map<CellInstance, gsl::index, CellInstanceHash> map_;
};
} // namespace openmc