done
This commit is contained in:
+38
-27
@@ -21,6 +21,7 @@ typedef struct {
|
||||
} StateArray;
|
||||
|
||||
StateArray arr_init(int capacity) {
|
||||
// creates a new array to store the state
|
||||
StateArray arr;
|
||||
arr.size = capacity;
|
||||
arr.capacity = capacity;
|
||||
@@ -32,39 +33,49 @@ StateArray arr_init(int capacity) {
|
||||
return arr;
|
||||
}
|
||||
|
||||
void arr_print(StateArray* self) {
|
||||
FILE* log_file = fopen("diff.txt", "w");
|
||||
if (log_file == NULL) {
|
||||
fprintf(stderr, "Error: Could not open log file\n");
|
||||
}
|
||||
// prints the state of the array into a file
|
||||
// this method is for debug purposes!
|
||||
// void arr_print(StateArray* self) {
|
||||
// FILE* log_file = fopen("diff.txt", "w");
|
||||
// if (log_file == NULL) {
|
||||
// fprintf(stderr, "Error: Could not open log file\n");
|
||||
// }
|
||||
|
||||
for (int i = 0; i < self->size; i++) {
|
||||
switch (self->data[i]) {
|
||||
case UNMODIFIED:
|
||||
fwrite("UNMODIFIED\n", sizeof(char), strlen("UNMODIFIED\n"), log_file);
|
||||
break;
|
||||
case MODIFIED:
|
||||
fwrite("MODIFIED\n", sizeof(char), strlen("MODIFIED\n"), log_file);
|
||||
break;
|
||||
case ADDED:
|
||||
fwrite("ADDED\n", sizeof(char), strlen("ADDED\n"), log_file);
|
||||
break;
|
||||
case REMOVED:
|
||||
fwrite("REMOVED\n", sizeof(char), strlen("REMOVED\n"), log_file);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// for (int i = 0; i < self->size; i++) {
|
||||
// switch (self->data[i]) {
|
||||
// case UNMODIFIED:
|
||||
// fwrite("UNMODIFIED\n", sizeof(char), strlen("UNMODIFIED\n"), log_file);
|
||||
// break;
|
||||
// case MODIFIED:
|
||||
// fwrite("MODIFIED\n", sizeof(char), strlen("MODIFIED\n"), log_file);
|
||||
// break;
|
||||
// case ADDED:
|
||||
// fwrite("ADDED\n", sizeof(char), strlen("ADDED\n"), log_file);
|
||||
// break;
|
||||
// case REMOVED:
|
||||
// fwrite("REMOVED\n", sizeof(char), strlen("REMOVED\n"), log_file);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
fclose(log_file);
|
||||
}
|
||||
// fclose(log_file);
|
||||
// }
|
||||
|
||||
// calculates an offset to use for indexing into the state relative to the buffer.
|
||||
// this is because some elements might not be aligned due to needing to insert the "REMOVED" element in some cases.
|
||||
int arr_added_or_removed_before(StateArray* self, int index) {
|
||||
int count = 0;
|
||||
for (int i = 0; i < index; i++) {
|
||||
if (self->data[i] == ADDED || self->data[i] == REMOVED) {
|
||||
if (self->data[i] == REMOVED) {
|
||||
index++;
|
||||
}
|
||||
// if (self->data[i] == ADDED || self->data[i] == REMOVED) {
|
||||
// if (self->data[i] == REMOVED) {
|
||||
// // every time a "REMOVED" element is found, we increase the index by 1
|
||||
// index++;
|
||||
// }
|
||||
// count++;
|
||||
// }
|
||||
if (self->data[i] == REMOVED) {
|
||||
// every time a "REMOVED" element is found, we increase the index by 1
|
||||
index++;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user