From 8ded648bf49d2d725a48ea7f41757c8498d65f27 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Fri, 28 Jun 2013 21:24:44 +0000 Subject: [PATCH] Speed up duplicate reaction check in installReactions This version of the "participants" key is more likely to have collisions, but having the key be a simple scalar speeds things up quite a bit. --- src/kinetics/importKinetics.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/kinetics/importKinetics.cpp b/src/kinetics/importKinetics.cpp index 8b07b903d..f6c0b9cc0 100644 --- a/src/kinetics/importKinetics.cpp +++ b/src/kinetics/importKinetics.cpp @@ -49,9 +49,9 @@ class rxninfo public: std::vector m_rdata; - //! Map of (vector indicating participating species) to reaction numbers + //! Map of (key indicating participating species) to reaction numbers //! Used to speed up duplicate reaction checks. - std::map, std::vector > m_participants; + std::map > m_participants; /** * Install an individual reaction into a kinetics manager. The @@ -752,14 +752,14 @@ bool rxninfo::installReaction(int iRxn, const XML_Node& r, Kinetics& kin, if (validate_rxn) { // Look for undeclared duplicate reactions. - vector participants(kin.nTotalSpecies(), 0); + unsigned long int participants = 0; for (size_t nn = 0; nn < rdata.reactants.size(); nn++) { rdata.net_stoich[-1 - int(rdata.reactants[nn])] -= rdata.rstoich[nn]; - participants[rdata.reactants[nn]] += 1; + participants += rdata.reactants[nn]; } for (size_t nn = 0; nn < rdata.products.size(); nn++) { rdata.net_stoich[int(rdata.products[nn])+1] += rdata.pstoich[nn]; - participants[rdata.products[nn]] += 2; + participants += 1000000 * rdata.products[nn]; } vector& related = m_participants[participants];