diff options
| author | Mikkel Thestrup <mithe24@student.sdu.dk> | 2025-12-04 18:51:54 +0100 |
|---|---|---|
| committer | Mikkel Thestrup <mithe24@student.sdu.dk> | 2025-12-04 18:51:54 +0100 |
| commit | 16527faeedfd8d3a27d3ac505d882f84bd34ed67 (patch) | |
| tree | 7cc110d89f728ebf6c2d2f6597b27bf2de702647 | |
| parent | 5e27a37c6ce0c8b98951b3ecc9308961b47b955a (diff) | |
| download | cycle-detector-16527faeedfd8d3a27d3ac505d882f84bd34ed67.tar.gz cycle-detector-16527faeedfd8d3a27d3ac505d882f84bd34ed67.zip | |
Prefix macros to avoid macro name collisions. <3 header files
| -rw-r--r-- | src/vector.c | 6 | ||||
| -rw-r--r-- | src/vector.h | 8 |
2 files changed, 7 insertions, 7 deletions
diff --git a/src/vector.c b/src/vector.c index b777487..40dc92c 100644 --- a/src/vector.c +++ b/src/vector.c @@ -8,14 +8,14 @@ Vector *vector_new(void) { if (!v) return NULL; - v->data = (void **)malloc(INITAL_CAPACITY * sizeof(void *)); + v->data = (void **)malloc(VECTOR_INITIAL_CAPACITY * sizeof(void *)); if (!v->data) { free(v); return NULL; } v->size = 0; - v->capacity = INITAL_CAPACITY; + v->capacity = VECTOR_INITIAL_CAPACITY; return v; } @@ -26,7 +26,7 @@ void vector_delete(Vector *v) { void vector_push(Vector *v, void *element) { if (v->size >= v->capacity) - vector_resize(v, v->capacity * GROWTH_FACTOR); + vector_resize(v, v->capacity * VECTOR_GROWTH_FACTOR); v->data[v->size++] = element; } diff --git a/src/vector.h b/src/vector.h index 271fcff..7320442 100644 --- a/src/vector.h +++ b/src/vector.h @@ -13,22 +13,22 @@ #include <stddef.h> /** - * @def INITAL_CAPACITY + * @def VECTOR_INITIAL_CAPACITY * @brief Initial capacity of a newly created vector. * @details The vector will be allocated with space for this many elements * when first created. This value is chosen to balance memory usage * and the number of early reallocations. */ -#define INITAL_CAPACITY 10 +#define VECTOR_INITIAL_CAPACITY 10 /** - * @def GROWTH_FACTOR + * @def VECTOR_GROWTH_FACTOR * @brief Multiplicative factor for vector capacity growth. * @details When the vector reaches capacity and needs to grow, the new * capacity is calculated as (current_capacity * GROWTH_FACTOR). * A factor of 2 provides good amortized performance. */ -#define GROWTH_FACTOR 2 +#define VECTOR_GROWTH_FACTOR 2 /** * @struct Vector |