add h_hashtable_merge function
This commit is contained in:
parent
194ddee90b
commit
e4d0b636dd
2 changed files with 21 additions and 0 deletions
|
|
@ -180,6 +180,25 @@ void h_hashtable_update(HHashTable *dst, const HHashTable *src) {
|
|||
}
|
||||
}
|
||||
|
||||
void h_hashtable_merge(void *(*combine)(void *v1, void *v2),
|
||||
HHashTable *dst, const HHashTable *src) {
|
||||
size_t i;
|
||||
HHashTableEntry *hte;
|
||||
for(i=0; i < src->capacity; i++) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int h_hashtable_present(const HHashTable* ht, const void* key) {
|
||||
HHashValue hashval = ht->hashFunc(key);
|
||||
#ifdef CONSISTENCY_CHECK
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue