diff --git a/librerie/exercise5/matrix/csr/matrixcsr.cpp b/librerie/exercise5/matrix/csr/matrixcsr.cpp index 9a91c0c..cae8ab6 100644 --- a/librerie/exercise5/matrix/csr/matrixcsr.cpp +++ b/librerie/exercise5/matrix/csr/matrixcsr.cpp @@ -37,7 +37,7 @@ MatrixCSR::MatrixCSR(const MatrixCSR& toCopy) : MatrixCSR(toCopy.rows, toC } template -MatrixCSR::MatrixCSR(MatrixCSR&& toMove) : MatrixCSR() noexcept{ // controllare se chiamare MatrixCSR() +MatrixCSR::MatrixCSR(MatrixCSR&& toMove) noexcept{ std::swap(rows, toMove.rows); std::swap(columns, toMove.columns); std::swap(size, toMove.size); @@ -75,7 +75,22 @@ MatrixCSR& MatrixCSR::operator=(MatrixCSR&& toMove) noexcept{ template bool MatrixCSR::operator==(const MatrixCSR& toCompare) const noexcept{ + if(columns == toCompare.columns && rows == toCompare.rows && size==toCompare.size){ + for(ulong i=0 ; i<(R.Size()-1) ; ++i){ + for(Node** ptr1 = R[i], ptr2 = toCopy.R[i] ; ptr1!=R[i+1] && ptr2!=toCopy.R[i+1] ; ptr1 = &( (*(*ptr1)).next ) , ptr2 = &( (*(*ptr2)).next ) ){ + if( ( ((*ptr1)->value).first != ((*ptr2)->value).first ) || ( ((*ptr1)->value).second != ((*ptr2)->value).second )) return false; + + if( (&((*(*ptr1)).next)==R[i+1] && &((*(*ptr2)).next) != toCopy.R.[i+1]) || (&((*(*ptr1)).next)!=R[i+1] && &((*(*ptr2)).next) == toCopy.R.[i+1])){ + return false; + } + + } + } + return true; + }else{ + return false; + } } template @@ -84,13 +99,94 @@ bool MatrixCSR::operator!=(const MatrixCSR& toCompare) const noexcept{ } template -void RowResize(const ulong& new_row_size){ - R.Resize(new_row_size+1); - for(ulong i=rows ; i::RowResize(const ulong& new_row_size){ + if(new_row_size == 0){ + Clear(); + } + else if(new_row_size > row){ + R.Resize(new_row_size+1); + for(ulong i=rows ; inext; + delete toDelete; + toDelete = tmp; + --size; + } + *(R[new_row_size]) = nullptr; + R.Resize(new_row_size+1); + rows = new_row_size; + } +} + +template +void MatrixCSR::ColumnResize(const ulong& new_column_size){ + if(new_column_size == 0){ + Clear(); + } + else if(new_column_size > columns){ + columns = new_column_size; + } + else if(new_column_size < columns){ + Node** add; + for(ulong i=0 ; ivalue).second) >= new_row_size) break; + } + if(ptr!=R[i+1]){ + //? + } + } + } +} + +template +bool MatrixCSR::ExistsCell(const ulong& r, const ulong& c) noexcept{ + if(r>=row || c>=column) return false; + Node** ptr = R[r]; + while(ptr != R[r+1]){ + if( (**ptr).value.second == c ) return true; + ptr = &((**ptr).next); + } + return false; +} + +template +const Data& MatrixCSR::operator()(const ulong& r, const ulong& c) const{ + if(r>=row || c>=column) throw std::out_of_range("Tried to access position ["< +Data& MatrixCSR::operator()(const ulong& r, const ulong& c){ + if(r>=row || c>=column) throw std::out_of_range("Tried to access position ["< c){ + Node** tmp = *ptr; + //? + } + } } - rows = new_row_size; - size = new_row_size * columns; } /* ************************************************************************** */