Closed toojays closed 8 years ago
I added support for this feature in a new branch 75ad4e0. Since it requires compiling with C++14, while everything else compiles with C++11, I haven't yet bothered to incorporate the unit test into the build system, which I want to do before merging into master. Until then, though, would you mind trying this branch out and seeing if it works for your purposes?
Merged into master.
Thanks Manu. It might be a little while before I can test this. :(
Is the only reason you need C++14 because you're using std::equal_to in your test program? I guess I'll find out when I try it, but I'm looking to use this in a C++11 project. Hopefully that's just a matter of defining an appropriate functor, not something I need new language features for.
Yeah I'm using std::equal_to, but with a void overload that was added in c++14 and not supported in c++11. The document you linked me explains how that works. Not sure if it's possible to implement such a comparator in c++11 because the void overload is not supported I think.
I'm hoping I can get away with having a non-template function object which just has the necessary overloads of operator()(). If my hashtable has keys of type std::string, as long as my Pred functor has an overload for operator()(const std::string &, const char *) (and maybe vice-versa), it looks like it should work. But I haven't tried it yet.
Oh yeah that could work. That's what I'm doing for the hash function in the test, so maybe I can change that for the comparator too.
I just pushed an update that removes the c++14 dependency, using an overloaded class instead of std::equal_to<>.
Sorry it took so long for me to test this. It appears to do exactly what I want, and works fine in C++11 mode.
Thanks!
C++14 added heterogeneous comparison lookup to std::map. This allows us to have a map where the key type is std::string, but use a const char * in our lookup, avoiding the construction of a temporary string object.
I'd like for cuckoohash_map::upsert() to support something similar. Let me have a cuckoohash_map with std::string as the key, but pass const char * as the key argument of upsert(), such that a conversion from const char * to std::string is only done if the key needs to be inserted into the table.
Right now for performance reasons I'm using const char * as my key, but it means the caller of my API must ensure the string is valid for the lifetime of the entry in the table, which it doesn't know.