diff --git a/graph.c b/graph.c index 949ca26..3123fc8 100644 --- a/graph.c +++ b/graph.c @@ -2,12 +2,12 @@ #include #include -void random_adjacency(const uint64_t row_length, const uint64_t column_length, uint64_t matrix[row_length][column_length]) { +void random_adjacency(const uint64_t vertex_count, uint64_t matrix[vertex_count][vertex_count]) { srand(time(NULL)); - for (uint8_t row_index=0; row_index < row_length; row_index++) { - for (uint8_t column_index=0; column_index < column_length; column_index++) { + for (uint8_t row_index=0; row_index < vertex_count; row_index++) { + for (uint8_t column_index=0; column_index < vertex_count; column_index++) { if(column_index == row_index) { matrix[row_index][column_index] = 0; continue; @@ -16,3 +16,7 @@ void random_adjacency(const uint64_t row_length, const uint64_t column_length, u } } } + +int calculate_eccentricities() { + return 0; +} diff --git a/graph.h b/graph.h index fe895c4..563e491 100644 --- a/graph.h +++ b/graph.h @@ -3,8 +3,7 @@ #include -void random_adjacency(const uint64_t row_length, - const uint64_t column_length, - uint64_t matrix[row_length][column_length]); +void random_adjacency(const uint64_t vertex_count, + uint64_t matrix[vertex_count][vertex_count]); #endif diff --git a/main.c b/main.c index ffc2a65..f9dec18 100644 --- a/main.c +++ b/main.c @@ -20,8 +20,8 @@ void benchmark() { clock_t start_time; for (uint64_t i = 0; i < iterations; i++) { - random_adjacency(row_length1, column_length1, matrix1); - random_adjacency(row_length2, column_length2, matrix2); + random_adjacency(row_length1, matrix1); + random_adjacency(row_length2, matrix2); start_time = clock(); @@ -43,18 +43,22 @@ void test() { read_csv("csv/graph.csv", row_length1, column_length1, matrix1); - // print_matrix(row_length1, column_length1, matrix1); + printf("G:\n"); + print_matrix(row_length1, column_length1, matrix1); + printf("\n"); - // uint64_t new_matrix[row_length1][column_length1]; - // - // matrix_multiply_basic(row_length1, column_length1, matrix1, - // row_length1, column_length1, matrix1, - // new_matrix); - // - // print_matrix(row_length1, column_length1, new_matrix); + uint64_t new_matrix[row_length1][column_length1]; + + matrix_multiply_basic(row_length1, column_length1, matrix1, + row_length1, column_length1, matrix1, + new_matrix); + + printf("G²:\n"); + print_matrix(row_length1, column_length1, new_matrix); + printf("\n"); } int main(void) { - test(); - // benchmark(); + // test(); + benchmark(); } diff --git a/matrix.c b/matrix.c index 7e35a7b..11fa904 100644 --- a/matrix.c +++ b/matrix.c @@ -3,6 +3,7 @@ #include #include #include +#include void print_matrix(const uint64_t row_length, const uint64_t column_length, const uint64_t matrix[row_length][column_length]) { for (uint64_t column_index=0; column_index < column_length; column_index++) { @@ -39,49 +40,36 @@ int matrix_multiply_basic(const uint64_t row_length1, const uint64_t column_leng int read_csv(const char *file_name, const uint64_t row_length, const uint64_t column_length, uint64_t output_matrix[row_length][column_length]) { FILE *file_ptr; uint32_t bufsize = row_length*2; // have to account for delimiters - char file_line[bufsize]; + char buffer[bufsize]; + char *value, *file_line; + uint64_t row_index = 0, column_index = 0; file_ptr = fopen(file_name, "r"); if (file_ptr == NULL) { printf("Unable to open csv\n"); return 1; } - for (uint64_t column_index = 0; column_index < column_length; column_index++) { - printf("row_index: %lu\n", column_index); - if (fgets(file_line, bufsize, file_ptr) == NULL) { - break; - } - char *bruh = strtok(file_line, ";,"); + while ((file_line = fgets(buffer, bufsize, file_ptr)) != NULL) { + // This shit is just needed and I dont know why + file_line[strcspn(file_line, "\n")] = 0; + value = strtok(file_line, ";,"); - for(uint64_t row_index = 0; row_index < row_length; row_index++) { - if (bruh == NULL) { - printf("Fuck You!!!"); - continue; - } - printf("column_index: %lu, bruh: %lu\n", row_index, strtoul(bruh, NULL, 0)); - bruh = strtok(NULL, ";,"); + // for some reason there are two NULLs at the end of a line + // and I dont wanna increment the column_index + if (value == NULL) { + continue; } - printf("\n"); + + while (value != NULL) { + output_matrix[row_index++][column_index] = strtoul(value, NULL, 0); + value = strtok(NULL, ";,"); + } + + row_index = 0; + column_index++; } - // uint64_t row_index = 0; - // uint64_t column_index = 0; - // while (fgets(file_line, bufsize, file_ptr)) { - // row_index = 0; - // char *bruh = strtok(file_line, ";,"); - // - // while (bruh) { - // output_matrix[row_index][column_index] = strtoul(bruh, NULL, 0); - // printf("column_index: %lu, bruh: %s\n", row_index, bruh); - // bruh = strtok(NULL, ";,"); - // row_index++; - // } - // - // printf("row_index: %lu\n", column_index); - // column_index++; - // } - fclose(file_ptr); return 0;