Switch sparse set to use unsigned size_t.

This commit is contained in:
Danila Fedorin 2017-07-21 17:45:04 -07:00
parent 1d037dd31e
commit 32de4e478f
2 changed files with 8 additions and 8 deletions

View File

@ -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

View File

@ -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;