let h_hashtable_merge's combine function decide what to do on NULL dst values
This commit is contained in:
parent
e4984fe60c
commit
3047fd223b
2 changed files with 5 additions and 9 deletions
|
|
@ -200,7 +200,7 @@ void h_hashtable_update(HHashTable *dst, const HHashTable *src) {
|
|||
}
|
||||
}
|
||||
|
||||
void h_hashtable_merge(void *(*combine)(void *v1, void *v2),
|
||||
void h_hashtable_merge(void *(*combine)(void *v1, const void *v2),
|
||||
HHashTable *dst, const HHashTable *src) {
|
||||
size_t i;
|
||||
HHashTableEntry *hte;
|
||||
|
|
@ -208,13 +208,9 @@ void h_hashtable_merge(void *(*combine)(void *v1, void *v2),
|
|||
for(hte = &src->contents[i]; hte; hte = hte->next) {
|
||||
if(hte->key == NULL)
|
||||
continue;
|
||||
void *oldvalue = h_hashtable_get(dst, hte->key);
|
||||
void *newvalue;
|
||||
if(oldvalue)
|
||||
newvalue = combine(oldvalue, hte->value);
|
||||
else
|
||||
newvalue = hte->value;
|
||||
h_hashtable_put(dst, hte->key, newvalue);
|
||||
void *dstvalue = h_hashtable_get(dst, hte->key);
|
||||
void *srcvalue = hte->value;
|
||||
h_hashtable_put(dst, hte->key, combine(dstvalue, srcvalue));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -255,7 +255,7 @@ HHashTable* h_hashtable_new(HArena *arena, HEqualFunc equalFunc, HHashFunc hashF
|
|||
void* h_hashtable_get(const HHashTable* ht, const void* key);
|
||||
void h_hashtable_put(HHashTable* ht, const void* key, void* value);
|
||||
void h_hashtable_update(HHashTable* dst, const HHashTable *src);
|
||||
void h_hashtable_merge(void *(*combine)(void *v1, void *v2),
|
||||
void h_hashtable_merge(void *(*combine)(void *v1, const void *v2),
|
||||
HHashTable *dst, const HHashTable *src);
|
||||
int h_hashtable_present(const HHashTable* ht, const void* key);
|
||||
void h_hashtable_del(HHashTable* ht, const void* key);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue