LPD-EPFL / CLHT

CLHT is a very fast and scalable (lock-based and lock-free) concurrent hash table with cache-line sized buckets.
http://lpd.epfl.ch/site/ascylib
Other
148 stars 21 forks source link

clht_lf_res.c hash table have collision detection? #4

Open jarwin123 opened 6 years ago

jarwin123 commented 6 years ago

i read some clht_lf_res.c code, i cannot found some collision code, if key value that hash function calculate is the same .

trigonak commented 6 years ago

clht_lf_res, do to the snapshot_t object, does not have a way to handle collisions. Instead, the hash table is resized to potentially make space. If you don't have a good reason, I recommend using the lock-based version of CLHT.

jarwin123 commented 6 years ago

if i need save struct key{char url[128]}, struct value{char url[128],int exist} into clht_lb_link hash table, the type of clht_addr_t is uintptr_t , i use murmur hash function calculate struct key{char url[128]} get a key value , and then i call clht_put(clht_t* h, clht_addr_t key, clht_val_t val) into hash table, if key value is the same but the url is not same, clht_lb_link cannot insert the second value by clht_lb_link's code. As far as I know, hashtable should have the most basic collision handling。i use clht in multithreads situation,some threads put value into hashtables,and some threads will iteration hashtables and maybe modify values(struct value{char url[128],int exist} the exist value), because the url is not same but the key maybe the same, i need insert hashtable both.

trigonak commented 6 years ago

struct key{char url[128]}, struct value{char url[128],int exist}

Currently, as you mentioned, CLHT supports 8-byte keys. You would need to slightly modify CLHT to use larger keys. The approach is similar to the way you already use CLHT, however, you need to make the key comparison in two steps:

  1. Compare the hashes; and
  2. Only if the hashes match, compare the actual keys.

To be able to do this comparison, you need to store all three: key_hash, key_pointer, and ofc val. You can change the put operation accordingly, to do the insertion if the keys are not fully matched.

Let me know if you will try to create this version yourself. Otherwise, whenever I find some time, I can create a first draft version for you.