Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clht_lf_res.c hash table have collision detection? #4

Open
jarwin123 opened this issue Nov 10, 2017 · 3 comments
Open

clht_lf_res.c hash table have collision detection? #4

jarwin123 opened this issue Nov 10, 2017 · 3 comments

Comments

@jarwin123
Copy link

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
Copy link
Member

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
Copy link
Author

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
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants