From 32de4e478fc332b35de2906f0030c217c3b4eba2 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Fri, 21 Jul 2017 17:45:04 -0700 Subject: [PATCH] Switch sparse set to use unsigned size_t. --- include/sprs.h | 8 ++++---- src/sprs.c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/sprs.h b/include/sprs.h index 59582b0..c7b1714 100644 --- a/include/sprs.h +++ b/include/sprs.h @@ -58,7 +58,7 @@ struct sprs_s { * The dense array. * This is a pointer so that an array of a certain size can be allocated as needed. */ - int* dense; + size_t* dense; /** * The sparse array. * This is a pointer so that an array of a certain size can be allocated as needed. @@ -94,14 +94,14 @@ void sprs_free(sprs* sprs); * @param index the index at which to store the value * @param data the value to store. */ -void sprs_put(sprs* sprs, int index, void* data); +void sprs_put(sprs* sprs, size_t index, void* data); /** * Checks if the sparse set contains data under a given index. * @param sprs the sparse set to check. * @param index the index for which to check. * @return 1 if the index exists, 0 if not. */ -int sprs_contains(sprs* sprs, int index); +int sprs_contains(sprs* sprs, size_t index); /** * Gets the value stored under the given sparse set index. * This will check for whether the index is in the sparse set first, @@ -113,7 +113,7 @@ int sprs_contains(sprs* sprs, int index); * @param index the index from under which to retrieve the value. * @return the value stored under the index, or NULL if there is nothing there. */ -void* sprs_get(sprs* sprs, int index); +void* sprs_get(sprs* sprs, size_t index); /** * Runs through every element in the sparse set, and compares it against the diff --git a/src/sprs.c b/src/sprs.c index 305e01a..99009c6 100644 --- a/src/sprs.c +++ b/src/sprs.c @@ -30,17 +30,17 @@ void sprs_free(sprs* sprs){ sprs->dense = NULL; sprs->sparse = NULL; } -void sprs_put(sprs* sprs, int index, void* data){ +void sprs_put(sprs* sprs, size_t index, void* data){ if(index < sprs->capacity && sprs->size < sprs->capacity){ sprs->dense[sprs->size++] = index; sprs->sparse[index].index = sprs->size - 1; sprs->sparse[index].data = data; } } -int sprs_contains(sprs* sprs, int index){ - return index >= 0 && sprs->sparse[index].index < sprs->size && sprs->dense[sprs->sparse[index].index] == index; +int sprs_contains(sprs* sprs, size_t index){ + return sprs->sparse[index].index < sprs->size && sprs->dense[sprs->sparse[index].index] == index; } -void* sprs_get(sprs* sprs, int index){ +void* sprs_get(sprs* sprs, size_t index){ void* data = NULL; if(sprs_contains(sprs, index)){ data = sprs->sparse[index].data;