Library 5

This commit is contained in:
Alessandro Ferro
2021-06-05 14:25:22 +02:00
parent 98f7065258
commit d15173a276
3 changed files with 19 additions and 26 deletions

View File

@ -116,10 +116,7 @@ bool MatrixCSR<Data>::operator!=(const MatrixCSR& toCompare) const noexcept{
template <typename Data> template <typename Data>
void MatrixCSR<Data>::RowResize(const ulong& new_row_size){ void MatrixCSR<Data>::RowResize(const ulong& new_row_size){
if(new_row_size == 0){ if(new_row_size > rows){
Clear();
}
else if(new_row_size > rows){
R.Resize(new_row_size+1); R.Resize(new_row_size+1);
for(ulong i=rows+1 ; i<R.Size(); ++i){ for(ulong i=rows+1 ; i<R.Size(); ++i){
R[i] = R[rows]; R[i] = R[rows];
@ -143,10 +140,7 @@ void MatrixCSR<Data>::RowResize(const ulong& new_row_size){
template <typename Data> template <typename Data>
void MatrixCSR<Data>::ColumnResize(const ulong& new_column_size){ void MatrixCSR<Data>::ColumnResize(const ulong& new_column_size){
if(new_column_size == 0){ if(new_column_size < columns){
Clear();
}
else if(new_column_size < columns){
Node** prev; Node** prev;
Node* toDelete; Node* toDelete;
Node** toModify; Node** toModify;

View File

@ -70,22 +70,17 @@ bool MatrixVec<Data>::operator!=(const MatrixVec& toCompare) const noexcept{
} }
template <typename Data> template <typename Data>
void MatrixVec<Data>::RowResize(const ulong& newdim){ void MatrixVec<Data>::RowResize(const ulong& new_row_dim){
if(newdim == 0){ if(new_row_dim != rows){
Clear(); Vector<Data>::Resize(new_row_dim * columns);
}else{ rows = new_row_dim;
Vector<Data>::Resize(newdim * columns); size = new_row_dim * columns;
rows = newdim;
size = newdim * columns;
} }
} }
template <typename Data> template <typename Data>
void MatrixVec<Data>::ColumnResize(const ulong& new_column_dim){ void MatrixVec<Data>::ColumnResize(const ulong& new_column_dim){
if(new_column_dim == 0){ if(new_column_dim != columns){
Clear();
}
else if(new_column_dim != columns){
ulong limit = (new_column_dim < columns)? new_column_dim : columns; ulong limit = (new_column_dim < columns)? new_column_dim : columns;
Data* tmp = new Data[rows * new_column_dim]{}; Data* tmp = new Data[rows * new_column_dim]{};
for(ulong i=0 ; i<rows ; ++i){ for(ulong i=0 ; i<rows ; ++i){

View File

@ -2,7 +2,6 @@
#include <random> #include <random>
#include <iostream> #include <iostream>
void menu(){ void menu(){
DataType chosenDataType; DataType chosenDataType;
@ -67,32 +66,38 @@ void UseChosenType(Implementation chosenImplementation, DataType chosenDataType)
if(chosenDataType == DataType::integer){ if(chosenDataType == DataType::integer){
MatrixVec<int> mtx; MatrixVec<int> mtx;
mtx = GenerateIntegerMat(mtx); mtx = GenerateIntegerMat(mtx);
cout<<"\nThe matrix has been randomly generated.\n";
IntegerFunctions(mtx); IntegerFunctions(mtx);
}else if(chosenDataType == DataType::ffloat){ }else if(chosenDataType == DataType::ffloat){
MatrixVec<float> mtx; MatrixVec<float> mtx;
mtx = GenerateFloatMat(mtx); mtx = GenerateFloatMat(mtx);
cout<<"\nThe matrix has been randomly generated.\n";
FloatFunctions(mtx); FloatFunctions(mtx);
}else if(chosenDataType == DataType::sstring){ }else if(chosenDataType == DataType::sstring){
MatrixVec<string> mtx; MatrixVec<string> mtx;
mtx = GenerateStringsMat(mtx); mtx = GenerateStringsMat(mtx);
cout<<"\nThe matrix has been randomly generated.\n";
StringFunctions(mtx); StringFunctions(mtx);
} }
}else if(chosenImplementation == Implementation::yale){ }else if(chosenImplementation == Implementation::yale){
if(chosenDataType == DataType::integer){ if(chosenDataType == DataType::integer){
MatrixCSR<int> mtx; MatrixCSR<int> mtx;
mtx = GenerateIntegerMat(mtx); mtx = GenerateIntegerMat(mtx);
cout<<"\nThe matrix has been randomly generated.\n";
IntegerFunctions(mtx); IntegerFunctions(mtx);
}else if(chosenDataType == DataType::ffloat){ }else if(chosenDataType == DataType::ffloat){
MatrixCSR<float> mtx; MatrixCSR<float> mtx;
mtx = GenerateFloatMat(mtx); mtx = GenerateFloatMat(mtx);
cout<<"\nThe matrix has been randomly generated.\n";
FloatFunctions(mtx); FloatFunctions(mtx);
}else if(chosenDataType == DataType::sstring){ }else if(chosenDataType == DataType::sstring){
MatrixCSR<string> mtx; MatrixCSR<string> mtx;
mtx = GenerateStringsMat(mtx); mtx = GenerateStringsMat(mtx);
cout<<"\nThe matrix has been randomly generated.\n";
StringFunctions(mtx); StringFunctions(mtx);
} }
} }
@ -524,7 +529,6 @@ T GenerateStringsMat(T& mat){
}while(column >= n_columns); }while(column >= n_columns);
matrix(row,column) = generateRandomString(dist(gen)); matrix(row,column) = generateRandomString(dist(gen));
} }
return matrix; return matrix;
} }