c_cpp C中的哈希函数dbg2

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp C中的哈希函数dbg2相关的知识,希望对你有一定的参考价值。

#include <stdio.h>

//c program hash

unsigned long
hash(unsigned char *str)
{
    unsigned long hash = 5381;
    int c;

    while (c = *str++)
        hash = ((hash << 5) + hash) + c; /* hash * 33 + c */

    return hash;
}




int main()
{
    printf("The hash is %d\n", hash("foo") % 100);
    printf("The hash is %d\n", hash("doo") % 100);
    printf("The hash is %d\n", hash("goo")% 100);
    printf("The hash is %d\n", hash("gdo")% 100);
    printf("The hash is %d\n", hash("gsojjj")% 100);
    printf("The hash is %d\n", hash("fooosd")% 100);
    return 0;
}

以上是关于c_cpp C中的哈希函数dbg2的主要内容,如果未能解决你的问题,请参考以下文章

c_cpp C中的哈希映射实现,带有djb2哈希函数

c_cpp 为字符串实现哈希表和哈希函数

c_cpp 为字符串实现哈希表和哈希函数

c_cpp 尝试新的哈希函数

c_cpp C中的哈希表环境类

c_cpp c中的快速哈希表实现。