Hi, I wrote a small sparse matrix class with the member:
std::map<int,std::map<int,double> > sm;
The method below is the function i use to access the elements of a matrix, if not possible through an iterator:
double matrix::operator()(int r,int c) const
{
std::map<int,std::map<int,double> >::const_iterator i = sm.find(r);
if(i==sm.end()) { return 0.0; }
std::map<int,double>::const_iterator j = i->second.find(c);
if(j==i->second.end()) { return 0.0; }
return j->second;
}
Still this function needs to get called very often. Has somebody an idea how to improve this function? Thanks ahead.