From 02a2640ac858df5d1ae00d006bdb02ff842c3e0c Mon Sep 17 00:00:00 2001 From: Naej Date: Sun, 1 Jan 2017 23:51:26 +0100 Subject: [PATCH 1/2] replace == by = --- report.md | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/report.md b/report.md index 9872337..63c7a93 100644 --- a/report.md +++ b/report.md @@ -32,7 +32,7 @@ BEGIN getCellValue <- ERROR endif - if (findMatrixElem( matrix , ColPos , RowPos ) == NULL) + if (findMatrixElem( matrix , ColPos , RowPos ) = NULL) getCellValue <- false endif @@ -45,7 +45,7 @@ BEGIN elem:*cellElement <- NULL Row <- getElementPos(rows(matrix),RowPos) - if (Row == NULL) + if (Row = NULL) findMatrixElem <- NULL endif @@ -63,7 +63,7 @@ END ```C setCellValue(matrix:Matrix, ColPos:integer, RowPos:integer,value:bool):bool BEGIN - if (value == true) + if (value = true) setCellValue <- createMatrixElem(matrix,ColPos,RowPos) else if ( deleteMatrixElem(matrix,ColPos,RowPos) >= 0 ) @@ -93,7 +93,7 @@ createMatrixElem( matrix:Matrix, ColPos:integer, RowPos:integer):bool Row <- getElementPos(rows(matrix),RowPos) if (Row != NULL AND data(Row) != NULL) - if (colIndex(data(Row)) == ColPos) + if (colIndex(data(Row)) = ColPos) error ++ else if (colIndex(data(Row)) > ColPos) @@ -107,7 +107,7 @@ createMatrixElem( matrix:Matrix, ColPos:integer, RowPos:integer):bool tmp <- nextCol(tmp) endwhile - if ( nextCol(tmp) == NULL OR colIndex(nextCol(tmp)) > ColPos) + if ( nextCol(tmp) = NULL OR colIndex(nextCol(tmp)) > ColPos) nextCol(elem) <- nextCol(tmp) nextCol(tmp) <- elem else @@ -123,7 +123,7 @@ createMatrixElem( matrix:Matrix, ColPos:integer, RowPos:integer):bool Col <- getElementPos(cols(matrix),ColPos) if (Col != NULL AND data(Col) != NULL) - if (rowIndex(data(Col)) == RowPos) + if (rowIndex(data(Col)) = RowPos) error ++ else if (rowIndex(data(Col)) > RowPos) @@ -136,7 +136,7 @@ createMatrixElem( matrix:Matrix, ColPos:integer, RowPos:integer):bool tmp <- nextRow(tmp) endwhile - if (nextRow(tmp) == NULL OR rowIndex(nextRow(tmp)) > RowPos) + if (nextRow(tmp) = NULL OR rowIndex(nextRow(tmp)) > RowPos) nexRow(elem) <- nextRow(tmp) newRow(tmp) <- elem else @@ -168,21 +168,21 @@ BEGIN Col : *ListElement <- NULL elem <- findMatrixElem(matrix,ColPos,RowPos) - if (elem == NULL) + if (elem = NULL) deleteMatrixElem <- 0 endif Row <- getElementPos(rows(matrix),RowPos) - if (Row == NULL) + if (Row = NULL) deleteMatrixElem <- -1 endif - if (data(Row) == NULL) + if (data(Row) = NULL) removeElementPos(rows(matrix),RowPos) deleteMatrixElem <- -1 endif - if (colIndex(data(Row)) == ColPos) + if (colIndex(data(Row)) = ColPos) data(Row) <- nextCol(elem) else tmp <- data(Row) @@ -197,21 +197,21 @@ BEGIN endif - if (data(Row) == NULL) + if (data(Row) = NULL) removeElementPos(rows(matrix),RowPos) endif Col <- getElementPos(cols(matrix),ColPos) - if (Col == NULL) + if (Col = NULL) deleteMatrixElem <- -2 endif - if (data(Col) == NULL) + if (data(Col) = NULL) removeElementPos(cols(matrix),ColPos) deleteMatrixElem <- -1 endif - if (rowIndex(data(Col)) == RowPos) + if (rowIndex(data(Col)) = RowPos) data(Col) <- nextRow(elem) else tmp <- data(Col) @@ -225,7 +225,7 @@ BEGIN endif - if (data(Col) == NULL) + if (data(Col) = NULL) removeElementPos(cols(matrix),ColPos) endif From d408036d04d99380b3d27e90dbd273d7f612a232 Mon Sep 17 00:00:00 2001 From: Naej Date: Mon, 2 Jan 2017 00:29:15 +0100 Subject: [PATCH 2/2] commented algos --- report.md | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/report.md b/report.md index 63c7a93..0d2c8e7 100644 --- a/report.md +++ b/report.md @@ -60,6 +60,7 @@ END ``` *setCellValue* is a simple function based on *createMatrixElem* and *deleteMatrixElement* : + ```C setCellValue(matrix:Matrix, ColPos:integer, RowPos:integer,value:bool):bool BEGIN @@ -84,7 +85,7 @@ createMatrixElem( matrix:Matrix, ColPos:integer, RowPos:integer):bool tmp: *cellElement<- NULL if (colCount(matrix) <= ColPos OR rowCount(matrix) <= RowPos ) - createMatrixElem <- ERROR + createMatrixElem <- ERROR /* out of bounds */ endif elem <- CreateCellElem() @@ -94,7 +95,7 @@ createMatrixElem( matrix:Matrix, ColPos:integer, RowPos:integer):bool if (Row != NULL AND data(Row) != NULL) if (colIndex(data(Row)) = ColPos) - error ++ + error ++ /* the element already exists */ else if (colIndex(data(Row)) > ColPos) nextCol(elem) <- data(Row) @@ -102,7 +103,7 @@ createMatrixElem( matrix:Matrix, ColPos:integer, RowPos:integer):bool endif else tmp <- data(Row) - + /* searching the previous element */ while ( nextCol(tmp) != NULL AND nextCol(colIndex(tmp)) < ColPos) do tmp <- nextCol(tmp) endwhile @@ -111,11 +112,12 @@ createMatrixElem( matrix:Matrix, ColPos:integer, RowPos:integer):bool nextCol(elem) <- nextCol(tmp) nextCol(tmp) <- elem else - error ++ + error ++ /* the element already exists */ endif endif else + /* if the list is empty */ push(rows(matrix),elem) pos(tail(rows(matrix))) <- RowPos endif @@ -124,7 +126,7 @@ createMatrixElem( matrix:Matrix, ColPos:integer, RowPos:integer):bool if (Col != NULL AND data(Col) != NULL) if (rowIndex(data(Col)) = RowPos) - error ++ + error ++ /* the element already exists */ else if (rowIndex(data(Col)) > RowPos) nextRow(elem) <- data(Col) @@ -132,6 +134,7 @@ createMatrixElem( matrix:Matrix, ColPos:integer, RowPos:integer):bool endif else tmp <- data(Col) + /* searching the previous element */ while (nextRow(tmp) != NULL AND rowIndex(nextRow(tmp)) < RowPos) do tmp <- nextRow(tmp) endwhile @@ -140,17 +143,19 @@ createMatrixElem( matrix:Matrix, ColPos:integer, RowPos:integer):bool nexRow(elem) <- nextRow(tmp) newRow(tmp) <- elem else - error ++ + error ++ /* the element already exists */ endif endif else + /* if the list is empty */ push(cols(matrix),elem) pos(tail(cols(matrix))) <- ColPos endif if (error != 0) + /* if the element already exists, free it */ FreeCellElement(elem) createMatrixElem <- true else @@ -169,63 +174,76 @@ BEGIN elem <- findMatrixElem(matrix,ColPos,RowPos) if (elem = NULL) + /* if the element does not exists */ deleteMatrixElem <- 0 endif Row <- getElementPos(rows(matrix),RowPos) if (Row = NULL) + /* this shouldn't happend */ deleteMatrixElem <- -1 endif if (data(Row) = NULL) + /* this shouldn't happend too */ removeElementPos(rows(matrix),RowPos) deleteMatrixElem <- -1 endif if (colIndex(data(Row)) = ColPos) + /* the element is the first element */ data(Row) <- nextCol(elem) else tmp <- data(Row) - + /* finding prefious element */ while (nextCol(tmp) != NULL AND nextCol(tmp) != elem) do tmp <- nextCol(tmp) endwhile if (nextCol(tmp) != NULL) + /* linking correctly the previous element */ nextCol(tmp) <- nextCol(elem) endif endif if (data(Row) = NULL) + /* if the row is empty now we delete it to save memory */ removeElementPos(rows(matrix),RowPos) endif Col <- getElementPos(cols(matrix),ColPos) if (Col = NULL) + /* this shouldn't happend */ deleteMatrixElem <- -2 endif if (data(Col) = NULL) + /* this shouldn't happend too */ removeElementPos(cols(matrix),ColPos) deleteMatrixElem <- -1 endif + if (rowIndex(data(Col)) = RowPos) + /* the element is the first element */ data(Col) <- nextRow(elem) else tmp <- data(Col) + /* finding prefious element */ while (nextRow(tmp) != NULL AND nextRow(tmp) != elem) do tmp <- nextRow(tmp) endwhile if (nextRow(tmp) != NULL) + /* linking correctly the previous element */ nextRow(tmp) <- nextRow(elem) endif endif if (data(Col) = NULL) + /* if the col is empty now we delete it to save memory */ removeElementPos(cols(matrix),ColPos) endif @@ -277,7 +295,7 @@ Here are the algorithm of the function *applyRules* and all the one related to i ```C applyRules ( matrix:Matrix, Rules:integer, N:integer):Matrix BEGIN - RulesMatrix :integer[9] + RulesMatrix :integer[9] /* the size is the number of fundamental rules */ i:integer <- 0 power:integer <- 2 sum:integer <- 0 @@ -290,6 +308,7 @@ BEGIN applyRules <- matrix endif + /* decompotition of the rule in basic rules */ while(power <= 512) do RulesMatrix[i] <- Rules%power - sum @@ -303,6 +322,8 @@ BEGIN endwhile + /* application of the rule */ + tempMatrix1 <- matrixFromRules(matrix, i, RulesMatrix) for j from 0 to N do @@ -315,8 +336,6 @@ BEGIN applyRules <- tempMatrix1 END - - ``` # Conclusion \ No newline at end of file