DavidLeeds / hashmap

Templated type-safe hashmap implementation in C using open addressing and linear probing for collision resolution.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

modifying key interface requirements

fancong5201314 opened this issue · comments

Can you provide an interface "hashmap_set" for modifying the key, the function is to add the key if it does not exist, and modify it if it exists. Thank you so much.

Hi @fancong5201314,

Would this satisfy your needs?

int hashmap_base_update(struct hashmap_base *hb, const void *key, void *data, void **original_data);

This would be used like this:

int r;
struct my_data *new_data = /* new data */;
struct my_data *old_data;

r = hashmap_update(&my_map, "MyKey", new_data, &old_data);
if (r < 0) {
    // Error
}

free(old_data);

I'll try it first, thanks.

Where are the two functions hashmap_update and hashmap_base_update implemented?

I use this to replace the redundant map table of C++. Now hashmap supports adding, deleting, and querying, but it has not been modified.