efficient / libcuckoo

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

newer version libcuckoo get compile error #48

Closed Hedgezzz closed 7 years ago

Hedgezzz commented 7 years ago

I have the following 2 libcuckoo in my machine :

  1. 186405 Apr 7 2016 libcuckoo-master.zip
  2. 217549 Dec 20 07:51 libcuckoo-master.zip

The following compile and run fine at Apr 7 version but failed at Dec 20 version :

include <libcuckoo/cuckoohash_map.hh>

include <libcuckoo/city_hasher.hh>

template <> class CityHasher<char> { public: size_t operator()(const char ptr) const { return CityHash64((const char) ptr, strlen(ptr)); } }; struct charptrcompare { bool operator()(char p1,char p2){ return strcmp( p1 , p2 ) == 0 ; } } ; cuckoohash_map<char,int,CityHasher<char*>,charptrcompare> StkidMap ;

int main() { char x[8]={0} ,y[8]={0},z[8]={0} ;

strcpy(x,"Marx") ;
strcpy(y,"Mary") ;
strcpy(z,"Marz") ;

StkidMap.insert( x , 100 ) ;
StkidMap.insert( y , 100 ) ;
StkidMap.insert( z , 100 ) ;

char x1[8]={0}  ;
int i ;
strcpy(x1,"Marz") ;
if( StkidMap.find(x1,i) )
    printf("1...YES\n") ;
strcpy(x1,"MarR") ;
if( StkidMap.find(x1,i) )
    printf("2...YES\n") ;
strcpy(x1,"Mary") ;
if( StkidMap.find(x1,i) )
    printf("3...YES\n") ;

}

compile by g++ --std=c++11 -O2 test2.cpp -lcityhash -o test2.exe using Apr 7 libcuckoo in g++ (GCC) 4.8.3 compile fine using Dec 20 libcuckoo in g++ (GCC) 4.8.5 compile error .

May I know how to avoid compile error in my test source ?!

mkaminsky commented 7 years ago

Try adding const in your compare class's operator() arguments as follows:

...
bool operator()(const char* p1,const char* p2){
...
Hedgezzz commented 7 years ago

Cool .... exactly what I need , thanks .