Closed Hedgezzz closed 7 years ago
I have the following 2 libcuckoo in my machine :
The following compile and run fine at Apr 7 version but failed at Dec 20 version :
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 ?!
Try adding const in your compare class's operator() arguments as follows:
const
operator()
... bool operator()(const char* p1,const char* p2){ ...
Cool .... exactly what I need , thanks .
I have the following 2 libcuckoo in my machine :
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} ;
}
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 ?!