2009/CaoCourseTme2: hash.c

File hash.c, 540 bytes (added by franck, 14 years ago)
Line 
1#include "hash.h"
2
3/************************************************************************
4  Fonction de calcul de l'index de hachage de Donald Knuth
5  Elle produit un nombre entier à partir d'une chaine de caractères.
6**************************************************************************/
7unsigned int hashindex(char *key)
8{
9    char *c = key;
10    unsigned h;
11    for (h = 0; *c; c++)
12    {
13        h += (h ^ (h >> 1)) + 314159 * (unsigned char) *c;
14        while (h >= 516595003)
15            h -= 516595003;
16    }
17    return h;
18}
19