Advertisement
miki_brill

Untitled

Jan 3rd, 2015
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. #ifndef SPARSE_H_
  2. #define SPARSE_H_
  3. #include <iostream>
  4. #include <cmath>
  5. #include <vector>
  6. using std::vector;
  7.  
  8. typedef double T;
  9. //template <class T>
  10. class rowVecItem{
  11. int col;
  12. T val;
  13. };
  14. //template <class T>
  15. class rowVec{
  16. int row;
  17. vector <rowVecItem> allRowItems;
  18. };
  19. //template <class T>
  20. class sparseMatrix{
  21. int maxRows;
  22. int maxCols;
  23. vector <rowVec> sparseMatVec;
  24. public:
  25. sparseMatrix(int rows, int cols);
  26. sparseMatrix(const sparseMatrix& sm);
  27. ~sparseMatrix();
  28. int getRowCount() const;
  29. int getColCount() const;
  30. int getNotEmptyCells();
  31. void iterateNonZeroRowVals();
  32. T& operator()(int row, int col);
  33. T& operator=(const T&);
  34. sparseMatrix& operator+=(const sparseMatrix& sm);
  35. vector <rowVec>::iterator begin();
  36. vector <rowVec>::iterator end();
  37. rowVec& at(int index);
  38. const rowVec& at(int index) const;
  39. };
  40.  
  41. sparseMatrix operator+(const sparseMatrix& sm1, const sparseMatrix& sm2);
  42. sparseMatrix operator*(const sparseMatrix& sm1, const sparseMatrix& sm2);
  43.  
  44.  
  45. vector <rowVec>::iterator sparseMatrix::begin(){
  46. return sparseMatVec.begin();
  47. }
  48.  
  49. vector <rowVec>::iterator sparseMatrix::end(){
  50. return sparseMatVec.end();
  51. }
  52.  
  53. rowVec& sparseMatrix::at(int index){
  54. return sparseMatVec.at(index);
  55. }
  56.  
  57. sparseMatrix::sparseMatrix(const sparseMatrix& sm){
  58. maxRows = sm.getRowCount();
  59. maxCols = sm.getColCount();
  60. }
  61.  
  62. int sparseMatrix::getRowCount() const{
  63. return maxRows;
  64. }
  65.  
  66. int sparseMatrix::getColCount() const{
  67. return maxCols;
  68. }
  69.  
  70. /*
  71. template <class T>
  72. class rowVecItem{
  73. int col;
  74. T val;
  75. };
  76. template <class T>
  77. class rowVec{
  78. //typedef ___ iterator; - public/private
  79. int row;
  80. vector <rowVecItem<T> > allRowItems[0];
  81. };
  82. template <class T>
  83. class sparseMatrix{
  84. // iterator - public/private
  85. vector <rowVec<T> > sparseMatVec[0];
  86. };
  87. */
  88. #endif /* SPARSE_H_ */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement