I am running an algorithm in C++ based on a binary tree computation with iteration and induction.
For this purpose I nested map like this
typedef map<double, bool> b1d;
typedef map<double, b1d> mb2d;
typedef vector<mb2d> vb3d;
typedef map<double, double> m1d;
typedef map<double, m1d> m2d;
typedef vector<m2d> v3d;
m2d ZY;
v3d * V = new v3d (n+1, m2d(ZY));
mb2d ZYb;
vb3d * Vb = new vb3d (n+1, mb2d(ZYb));
and I change the values like that
(*J_tab)[K+1.0][Z+y][W - 1.0/sqrt((double) n)] = V_tmp;
(*J_bool)[K+1.0][Z+y][W - 1.0/sqrt((double) n)] = true;
The problem is I obtain many duplication and it is strange for an std::map as you can see in this picture I have obtained with my debugger
In this picture you can see in the second degree many duplication 0.6 or 0.7 for instance and at the third degree in 0.3.
The only way to get rid of the duplication I have found is to change double to string i.e.
typedef map<string, bool> b1d;
typedef map<string, b1d> mb2d;
typedef vector<mb2d> vb3d;
and making those operations
std::string strZy, strWm, strWp;
std::ostringstream strsZy, strsWm, strsWp;
int precision = 5;
strsZy << fixed << setprecision(precision) << Z+y;
strsWp << fixed << setprecision(precision) << W + 1.0/sqrt((double) n);
strsWm << fixed << setprecision(precision) << W - 1.0/sqrt((double) n);
strZy = strsZy.str();
strWm = strsWm.str();strWp = strsWp.str();
However I think it takes more memory than a double and more time, so it is not the most efficient solution.
Someone know how to correct it ? or another elegant way to do it ?