From 37eaaabd6cf97caa8653af5c7cc089935be7a096 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Fri, 10 Jan 2020 06:54:05 -0600 Subject: [PATCH] Simplify CellInstance hash function and use template argument for unordered_map --- include/openmc/cell.h | 16 +++------------- include/openmc/tallies/filter_cell_instance.h | 2 +- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/include/openmc/cell.h b/include/openmc/cell.h index d3b411dda..3df2f40d5 100644 --- a/include/openmc/cell.h +++ b/include/openmc/cell.h @@ -300,28 +300,18 @@ struct CellInstance { gsl::index index_cell; gsl::index instance; }; -} // namespace openmc -namespace std { -template<> -struct hash { - // 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()(k.index_cell); - res = 31 * res + std::hash()(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 diff --git a/include/openmc/tallies/filter_cell_instance.h b/include/openmc/tallies/filter_cell_instance.h index 33874b85d..1b2cdd425 100644 --- a/include/openmc/tallies/filter_cell_instance.h +++ b/include/openmc/tallies/filter_cell_instance.h @@ -55,7 +55,7 @@ private: std::vector cell_instances_; //! A map from cell/instance indices to filter bin indices. - std::unordered_map map_; + std::unordered_map map_; }; } // namespace openmc