Matrix 通过std::map更快地工作
我有个问题。我有一个程序正在运行,使用的是这样的地图:Matrix 通过std::map更快地工作,matrix,stdmap,Matrix,Stdmap,我有个问题。我有一个程序正在运行,使用的是这样的地图: template<typename T> class Matrix{ public: //--- Parameters --- std::map<std::array<int,2>,T> data; const int nRow; const int nCol; 模板 类矩阵{ 公众: //---参数--- 地图数据; 恒流; 康斯特国际学院; 这对所有方法和操作符都很
template<typename T>
class Matrix{
public:
//--- Parameters ---
std::map<std::array<int,2>,T> data;
const int nRow;
const int nCol;
模板
类矩阵{
公众:
//---参数---
地图数据;
恒流;
康斯特国际学院;
这对所有方法和操作符都很有效。
到目前为止,我一直在为操作符使用for循环,例如:
Matrix& operator+=(const Matrix<T>& other){
for (auto r = 0; r<nRow;r++){
for (auto c= 0; c<nCol;c++){
if(other.data.count({r,c}))
data[{r,c}] +=other[{r,c}];
};
};
return *this;
};
Matrix operator+(const Matrix<T>& other){
return Matrix(*this)+=other;
};
矩阵和运算符+=(常数矩阵和其他){
对于(自动r=0;r