mirror of
https://gitlab.com/klmp200/LO27.git
synced 2024-11-22 22:43:19 +00:00
SequenceOnMatrix operations
This commit is contained in:
parent
b063bc42c0
commit
f327f1024b
@ -51,7 +51,7 @@ bool CreateMatrixElem(Matrix matrix, int ColPos, int RowPos){
|
|||||||
|
|
||||||
Row = GetElementPos(matrix.rows,RowPos);
|
Row = GetElementPos(matrix.rows,RowPos);
|
||||||
if (Row != NULL && Row->data != NULL){
|
if (Row != NULL && Row->data != NULL){
|
||||||
|
|
||||||
if (Row->data->colIndex == ColPos){
|
if (Row->data->colIndex == ColPos){
|
||||||
error ++;
|
error ++;
|
||||||
} else if (Row->data->colIndex > ColPos){
|
} else if (Row->data->colIndex > ColPos){
|
||||||
@ -77,7 +77,7 @@ bool CreateMatrixElem(Matrix matrix, int ColPos, int RowPos){
|
|||||||
|
|
||||||
Col = GetElementPos(matrix.cols,ColPos);
|
Col = GetElementPos(matrix.cols,ColPos);
|
||||||
if (Col != NULL && Col->data != NULL){
|
if (Col != NULL && Col->data != NULL){
|
||||||
|
|
||||||
if (Col->data->rowIndex == RowPos){
|
if (Col->data->rowIndex == RowPos){
|
||||||
error ++;
|
error ++;
|
||||||
} else if (Col->data->rowIndex > RowPos){
|
} else if (Col->data->rowIndex > RowPos){
|
||||||
@ -134,7 +134,7 @@ int SupprMatrixElem(Matrix matrix, int ColPos, int RowPos){
|
|||||||
|
|
||||||
ListElement * Row = NULL;
|
ListElement * Row = NULL;
|
||||||
ListElement * Col = NULL;
|
ListElement * Col = NULL;
|
||||||
|
|
||||||
elem = FindMatrixElem(matrix,ColPos,RowPos);
|
elem = FindMatrixElem(matrix,ColPos,RowPos);
|
||||||
if (elem == NULL){
|
if (elem == NULL){
|
||||||
return 0;
|
return 0;
|
||||||
@ -161,7 +161,7 @@ int SupprMatrixElem(Matrix matrix, int ColPos, int RowPos){
|
|||||||
} else {
|
} else {
|
||||||
tmp->nextCol = elem->nextCol;
|
tmp->nextCol = elem->nextCol;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (Row->data == NULL){
|
if (Row->data == NULL){
|
||||||
RemoveElementPos(matrix.rows,RowPos);
|
RemoveElementPos(matrix.rows,RowPos);
|
||||||
@ -187,12 +187,12 @@ int SupprMatrixElem(Matrix matrix, int ColPos, int RowPos){
|
|||||||
return -4; /* should never happend */
|
return -4; /* should never happend */
|
||||||
} else {
|
} else {
|
||||||
tmp->nextRow = elem->nextRow;
|
tmp->nextRow = elem->nextRow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Col->data == NULL){
|
if (Col->data == NULL){
|
||||||
RemoveElementPos(matrix.cols,ColPos);
|
RemoveElementPos(matrix.cols,ColPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
FreeCellElement(elem);
|
FreeCellElement(elem);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
@ -225,16 +225,18 @@ void BasicPrintMatrix(Matrix matrix){
|
|||||||
/* Non optimisé : debug fx */
|
/* Non optimisé : debug fx */
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
|
bool b;
|
||||||
|
|
||||||
printf("\n---PRINT MATRIX---\n");
|
printf("\n---PRINT MATRIX---\n");
|
||||||
|
|
||||||
for (i=0;i<matrix.colCount;i++){
|
for (i=0;i<matrix.rowCount;i++){
|
||||||
printf("| ");
|
printf("| ");
|
||||||
for (j=0;j<matrix.rowCount;j++){
|
for (j=0;j<matrix.colCount;j++){
|
||||||
|
|
||||||
if (GetCellValue(matrix,i,j) == true){
|
b = GetCellValue(matrix,j,i);
|
||||||
|
if (b == true){
|
||||||
printf("1 ");
|
printf("1 ");
|
||||||
}else if (GetCellValue(matrix,i,j) == false){
|
}else if (b == false){
|
||||||
printf("0 ");
|
printf("0 ");
|
||||||
}else{
|
}else{
|
||||||
printf("X "); /* error out of bounds, should never happend*/
|
printf("X "); /* error out of bounds, should never happend*/
|
||||||
@ -244,14 +246,14 @@ void BasicPrintMatrix(Matrix matrix){
|
|||||||
printf("|\n");
|
printf("|\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("---END OF MATRIX---\n\n");
|
printf("---END OF MATRIX---\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RecursiveFreeCol(Matrix matrix, cellElement * elem){
|
bool RecursiveFreeCol(Matrix matrix, cellElement * elem){
|
||||||
cellElement * tmp = NULL;
|
cellElement * tmp = NULL;
|
||||||
ListElement * Row = NULL;
|
ListElement * Row = NULL;
|
||||||
|
|
||||||
if (elem == NULL){
|
if (elem == NULL){
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
@ -259,11 +261,11 @@ bool RecursiveFreeCol(Matrix matrix, cellElement * elem){
|
|||||||
if (elem->nextRow != NULL){
|
if (elem->nextRow != NULL){
|
||||||
RecursiveFreeCol(matrix,elem->nextRow);
|
RecursiveFreeCol(matrix,elem->nextRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (elem->nextRow == NULL){
|
if (elem->nextRow == NULL){
|
||||||
|
|
||||||
Row = GetElementPos(matrix.rows,elem->rowIndex);
|
Row = GetElementPos(matrix.rows,elem->rowIndex);
|
||||||
|
|
||||||
if (Row == NULL || Row->data == NULL ){
|
if (Row == NULL || Row->data == NULL ){
|
||||||
return ERROR; /*should never happend*/
|
return ERROR; /*should never happend*/
|
||||||
}
|
}
|
||||||
@ -280,7 +282,7 @@ bool RecursiveFreeCol(Matrix matrix, cellElement * elem){
|
|||||||
} else {
|
} else {
|
||||||
tmp->nextCol = elem->nextCol;
|
tmp->nextCol = elem->nextCol;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FreeCellElement(elem);
|
FreeCellElement(elem);
|
||||||
@ -311,6 +313,75 @@ Matrix freeMatrix(Matrix matrix){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Matrix colSequenceOnMatrix(Matrix m, bool (operator)(bool, bool)){
|
||||||
|
bool a;
|
||||||
|
bool b;
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
Matrix newM = CreateMatrix();
|
||||||
|
|
||||||
|
|
||||||
|
newM.rowCount = m.rowCount;
|
||||||
|
if (m.colCount <= 1){
|
||||||
|
newM.colCount = 0;
|
||||||
|
return newM;
|
||||||
|
}
|
||||||
|
newM.colCount = m.colCount - 1;
|
||||||
|
|
||||||
|
for (i=0;i < m.colCount - 1;i++){
|
||||||
|
for (j=0;j < m.rowCount;j++){
|
||||||
|
a = GetCellValue(m, i, j);
|
||||||
|
b = GetCellValue(m, i + 1, j);
|
||||||
|
if (operator(a, b)){
|
||||||
|
SetCellValue(newM, i, j, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return newM;
|
||||||
|
}
|
||||||
|
|
||||||
|
Matrix rowSequenceOnMatrix(Matrix m, bool (operator)(bool, bool)){
|
||||||
|
bool a;
|
||||||
|
bool b;
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
Matrix newM = CreateMatrix();
|
||||||
|
|
||||||
|
newM.colCount = m.colCount;
|
||||||
|
if (m.rowCount <= 1){
|
||||||
|
newM.rowCount = 0;
|
||||||
|
return newM;
|
||||||
|
}
|
||||||
|
newM.rowCount = m.rowCount - 1;
|
||||||
|
|
||||||
|
for (i=0; i < m.colCount;i++){
|
||||||
|
for (j=0;j < m.rowCount - 1;j++){
|
||||||
|
a = GetCellValue(m, i, j);
|
||||||
|
b = GetCellValue(m, i, j + 1);
|
||||||
|
if (operator(a, b)){
|
||||||
|
SetCellValue(newM, i, j, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return newM;
|
||||||
|
}
|
||||||
|
|
||||||
|
Matrix andColSequenceOnMatrix(Matrix m){
|
||||||
|
return colSequenceOnMatrix(m, AND);
|
||||||
|
}
|
||||||
|
|
||||||
|
Matrix orColSequenceOnMatrix(Matrix m){
|
||||||
|
return colSequenceOnMatrix(m, OR);
|
||||||
|
}
|
||||||
|
|
||||||
|
Matrix andRowSequenceOnMatrix(Matrix m){
|
||||||
|
return rowSequenceOnMatrix(m, AND);
|
||||||
|
}
|
||||||
|
|
||||||
|
Matrix orRowSequenceOnMatrix(Matrix m){
|
||||||
|
return rowSequenceOnMatrix(m, OR);
|
||||||
|
}
|
||||||
|
|
||||||
/* todos :
|
/* todos :
|
||||||
*finir le freeMatrix
|
*finir le freeMatrix
|
||||||
*chasser les bugs
|
*chasser les bugs
|
||||||
|
@ -120,7 +120,7 @@ Matrix SetMatrixDim(Matrix matrix,int nbCols,int nbRows);
|
|||||||
/**
|
/**
|
||||||
*Basically print the Matrix in the standard output
|
*Basically print the Matrix in the standard output
|
||||||
*
|
*
|
||||||
*@param matrix the Matrix
|
*@param matrix the Matrix
|
||||||
*
|
*
|
||||||
*@return void
|
*@return void
|
||||||
*
|
*
|
||||||
@ -131,6 +131,61 @@ bool RecursiveFreeCol(Matrix matrix, cellElement * elem);
|
|||||||
|
|
||||||
Matrix freeMatrix(Matrix matrix);
|
Matrix freeMatrix(Matrix matrix);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given an input matrix with M rows and N columns, computes a matrix with
|
||||||
|
* M rows and N-1 columns were each element corresponds to the operator boolean operation
|
||||||
|
* between two successive horizontal elements in the input matrix
|
||||||
|
* @param m a Matrix
|
||||||
|
* @param operator a function
|
||||||
|
* @return matrix the copmuted matrix
|
||||||
|
*/
|
||||||
|
Matrix colSequenceOnMatrix(Matrix m, bool (operator)(bool, bool));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given an input matrix with M rows and N columns, computes a matrix with
|
||||||
|
* M-1 rows and N columns were each element corresponds to the operator boolean operation
|
||||||
|
* between two succesive vertical elements in the input matrix
|
||||||
|
* @param m a Matrix
|
||||||
|
* @param operator a function
|
||||||
|
* @return matrix the copmuted matrix
|
||||||
|
*/
|
||||||
|
Matrix rowSequenceOnMatrix(Matrix m, bool (operator)(bool, bool));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given an input matrix with M rows and N columns, computes a matrix with
|
||||||
|
* M rows and N-1 columns were each element corresponds to the AND boolean operation
|
||||||
|
* between two successive horizontal elements in the input matrix
|
||||||
|
* @param m a Matrix
|
||||||
|
* @return matrix the copmuted matrix
|
||||||
|
*/
|
||||||
|
Matrix andColSequenceOnMatrix(Matrix m);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given an input matrix with M rows and N columns, computes a matrix with
|
||||||
|
* M rows and N-1 columns were each element corresponds to the OR boolean operation
|
||||||
|
* between two successive horizontal elements in the input matrix
|
||||||
|
* @param m a Matrix
|
||||||
|
* @return matrix the copmuted matrix
|
||||||
|
*/
|
||||||
|
Matrix orColSequenceOnMatrix(Matrix m);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given an input matrix with M rows and N columns, computes a matrix with
|
||||||
|
* M-1 rows and N columns were each element corresponds to the AND boolean operation
|
||||||
|
* between two succesive vertical elements in the input matrix
|
||||||
|
* @param m a Matrix
|
||||||
|
* @return matrix the copmuted matrix
|
||||||
|
*/
|
||||||
|
Matrix andRowSequenceOnMatrix(Matrix m);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given an input matrix with M rows and N columns, computes a matrix with
|
||||||
|
* M-1 rows and N columns were each element corresponds to the OR boolean operation
|
||||||
|
* between two succesive vertical elements in the input matrix
|
||||||
|
* @param m a Matrix
|
||||||
|
* @return matrix the copmuted matrix
|
||||||
|
*/
|
||||||
|
Matrix orRowSequenceOnMatrix(Matrix m);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
10
main.c
10
main.c
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
int main(int argc, char **argv){
|
int main(int argc, char **argv){
|
||||||
Matrix matrix = CreateMatrix();
|
Matrix matrix = CreateMatrix();
|
||||||
|
Matrix m2;
|
||||||
int Rule = 256;
|
int Rule = 256;
|
||||||
int N = 1;
|
int N = 1;
|
||||||
applyRules(matrix,Rule,N);
|
applyRules(matrix,Rule,N);
|
||||||
@ -26,7 +27,14 @@ int main(int argc, char **argv){
|
|||||||
|
|
||||||
SetCellValue(matrix,0,0,false);
|
SetCellValue(matrix,0,0,false);
|
||||||
SetCellValue(matrix,0,1,false);
|
SetCellValue(matrix,0,1,false);
|
||||||
BasicPrintMatrix(matrix);
|
BasicPrintMatrix(matrix);
|
||||||
|
|
||||||
|
m2 = colSequenceOnMatrix(matrix, OR);
|
||||||
|
BasicPrintMatrix(m2);
|
||||||
|
freeMatrix(m2);
|
||||||
|
m2 = rowSequenceOnMatrix(matrix, AND);
|
||||||
|
BasicPrintMatrix(m2);
|
||||||
|
freeMatrix(m2);
|
||||||
|
|
||||||
freeMatrix(matrix);
|
freeMatrix(matrix);
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user