efficient / libcuckoo

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

Implementation of operator= with locked table #72

Closed krsvital closed 7 years ago

krsvital commented 7 years ago

my example:

typedef cockoohash_map<std::string, int> cockoo_map; std::map<std::string, int> my_map;

cockoo_map tbl;

auto lt = tbl.lock_table(); my_map = lt; //its not working, no implementation of operator= lt.unlock();

can you add support this? somtimes needs to work with unlocked tables, becouse if its locked CPU time is greatly increased.

krsvital commented 7 years ago

or can you do implementation itarerators on unlocked table for reading?

dnbaker commented 7 years ago

You just have to access through the locked table. It provides an interface for querying but not modifying, which makes it threadsafe without the reduction in performance.

The locked_table.find functions are here, while begin, end, cbegin, and cend are here.

manugoyal commented 7 years ago

@dnbh is correct. The reason iteration is done through the locked table, is that iterators can be invalidated by other concurrent operations on the table, such as inserts and deletions. The interface for locked_table actually emulates exactly the interface for std::unordered_map, so iteration should work exactly the same way as it does in STL.

Regarding support for operator=, we currently only support moving the locked table to another locked_table object, and not copying, or copying into a different type. Your best bet for copying the table data into an instance of std::map is to iterate through the locked_table, and insert every key-value pair individually. There really wouldn't be a more efficient way to do this anyways.