Rename Matrix.data to Matrix.buffer

This commit is contained in:
Tobias Linz committed 2026-11-05 10:06:13 +01:00
1 parent 944de1a006
commit b496092125
2 files changed
+15 -15

No files matched your search

+14 -14
View File
@@ -10,9 +10,9 @@ Matrix createMatrix(unsigned int rows, unsigned int cols)
matrix.rows = rows;
matrix.cols = cols;
matrix.data = calloc(rows * cols, sizeof(MatrixType));
matrix.buffer = calloc(rows * cols, sizeof(MatrixType));
if (matrix.data == NULL)
if (matrix.buffer == NULL)
{
matrix.rows = 0;
matrix.cols = 0;
@@ -26,9 +26,9 @@ void clearMatrix(Matrix* matrix)
{
if (matrix != NULL)
{
free(matrix->data);
free(matrix->buffer);
matrix->data = NULL;
matrix->buffer = NULL;
matrix->rows = 0;
matrix->cols = 0;
}
@@ -38,11 +38,11 @@ void clearMatrix(Matrix* matrix)
void setMatrixAt(MatrixType value, Matrix matrix,
unsigned int rowIdx, unsigned int colIdx)
{
if (matrix.data != NULL &&
if (matrix.buffer != NULL &&
rowIdx < matrix.rows &&
colIdx < matrix.cols)
{
matrix.data[rowIdx * matrix.cols + colIdx] = value;
matrix.buffer[rowIdx * matrix.cols + colIdx] = value;
}
}
@@ -50,11 +50,11 @@ void setMatrixAt(MatrixType value, Matrix matrix,
MatrixType getMatrixAt(const Matrix matrix,
unsigned int rowIdx, unsigned int colIdx)
{
if (matrix.data != NULL &&
if (matrix.buffer != NULL &&
rowIdx < matrix.rows &&
colIdx < matrix.cols)
{
return matrix.data[rowIdx * matrix.cols + colIdx];
return matrix.buffer[rowIdx * matrix.cols + colIdx];
}
return UNDEFINED_MATRIX_VALUE;
@@ -65,15 +65,15 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
{
if (matrix1.rows != matrix2.rows ||
matrix1.cols != matrix2.cols ||
matrix1.data == NULL ||
matrix2.data == NULL)
matrix1.buffer == NULL ||
matrix2.buffer == NULL)
{
return createMatrix(0, 0);
}
Matrix result = createMatrix(matrix1.rows, matrix1.cols);
if (result.data == NULL)
if (result.buffer == NULL)
{
return result;
}
@@ -97,15 +97,15 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
{
if (matrix1.cols != matrix2.rows ||
matrix1.data == NULL ||
matrix2.data == NULL)
matrix1.buffer == NULL ||
matrix2.buffer == NULL)
{
return createMatrix(0, 0);
}
Matrix result = createMatrix(matrix1.rows, matrix2.cols);
if (result.data == NULL)
if (result.buffer == NULL)
{
return result;
}
+1 -1
View File
@@ -6,7 +6,7 @@
typedef float MatrixType;
typedef struct {
MatrixType *data;
MatrixType *buffer;
unsigned int rows;
unsigned int cols;
} Matrix;