Advertisement
miki_brill

Untitled

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