From 316d2daf89156d12ab8e45bd4f2b6f5e74c07661 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Mon, 5 Feb 2018 13:08:21 -0800 Subject: [PATCH] Check put for duplicate pieces of data. --- src/sprs.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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){