hash算法简易实现

unsigned int BKDRHash(const char *strHash)
{
   // char hash_name[512] = {0};

    register unsigned int hash;  
    register unsigned char *p;  

    for(hash = 0, p = (unsigned char *)strHash;*p ;p++)
        hash = 31 * hash + *p;  

    return (hash & 0x7FFFFFFF);
}

char cHash[128] = {0};
        struct timeval curr_tv; 
        gettimeofday(&curr_tv,NULL);
        snprintf(cHash,128,"%ld",(curr_tv.tv_sec*1000000+curr_tv.tv_usec));
        int toSkip = BKDRHash(cHash) % 10000; 

你可能感兴趣的:(c,算法,hash)