grid_data_t->matrix_data_t, for consistency

This commit is contained in:
Miguel M 2023-04-26 15:25:56 +01:00
parent 65f0c1dc95
commit 5b41def60a
2 changed files with 8 additions and 8 deletions

View File

@ -5,7 +5,7 @@
#include <inttypes.h>
#define PRIgridDATA PRIiFAST32
typedef int_fast32_t grid_data_t;
typedef int_fast32_t matrix_data_t;
// Struct representing the input matrix.
typedef struct
@ -15,7 +15,7 @@ typedef struct
// Pointer to the buffer containing the matrix's characters.
// The data is organized as <string length> <chars...>, such that the `char`s
// are casted to `int_fast32_t` to allow for the mixed types.
grid_data_t *data_head;
matrix_data_t *data_head;
// Array of indices in `data_head` of the start of each string.
size_t *entries_head;
// Number of bytes.
@ -28,7 +28,7 @@ typedef struct
typedef struct
{
size_t data_cap;
grid_data_t *data_head;
matrix_data_t *data_head;
size_t *entries_head;
} matrix_bufs_t;

View File

@ -62,8 +62,8 @@ void DebugPrintGrid(matrix_t *matrix)
matrix_bufs_t increase_input_buffers(matrix_bufs_t bufs)
{
bufs.data_cap *= 2;
bufs.data_head = realloc(bufs.data_head, bufs.data_cap * sizeof(grid_data_t));
bufs.entries_head = realloc(bufs.entries_head, bufs.data_cap * sizeof(grid_data_t *));
bufs.data_head = realloc(bufs.data_head, bufs.data_cap * sizeof(matrix_data_t));
bufs.entries_head = realloc(bufs.entries_head, bufs.data_cap * sizeof(matrix_data_t *));
if ((bufs.data_head == NULL) || (bufs.entries_head == NULL))
{
printf(
@ -80,8 +80,8 @@ matrix_bufs_t increase_input_buffers(matrix_bufs_t bufs)
// As reallocation will happen, the updated pointers and capacity are returned
// in an updated parameters object.
matrix_bufs_t compact_buffers(matrix_t *matrix) {
matrix->data_head = realloc(matrix->data_head, matrix->data_len * sizeof(grid_data_t));
matrix->entries_head = realloc(matrix->entries_head, matrix->entries_len * sizeof(grid_data_t *));
matrix->data_head = realloc(matrix->data_head, matrix->data_len * sizeof(matrix_data_t));
matrix->entries_head = realloc(matrix->entries_head, matrix->entries_len * sizeof(matrix_data_t *));
if ((matrix->data_head == NULL) || (matrix->entries_head == NULL))
{
fprintf(
@ -109,7 +109,7 @@ matrix_t ParseMatrix(size_t row_len)
size_t data_cap = 32; // Initial value is arbitrary.
size_t data_len = 0; // Number of characters written so far.
size_t entries_len = 0; // Number of strings written so far.
grid_data_t *data_head = malloc(data_cap * sizeof(grid_data_t));
matrix_data_t *data_head = malloc(data_cap * sizeof(matrix_data_t));
size_t *entries_head = malloc(data_cap * sizeof(size_t));
_Bool spaces = 1;