Skip to content

Instantly share code, notes, and snippets.

@jbandela
Created July 26, 2013 18:47
Show Gist options
  • Save jbandela/6091277 to your computer and use it in GitHub Desktop.
Save jbandela/6091277 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cds/container/cuckoo_map.h>
#include <string>
#include <utility>
struct hash1 {
size_t operator()(std::string const& s) const
{
std::hash<std::string> h;
return h( s ) ;
}
};
struct hash2: private hash1 {
size_t operator()(std::string const& s) const
{
size_t h = ~( hash1::operator()(s)) ;
return ~h + 0x9e3779b9 + (h << 6) + (h >> 2) ;
}
};
typedef int foo;
// Declare type traits
struct my_traits: public cds::container::cuckoo::type_traits
{
typedef std::equal_to< std::string > equal_to ;
typedef std::tuple< hash1, hash2 > hash ;
enum{store_hash = true };
};
// Equal option-based declaration
typedef cds::container::CuckooMap< std::string, foo,
cds::container::cuckoo::make_traits<
cds::opt::hash< std::tuple< hash1, hash2 > >
,cds::opt::equal_to< std::equal_to< std::string > >
,cds::container::cuckoo::store_hash< true >
>::type
> opt_cuckoo_map ;
int main(){
opt_cuckoo_map c;
c.insert("Hello",5);
c.find("Hello",[](std::pair<std::string,int> i){
std::cout << i.second << "\n";
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment