UNIX: System-V-Hash 生成算法

尽量少产生collision

int ELFhash(char* key) {
    unsigned long h = 0;
    while(*key) {
        h = (h << 4) + *key++;  //move left 4 bit
        unsigned long g = h & 0xF0000000L;   //and
        if(g) h ^= g >> 24;    //or , move right
        h &= ~g;    //and, not, 
    }
    return h % M;
}

你可能感兴趣的:(C++,c,算法,unix,C#)