158Fermer160
ThibautLe 12/10/2007 à 17:46
Donc voici la fonction retenue pour mon programme :

int fast_and_perfect_hash(const char *str, int length)  // works only with HASH_TABLE_SIZE = 256 or 512 or 1024
{   // very good Daniel Julius Bernstein's algorithm
    // speed optimized by Pollux
    // unrolled by Thibaut for more speed
    // generates very uniform hash tables even with non prime modulos

    register unsigned int hash = 5381; // DJB Hash
    register unsigned int hash5 = 0;
    register const char   *s;
    register int          ir;
    int                   i4;


    s = str;
    i4= length / 4;
    ir= length % 4;

    while (i4-- > 0) {
        hash5+= hash;  hash+= *s++;
        hash5+= hash;  hash+= *s++;
        hash5+= hash;  hash+= *s++;
        hash5+= hash;  hash+= *s++;
    }

    while (ir-- > 0) {
        hash5+= hash;
        hash+= *s++;
    }

    return (hash + (hash5<<5)) % HASH_TABLE_SIZE;
}
Y a-t-il des gens qui trouvent des optimisations de vitesse supplémentaires à y faire ? (à part coder en assembleur tongue)