Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef SPARSE_H_
- #define SPARSE_H_
- #include <iostream>
- #include <cmath>
- #include <vector>
- using std::vector;
- namespace mtm{
- typedef double T;
- //template <class T>
- class rowVecItem{
- int index;
- T val;
- public:
- T& get();
- friend class rowVec;
- };
- //////////////////funcs of class rowVecItem/////////////////////////////////////
- T& rowVecItem::get(){
- return val;
- }
- ////////////////////////////////////////////////////////////////////////////////
- //template <class T>
- class rowVec{
- int index;
- vector <rowVecItem> all_row_items;
- public:
- vector <rowVecItem>::iterator begin();
- vector <rowVecItem>::iterator end();
- rowVecItem& at(int index);
- const rowVecItem& at(int index) const;
- vector <rowVecItem>& get();
- friend class SparseMatrix;
- };
- ///////////////////////funcs of class rowVec////////////////////////////////////
- vector <rowVecItem>& rowVec::get(){
- return all_row_items;
- }
- vector <rowVecItem>::iterator rowVec::begin(){
- return all_row_items.begin();
- }
- vector <rowVecItem>::iterator rowVec::end(){
- return all_row_items.end();
- }
- rowVecItem& rowVec::at(int index){
- return all_row_items.at(index);
- }
- const rowVecItem& rowVec::at(int index) const{
- return all_row_items.at(index);
- }
- ////////////////////////////////////////////////////////////////////////////////
- //template <class T>
- class SparseMatrix{
- int max_rows;
- int max_cols;
- vector <rowVec> sparse_mat_vec;
- public:
- typedef vector <rowVec>::const_iterator row_const_iterator;
- SparseMatrix(int rows, int cols);
- SparseMatrix(const SparseMatrix& sm);
- ~SparseMatrix();
- int get_row_count() const;
- int get_col_count() const;
- int get_non_zero_cells();
- void iterate_non_zero_row_vals();
- //T& operator()(int row, int col); // reading+writing.
- //const T operator()(int row, int col) const; // reading only.
- SparseMatrix& operator+=(const SparseMatrix& sm);
- vector <rowVec>::iterator begin();
- vector <rowVec>::iterator end();
- rowVec& at(int index);
- const rowVec& at(int index) const;
- };
- SparseMatrix operator+(const SparseMatrix& sm1, const SparseMatrix& sm2);
- SparseMatrix operator*(const SparseMatrix& sm1, const SparseMatrix& sm2);
- ///////////////////////funcs of class rowVec////////////////////////////////////
- //NOT COMPLETED
- SparseMatrix::~SparseMatrix(){
- }
- vector <rowVec>::iterator SparseMatrix::begin(){
- return sparse_mat_vec.begin();
- }
- vector <rowVec>::iterator SparseMatrix::end(){
- return sparse_mat_vec.end();
- }
- rowVec& SparseMatrix::at(int index){
- return sparse_mat_vec.at(index);
- }
- const rowVec& SparseMatrix::at(int index) const{
- return sparse_mat_vec.at(index);
- }
- //NOT COMPLETED
- SparseMatrix::SparseMatrix(const SparseMatrix& sm){
- max_rows = sm.get_row_count();
- max_cols = sm.get_col_count();
- }
- int SparseMatrix::get_row_count() const{
- return max_rows;
- }
- int SparseMatrix::get_col_count() const{
- return max_cols;
- }
- SparseMatrix::SparseMatrix(int rows, int cols): max_rows(rows), max_cols(cols){
- vector<rowVec> sparseMatVec();
- }
- /*int sparseMatrix::get_non_zero_cells(){
- int count=0;
- int row=0;
- for(vector<rowVec>::iterator i = sparseMatVec.begin();
- i != sparseMatVec.end(); ++i) {
- for(vector<rowVecItem>::iterator i = rowVec::allRowItems.begin();
- i != rowVec::allRowItems.end(); ++i) {
- }
- row=0;
- }
- return count;
- }*/
- ////////////////////////////////////////////////////////////////////////////////
- }
- /*
- template <class T>
- class rowVecItem{
- int col;
- T val;
- };
- template <class T>
- class rowVec{
- //typedef ___ iterator; - public/private
- int row;
- vector <rowVecItem<T> > allRowItems;
- };
- template <class T>
- class sparseMatrix{
- // iterator - public/private
- vector <rowVec<T> > sparseMatVec;
- };
- */
- #endif /* SPARSE_H_ */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement