efficient / libcuckoo

A high-performance, concurrent hash table
Other
1.62k stars 275 forks source link

simple question about update_fn #154

Open arjen-Lee1993 opened 1 year ago

arjen-Lee1993 commented 1 year ago

there are several threads concurrently writing on a same value in the hashmap,so i need "update_fn" rather than "update" to lock the value to avoid overwriting. my input function seems like void fn(mapped_type&, param1 xx, param2 xx ....)
i need more extra input params, but the update_fn may not supported. can u give me some advices to solve this problem?

manugoyal commented 1 year ago

Hi @arjen-Lee1993. update_fn can only provide mapped_type&, as that is the only information stored in the hashtable. If the additional parameters are coming from somewhere else, maybe they can be captured by the lambda you provide to update_fn? E.g.

map.update_fn(k, [&param1, &param2, &fn](mapped_type& m) { fn(m, param1, param2); });