diff --git a/src/sprs.c b/src/sprs.c index 99009c6..5939e0c 100644 --- a/src/sprs.c +++ b/src/sprs.c @@ -32,9 +32,13 @@ void sprs_free(sprs* sprs){ } 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; + if(!sprs_contains(sprs, index)){ + sprs->dense[sprs->size++] = index; + sprs->sparse[index].index = sprs->size - 1; + sprs->sparse[index].data = data; + } else { + sprs->sparse[index].data = data; + } } } int sprs_contains(sprs* sprs, size_t index){