docs(action_list): small comments

This commit is contained in:
lisk77 2025-08-17 17:08:14 +02:00
parent e8338d011d
commit f7043cc03a
2 changed files with 5 additions and 0 deletions

View file

@ -11,12 +11,14 @@ typedef enum {
DELETE DELETE
} ActionType; } ActionType;
// Represents a deletion or insertion into the files text
typedef struct { typedef struct {
ActionType type; ActionType type;
uint64_t line_original; uint64_t line_original;
uint64_t line_changed; uint64_t line_changed;
} Action; } Action;
// Dynamic array of Actions
typedef struct { typedef struct {
Action* actions; Action* actions;
uint64_t capacity; uint64_t capacity;

View file

@ -1,5 +1,6 @@
#include "action_list.h" #include "action_list.h"
// Create a new ActionList
ActionList* new_list() { ActionList* new_list() {
ActionList* list = calloc(1, sizeof(ActionList)); ActionList* list = calloc(1, sizeof(ActionList));
list->capacity = 10; list->capacity = 10;
@ -8,6 +9,7 @@ ActionList* new_list() {
return list; return list;
} }
// Add an Action to the end of the ActionList
void add_action(ActionList* list, Action action) { void add_action(ActionList* list, Action action) {
if (list->len >= list->capacity) { if (list->len >= list->capacity) {
list->capacity *= 2; list->capacity *= 2;
@ -21,6 +23,7 @@ void add_action(ActionList* list, Action action) {
list->actions[list->len++] = action; list->actions[list->len++] = action;
} }
// Concatenate two ActionLists. Modifies list1 in place
void append_list(ActionList* list1, ActionList* list2) { void append_list(ActionList* list1, ActionList* list2) {
uint64_t available_space = list1->capacity - list1->len; uint64_t available_space = list1->capacity - list1->len;
if (available_space < list2->len) { if (available_space < list2->len) {