v4 parser NumericalConstants.{cc,hh}: optimization to avoid multiple IDs for the same constant
git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@1094 ac1d8469-bf42-47a9-8791-bf33cf982152time-shift
parent
56f54de49a
commit
9ff865e84b
|
@ -10,12 +10,13 @@ using namespace std;
|
|||
#include "NumericalConstants.hh"
|
||||
//------------------------------------------------------------------------------
|
||||
vector<string> NumericalConstants::mNumericalConstants;
|
||||
map<string, int, less<string> > NumericalConstants::numConstantsIndex;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
NumericalConstants::NumericalConstants()
|
||||
{
|
||||
mNumericalConstants.push_back("0.0");
|
||||
mNumericalConstants.push_back("1.0");
|
||||
|
||||
AddConstant("0.0");
|
||||
AddConstant("1.0");
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
@ -27,12 +28,15 @@ NumericalConstants::~NumericalConstants()
|
|||
//------------------------------------------------------------------------------
|
||||
int NumericalConstants::AddConstant(string iConst)
|
||||
{
|
||||
if (iConst == "0.0")
|
||||
return 0;
|
||||
else if (iConst == "1.0")
|
||||
return 1;
|
||||
map<string, int, less<string> >::iterator iter = numConstantsIndex.find(iConst);
|
||||
|
||||
if (iter != numConstantsIndex.end())
|
||||
return iter->second;
|
||||
|
||||
int id = (int) mNumericalConstants.size();
|
||||
mNumericalConstants.push_back(iConst);
|
||||
return (int) mNumericalConstants.size()-1;
|
||||
numConstantsIndex[iConst] = id;
|
||||
return id;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
//------------------------------------------------------------------------------
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
//------------------------------------------------------------------------------
|
||||
/*!
|
||||
\class NumericalConstants
|
||||
|
@ -19,6 +20,8 @@ class NumericalConstants
|
|||
private :
|
||||
/*! Vector of numerical constants */
|
||||
static std::vector<std::string> mNumericalConstants;
|
||||
//! Map matching constants to their id
|
||||
static std::map<std::string, int, std::less<std::string> > numConstantsIndex;
|
||||
public :
|
||||
/*! Construcor */
|
||||
NumericalConstants();
|
||||
|
|
Loading…
Reference in New Issue