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
146 stars 21 forks source link

C++ #5

Open a-yasar opened 6 years ago

a-yasar commented 6 years ago

Is there any c++ implementation of CLHT? If not how can I use it inside of a c++ program?

Thanks in advance!

trigonak commented 6 years ago

Hello. No, unfortunately I don't have a C++ implementation.

You can use CLHT in C++, the same way you do in C, e.g., https://github.com/LPD-EPFL/CLHT/blob/master/bmarks/test_mem.c Plus, you need to add the extern C def in CLHT, e.g., read https://stackoverflow.com/questions/1041866/what-is-the-effect-of-extern-c-in-c#1041880

You should also read the README file: https://github.com/LPD-EPFL/CLHT

The only thing you need to be careful about is that you cannot re-use the same value of a key/value value pair in a concurrent setting. This applies if you put as values memory pointers. As we write in the paper:

the memory allocator of the values must guarantee that the same address cannot appear twice during the lifespan of an operation (see https://infoscience.epfl.ch/record/203822/files/Tech_report_CLHT_BSTTK.pdf for more details)

a-yasar commented 6 years ago

Thanks a lot! I have another question; at some point can we clean up the hash table (i.e. remove all key-value pairs) and continue to insert new ones?

trigonak commented 6 years ago

Hmm, there isn't such an operation. It should be very easy to implement though:

  1. traverse the buckets and free all expansions -- i.e. bucket->next
  2. re-initialize all keys[i] to 0 (similar to the initialization in https://github.com/LPD-EPFL/CLHT/blob/master/src/clht_lb.c#L108)