1
0
mirror of https://gitlab.com/klmp200/LO27.git synced 2024-11-26 09:54:13 +00:00

Renommage de fonction et plus de doc

This commit is contained in:
Antoine Bartuccio 2017-01-02 00:37:47 +01:00
parent 4648c34686
commit ec0f959f5e
7 changed files with 48 additions and 56 deletions

View File

@ -22,7 +22,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <CellElement.h> #include <CellElement.h>
cellElement * CreateCellElem(){ cellElement * createCellElem(){
cellElement * elem = NULL; cellElement * elem = NULL;
elem = (cellElement*) malloc(sizeof(cellElement)); elem = (cellElement*) malloc(sizeof(cellElement));
if (elem == NULL){ if (elem == NULL){
@ -35,7 +35,7 @@ cellElement * CreateCellElem(){
return elem; return elem;
} }
bool is_leaf(cellElement* tree){ bool isLeaf(cellElement* tree){
if (tree->nextCol == NULL && tree->nextRow == NULL){ if (tree->nextCol == NULL && tree->nextRow == NULL){
return true; return true;
} else { } else {
@ -43,7 +43,7 @@ bool is_leaf(cellElement* tree){
} }
} }
int SetPositionIndex(cellElement* elem,int Col,int Row){ int setPositionIndex(cellElement* elem,int Col,int Row){
if (elem != NULL){ if (elem != NULL){
elem->colIndex = Col; elem->colIndex = Col;
elem->rowIndex = Row; elem->rowIndex = Row;
@ -53,7 +53,7 @@ int SetPositionIndex(cellElement* elem,int Col,int Row){
return 1; return 1;
} }
int SetNextCol(cellElement* tree,cellElement* elem){ int setNextCol(cellElement* tree,cellElement* elem){
if (tree->nextCol == NULL){ if (tree->nextCol == NULL){
tree->nextCol = elem; tree->nextCol = elem;
}else{ }else{
@ -62,7 +62,7 @@ int SetNextCol(cellElement* tree,cellElement* elem){
return 1; return 1;
} }
int SetNextRow(cellElement* tree,cellElement* elem){ int setNextRow(cellElement* tree,cellElement* elem){
if (tree->nextRow == NULL){ if (tree->nextRow == NULL){
tree->nextRow = elem; tree->nextRow = elem;
}else{ }else{
@ -71,30 +71,30 @@ int SetNextRow(cellElement* tree,cellElement* elem){
return 1; return 1;
} }
int AddNextCol(cellElement* tree){ int addNextCol(cellElement* tree){
cellElement * elem = NULL; cellElement * elem = NULL;
elem = CreateCellElem(); elem = createCellElem();
if (elem == NULL){ if (elem == NULL){
return -1; return -1;
} }
return(SetNextCol(tree,elem)); return(setNextCol(tree,elem));
} }
int AddNextRow(cellElement* tree){ int addNextRow(cellElement* tree){
cellElement * elem = NULL; cellElement * elem = NULL;
elem = CreateCellElem(); elem = createCellElem();
if (elem == NULL){ if (elem == NULL){
return -1; return -1;
} }
return(SetNextRow(tree,elem)); return(setNextRow(tree,elem));
} }
@ -119,7 +119,7 @@ void removeNextRow(cellElement* tree){
void recursivePrint(cellElement * tree){ void recursivePrint(cellElement * tree){
if (tree != NULL){ if (tree != NULL){
printf("Elem : x: %d y: %d \n",tree->colIndex,tree->rowIndex); printf("Elem : x: %d y: %d \n",tree->colIndex,tree->rowIndex);
if (is_leaf(tree)){ if (isLeaf(tree)){
printf("leaf\n"); printf("leaf\n");
} else { } else {
if (tree->nextCol != NULL){ if (tree->nextCol != NULL){
@ -132,7 +132,7 @@ void recursivePrint(cellElement * tree){
} }
} }
void FreeCellElement(cellElement* element) { void freeCellElement(cellElement* element) {
if (element != NULL){ if (element != NULL){
free(element); free(element);
@ -167,7 +167,7 @@ bool XOR(bool a, bool b){
} }
} }
bool ErrorToFalse(bool x){ bool errorToFalse(bool x){
if (x == ERROR){ if (x == ERROR){
return false; return false;
} }

View File

@ -48,7 +48,7 @@ typedef enum Bool{
* @param nextCol is pointer on the next cellElement in the same column * @param nextCol is pointer on the next cellElement in the same column
* @param nextRow is pointer on the next cellElement in the same row * @param nextRow is pointer on the next cellElement in the same row
* *
* @see CreateCellElem to allocate one and FreeCellElement to free one * @see createCellElem to allocate one and freeCellElement to free one
*/ */
struct cellElement { struct cellElement {
@ -67,7 +67,7 @@ typedef struct cellElement cellElement;
* @return pointer on the allocated cellElement * @return pointer on the allocated cellElement
* *
*/ */
cellElement * CreateCellElem(); cellElement * createCellElem();
/** /**
@ -78,7 +78,7 @@ cellElement * CreateCellElem();
* @return int error codes * @return int error codes
* *
*/ */
int AddNextCol(cellElement* tree); int addNextCol(cellElement* tree);
/** /**
@ -89,13 +89,12 @@ int AddNextCol(cellElement* tree);
* @return int error codes * @return int error codes
* *
*/ */
int AddNextRow(cellElement* tree); int addNextRow(cellElement* tree);
/** /**
* Free the nextCol cellElement of the tree * Free the nextCol cellElement of the tree
* *
* @param tree is a pointer on an allocated cellElement * @param tree is a pointer on an allocated cellElement
* @return void
* *
*/ */
void removeNextCol(cellElement* tree); void removeNextCol(cellElement* tree);
@ -104,7 +103,6 @@ void removeNextCol(cellElement* tree);
* Free the nextRow cellElement of the tree * Free the nextRow cellElement of the tree
* *
* @param tree is a pointer on an allocated cellElement * @param tree is a pointer on an allocated cellElement
* @return void
* *
*/ */
void removeNextRow(cellElement* tree); void removeNextRow(cellElement* tree);
@ -114,10 +112,9 @@ void removeNextRow(cellElement* tree);
* Frees a cellElement and returns it * Frees a cellElement and returns it
* *
* @param element is pointer on the allocated cellElement * @param element is pointer on the allocated cellElement
* @return void
* *
*/ */
void FreeCellElement(cellElement* element); void freeCellElement(cellElement* element);
/** /**
@ -125,10 +122,10 @@ void FreeCellElement(cellElement* element);
* *
* @param tree is a pointer on an allocated cellElement * @param tree is a pointer on an allocated cellElement
* *
* @return a bool (true/false) * @return bool (true/false)
* *
*/ */
bool is_leaf(cellElement* tree); bool isLeaf(cellElement* tree);
/** /**
@ -141,7 +138,7 @@ bool is_leaf(cellElement* tree);
* @return int error codes * @return int error codes
* *
*/ */
int SetPositionIndex(cellElement* elem,int Col,int Row); int setPositionIndex(cellElement* elem,int Col,int Row);
/** /**
* Allows you to set the nextCol of the cellElement tree * Allows you to set the nextCol of the cellElement tree
@ -152,7 +149,7 @@ int SetPositionIndex(cellElement* elem,int Col,int Row);
* @return int error codes * @return int error codes
* *
*/ */
int SetNextCol(cellElement* tree,cellElement* elem); int setNextCol(cellElement* tree,cellElement* elem);
/** /**
* Allows you to set the nextRow of the cellElement elem * Allows you to set the nextRow of the cellElement elem
@ -163,14 +160,13 @@ int SetNextCol(cellElement* tree,cellElement* elem);
* @return int error codes * @return int error codes
* *
*/ */
int SetNextRow(cellElement* tree,cellElement* elem); int setNextRow(cellElement* tree,cellElement* elem);
/** /**
* A debug function that recursively prints a tree, don't use it in not tree structured cellElements (may cause endless loops) * A debug function that recursively prints a tree, don't use it in not tree structured cellElements (may cause endless loops)
* *
* @param tree a pointer on a cell element * @param tree a pointer on a cell element
* *
* @return void
*/ */
void recursivePrint(cellElement * tree); void recursivePrint(cellElement * tree);
@ -181,7 +177,7 @@ void recursivePrint(cellElement * tree);
* @param a a bool * @param a a bool
* @param b a bool * @param b a bool
* *
* @return result a or b * @return bool
*/ */
bool OR(bool a, bool b); bool OR(bool a, bool b);
@ -191,7 +187,7 @@ bool OR(bool a, bool b);
* @param a a bool * @param a a bool
* @param b a bool * @param b a bool
* *
* @return result a and b * @return bool
*/ */
bool AND(bool a, bool b); bool AND(bool a, bool b);
@ -201,7 +197,7 @@ bool AND(bool a, bool b);
* @param a a bool * @param a a bool
* @param b a bool * @param b a bool
* *
* @return result a and b * @return bool
*/ */
bool XOR(bool a, bool b); bool XOR(bool a, bool b);
@ -210,8 +206,8 @@ bool XOR(bool a, bool b);
* *
* @param x a bool * @param x a bool
* *
* @return result a bool * @return bool
*/ */
bool ErrorToFalse(bool x); bool errorToFalse(bool x);
#endif #endif

View File

@ -148,7 +148,7 @@ int popPtnList(List *list, ListElement *element){
} }
if (element->data != NULL){ if (element->data != NULL){
FreeCellElement(element->data); freeCellElement(element->data);
} }
free(element); free(element);
list->size = list->size - 1; list->size = list->size - 1;

View File

@ -87,8 +87,8 @@ bool createMatrixElem(Matrix matrix, int ColPos, int RowPos){
if (matrix.colCount <= ColPos || matrix.rowCount <= RowPos ){ if (matrix.colCount <= ColPos || matrix.rowCount <= RowPos ){
return ERROR; return ERROR;
} }
elem = CreateCellElem(); elem = createCellElem();
SetPositionIndex(elem,ColPos,RowPos); setPositionIndex(elem,ColPos,RowPos);
Row = getElementPos(matrix.rows,RowPos); Row = getElementPos(matrix.rows,RowPos);
if (Row != NULL && Row->data != NULL){ if (Row != NULL && Row->data != NULL){
@ -144,7 +144,7 @@ bool createMatrixElem(Matrix matrix, int ColPos, int RowPos){
if (error != 0){ if (error != 0){
FreeCellElement(elem); freeCellElement(elem);
return true; return true;
}else{ }else{
return false; return false;
@ -234,7 +234,7 @@ int deleteMatrixElem(Matrix matrix, int ColPos, int RowPos){
removeElementPos(matrix.cols,ColPos); removeElementPos(matrix.cols,ColPos);
} }
FreeCellElement(elem); freeCellElement(elem);
return 1; return 1;
} }
@ -516,39 +516,39 @@ bool MXOR(int n, bool bools[]){
} }
bool firstRule(Matrix m, int ColPos, int RowPos){ bool firstRule(Matrix m, int ColPos, int RowPos){
return ErrorToFalse(getCellValue(m, ColPos, RowPos)); return errorToFalse(getCellValue(m, ColPos, RowPos));
} }
bool leftRule(Matrix m, int ColPos, int RowPos){ bool leftRule(Matrix m, int ColPos, int RowPos){
return ErrorToFalse(getCellValue(m, ColPos + 1, RowPos)); return errorToFalse(getCellValue(m, ColPos + 1, RowPos));
} }
bool rightRule(Matrix m, int ColPos, int RowPos){ bool rightRule(Matrix m, int ColPos, int RowPos){
return ErrorToFalse(getCellValue(m, ColPos - 1, RowPos)); return errorToFalse(getCellValue(m, ColPos - 1, RowPos));
} }
bool topRule(Matrix m, int ColPos, int RowPos){ bool topRule(Matrix m, int ColPos, int RowPos){
return ErrorToFalse(getCellValue(m, ColPos, RowPos + 1)); return errorToFalse(getCellValue(m, ColPos, RowPos + 1));
} }
bool bottomRule(Matrix m, int ColPos, int RowPos){ bool bottomRule(Matrix m, int ColPos, int RowPos){
return ErrorToFalse(getCellValue(m, ColPos, RowPos - 1)); return errorToFalse(getCellValue(m, ColPos, RowPos - 1));
} }
bool topLeftRule(Matrix m, int ColPos, int RowPos){ bool topLeftRule(Matrix m, int ColPos, int RowPos){
return ErrorToFalse(getCellValue(m, ColPos + 1, RowPos + 1)); return errorToFalse(getCellValue(m, ColPos + 1, RowPos + 1));
} }
bool topRightRule(Matrix m, int ColPos, int RowPos){ bool topRightRule(Matrix m, int ColPos, int RowPos){
return ErrorToFalse(getCellValue(m, ColPos - 1, RowPos + 1)); return errorToFalse(getCellValue(m, ColPos - 1, RowPos + 1));
} }
bool bottomLeftRule(Matrix m, int ColPos, int RowPos){ bool bottomLeftRule(Matrix m, int ColPos, int RowPos){
return ErrorToFalse(getCellValue(m, ColPos + 1, RowPos - 1)); return errorToFalse(getCellValue(m, ColPos + 1, RowPos - 1));
} }
bool bottomRightRule(Matrix m, int ColPos, int RowPos){ bool bottomRightRule(Matrix m, int ColPos, int RowPos){
return ErrorToFalse(getCellValue(m, ColPos - 1, RowPos - 1)); return errorToFalse(getCellValue(m, ColPos - 1, RowPos - 1));
} }
bool * getFromRules(Matrix m, int ColPos, int RowPos, int n, int rules[]){ bool * getFromRules(Matrix m, int ColPos, int RowPos, int n, int rules[]){

View File

@ -87,8 +87,6 @@ BooleanMatrix randomizeBooleanMatrix(BooleanMatrix matrix);
* Free a BooleanMatrix * Free a BooleanMatrix
* *
* @param matrix a BooleanMatrix * @param matrix a BooleanMatrix
*
* @return void
*/ */
void freeBooleanMatrix(BooleanMatrix matrix); void freeBooleanMatrix(BooleanMatrix matrix);
@ -197,8 +195,6 @@ Matrix setMatrixDim(Matrix matrix,int nbCols,int nbRows);
* *
* @param matrix the Matrix * @param matrix the Matrix
* *
* @return void
*
*/ */
void printMatrix(Matrix matrix); void printMatrix(Matrix matrix);

View File

@ -37,7 +37,7 @@ int main(){
Matrix m2; Matrix m2;
BooleanMatrix bmatrix; BooleanMatrix bmatrix;
useSDL = inputYesOrNo("Do you want to use SDL library for matrix display ?"); useSDL = inputYesOrNo("Do you want to use SDL library for matrix display ( interesting for big matrix only ) ?");
printf("A random matrix will be generated\n"); printf("A random matrix will be generated\n");
printf("Enter the number of columns of this matrix\n"); printf("Enter the number of columns of this matrix\n");
col = safeNumberInput(1, 30000); col = safeNumberInput(1, 30000);

View File

@ -88,8 +88,8 @@ createMatrixElem( matrix:Matrix, ColPos:integer, RowPos:integer):bool
createMatrixElem <- ERROR /* out of bounds */ createMatrixElem <- ERROR /* out of bounds */
endif endif
elem <- CreateCellElem() elem <- createCellElem()
SetPositionIndex(elem,ColPos,RowPos) setPositionIndex(elem,ColPos,RowPos)
Row <- getElementPos(rows(matrix),RowPos) Row <- getElementPos(rows(matrix),RowPos)
if (Row != NULL AND data(Row) != NULL) if (Row != NULL AND data(Row) != NULL)
@ -156,7 +156,7 @@ createMatrixElem( matrix:Matrix, ColPos:integer, RowPos:integer):bool
if (error != 0) if (error != 0)
/* if the element already exists, free it */ /* if the element already exists, free it */
FreeCellElement(elem) freeCellElement(elem)
createMatrixElem <- true createMatrixElem <- true
else else
createMatrixElem <- false createMatrixElem <- false
@ -247,7 +247,7 @@ BEGIN
removeElementPos(cols(matrix),ColPos) removeElementPos(cols(matrix),ColPos)
endif endif
FreeCellElement(elem) freeCellElement(elem)
deleteMatrixElem <- 1 deleteMatrixElem <- 1
END END