
Envoyé par
guillaume07
j'utilise celle ci :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
struct Hash : std::unary_function<std::string, std::size_t>
{
std::size_t operator()(const std::string & s) const
{
int nb = s.length();
unsigned char *str = new unsigned char [ s.length()+1 ];
std::stringstream ss;
ss >> *str;
str[s.length()]='\0';
std::size_t hash = 5381;
while(*str!='\0')
{
int c = *str;
/* hash = hash*33 + c */
hash = ((hash << 5) + hash) + c;
str++;
}
return hash;
}
}; |
Je viens de voir qu'il y a un new et un stringstream là-dedans 
Là je ne m'étonne plus si on me dis que ce n'est pas performant !
Ceci est tellement plus simple (et intuitif)
const unsigned char *str = s.c_str();
Partager