首页 > 解决方案 > 字符串的哈希函数

问题描述

我必须开发一个适用于三个键的函数:车辆许可证号、问题日期和姓氏。我的代码适用于 issue_date 和 last_name,但会导致许可证编号发生很多冲突。示例 license_no L1-0015338

我是散列函数的新手,不知道要使用哪种散列函数。

int hash3(char* s, int max)
{
    int prime = 20000;
    char* c;
    unsigned long number, column=1, hash, i;

    for (i = hash = 0; *s; i++, s++)
    {
        column *= (*s);
        prime = nextPrime(prime);
        hash = (((hash << 5) + hash) ^ column) * prime;
    }

    return (int)((hash) % max);
}

标签: chashhashtable

解决方案


推荐阅读