mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-26 21:25:36 -04:00
Simplify CellInstance hash function and use template argument for unordered_map
This commit is contained in:
parent
9787e9e8c0
commit
37eaaabd6c
2 changed files with 4 additions and 14 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue