Check put for duplicate pieces of data.

This commit is contained in:
Danila Fedorin 2018-02-05 13:08:21 -08:00
parent 276d38a292
commit 316d2daf89

View File

@ -32,9 +32,13 @@ void sprs_free(sprs* sprs){
} }
void sprs_put(sprs* sprs, size_t index, void* data){ void sprs_put(sprs* sprs, size_t index, void* data){
if(index < sprs->capacity && sprs->size < sprs->capacity){ if(index < sprs->capacity && sprs->size < sprs->capacity){
if(!sprs_contains(sprs, index)){
sprs->dense[sprs->size++] = index; sprs->dense[sprs->size++] = index;
sprs->sparse[index].index = sprs->size - 1; sprs->sparse[index].index = sprs->size - 1;
sprs->sparse[index].data = data; sprs->sparse[index].data = data;
} else {
sprs->sparse[index].data = data;
}
} }
} }
int sprs_contains(sprs* sprs, size_t index){ int sprs_contains(sprs* sprs, size_t index){