Check put for duplicate pieces of data.
This commit is contained in:
parent
276d38a292
commit
316d2daf89
10
src/sprs.c
10
src/sprs.c
|
@ -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){
|
||||||
sprs->dense[sprs->size++] = index;
|
if(!sprs_contains(sprs, index)){
|
||||||
sprs->sparse[index].index = sprs->size - 1;
|
sprs->dense[sprs->size++] = index;
|
||||||
sprs->sparse[index].data = data;
|
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){
|
int sprs_contains(sprs* sprs, size_t index){
|
||||||
|
|
Loading…
Reference in New Issue
Block a user