hashmap icon indicating copy to clipboard operation
hashmap copied to clipboard

modifying key interface requirements

Open fancong5201314 opened this issue 2 years ago • 4 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.

fancong5201314 avatar Jan 26 '22 02:01 fancong5201314

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);

DavidLeeds avatar Feb 05 '22 04:02 DavidLeeds

I'll try it first, thanks.

fancong5201314 avatar Feb 11 '22 09:02 fancong5201314

Where are the two functions hashmap_update and hashmap_base_update implemented?

fancong5201314 avatar Feb 11 '22 09:02 fancong5201314

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

fancong5201314 avatar Feb 11 '22 09:02 fancong5201314