From 1b57ebb0270f421c173203880146f9c246e5d6a1 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Thu, 20 Jul 2017 21:34:33 -0700 Subject: [PATCH] Switch vector to use size_t for its array sizes and indices. --- include/vec.h | 6 +++--- src/vec.c | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/vec.h b/include/vec.h index 0d39c2c..69268b6 100644 --- a/include/vec.h +++ b/include/vec.h @@ -18,11 +18,11 @@ struct vec_s { /** * The maximum size of the vector. */ - int capacity; + size_t capacity; /** * The current number of items in the vector. */ - int size; + size_t size; }; typedef struct vec_s vec; @@ -87,7 +87,7 @@ int vec_foreach(vec* vec, void* data, compare_func compare, foreach_func foreach * @param index the index to retreive a value from * @return pointer to the value, or, if the index is out of bounds (or there is nothing there) NULL. */ -void* vec_index(vec* vec, int index); +void* vec_index(vec* vec, size_t index); /** * Clears the vector, removing all elements from it * but not resizing it down. diff --git a/src/vec.c b/src/vec.c index b56aa14..0d769cc 100644 --- a/src/vec.c +++ b/src/vec.c @@ -44,16 +44,16 @@ libds_result vec_add(vec* v, void* data) { return result; } void vec_remove(vec* v, void* data) { - int index = 0; + size_t index = 0; void** data_array = v->data; while (index < v->size && data_array[index]) { - int search_ahead = 0; + size_t search_ahead = 0; while(data_array[index + search_ahead] == data){ search_ahead++; } if(search_ahead){ - int remaining_elements = v->size - (index + search_ahead); + size_t remaining_elements = v->size - (index + search_ahead); memmove(data_array + index, data_array + index + search_ahead, remaining_elements); v->size -= search_ahead; } @@ -62,7 +62,7 @@ void vec_remove(vec* v, void* data) { } void* vec_find(vec* v, void* data, compare_func compare) { - int index = 0; + size_t index = 0; void* found = NULL; void** data_array = v->data; while (index < v->size && found == NULL) { @@ -75,7 +75,7 @@ void* vec_find(vec* v, void* data, compare_func compare) { } int vec_foreach(vec* v, void* data, compare_func compare, foreach_func foreach, ...) { - int index = 0; + size_t index = 0; int return_code = 0; void** data_array = v->data; va_list args; @@ -90,7 +90,7 @@ int vec_foreach(vec* v, void* data, compare_func compare, foreach_func foreach, return return_code; } -void* vec_index(vec* v, int index) { +void* vec_index(vec* v, size_t index) { void* to_return = NULL; if (index < v->capacity && index >= 0) { to_return = ((void**) v->data)[index];