Advertisement
miki_brill

Untitled

Jan 3rd, 2015
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 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. public:
  19. vector <rowVecItem>::iterator begin();
  20. vector <rowVecItem>::iterator end();
  21. rowVecItem& at(int index);
  22. const rowVecItem& at(int index) const;
  23. };
  24.  
  25. vector <rowVecItem>::iterator rowVec::begin(){
  26. return allRowItems.begin();
  27. }
  28. vector <rowVecItem>::iterator rowVec::end(){
  29. return allRowItems.end();
  30. }
  31. rowVecItem& rowVec::at(int index){
  32. return allRowItems.at(index);
  33. }
  34.  
  35. const rowVecItem& rowVec::at(int index) const{
  36. return allRowItems.at(index);
  37. }
  38.  
  39. //template <class T>
  40. class sparseMatrix{
  41. int maxRows;
  42. int maxCols;
  43. vector <rowVec> sparseMatVec;
  44. public:
  45. sparseMatrix(int rows, int cols);
  46. sparseMatrix(const sparseMatrix& sm);
  47. ~sparseMatrix();
  48. int getRowCount() const;
  49. int getColCount() const;
  50. int getNotEmptyCells();
  51. void iterateNonZeroRowVals();
  52. T& operator()(int row, int col);
  53. T& operator=(const T&);
  54. sparseMatrix& operator+=(const sparseMatrix& sm);
  55. vector <rowVec>::iterator begin();
  56. vector <rowVec>::iterator end();
  57. rowVec& at(int index);
  58. const rowVec& at(int index) const;
  59. };
  60.  
  61. sparseMatrix operator+(const sparseMatrix& sm1, const sparseMatrix& sm2);
  62. sparseMatrix operator*(const sparseMatrix& sm1, const sparseMatrix& sm2);
  63.  
  64. vector <rowVec>::iterator sparseMatrix::begin(){
  65. return sparseMatVec.begin();
  66. }
  67.  
  68. vector <rowVec>::iterator sparseMatrix::end(){
  69. return sparseMatVec.end();
  70. }
  71.  
  72. rowVec& sparseMatrix::at(int index){
  73. return sparseMatVec.at(index);
  74. }
  75.  
  76. const rowVec& sparseMatrix::at(int index) const{
  77. return sparseMatVec.at(index);
  78. }
  79.  
  80. //NOT COMPLETED
  81. sparseMatrix::sparseMatrix(const sparseMatrix& sm){
  82. maxRows = sm.getRowCount();
  83. maxCols = sm.getColCount();
  84. }
  85.  
  86. int sparseMatrix::getRowCount() const{
  87. return maxRows;
  88. }
  89.  
  90. int sparseMatrix::getColCount() const{
  91. return maxCols;
  92. }
  93.  
  94. /*
  95. template <class T>
  96. class rowVecItem{
  97. int col;
  98. T val;
  99. };
  100. template <class T>
  101. class rowVec{
  102. //typedef ___ iterator; - public/private
  103. int row;
  104. vector <rowVecItem<T> > allRowItems;
  105. };
  106. template <class T>
  107. class sparseMatrix{
  108. // iterator - public/private
  109. vector <rowVec<T> > sparseMatVec;
  110. };
  111. */
  112. #endif /* SPARSE_H_ */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement