c - 字符串的哈希函数
问题描述
我必须开发一个适用于三个键的函数:车辆许可证号、问题日期和姓氏。我的代码适用于 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);
}
解决方案
推荐阅读
- java - 在主类中使用 maven
- javascript - JS - touchstart / end 事件在 iOS 上不起作用
- python - Python - 如何解决 OSError:[Errno 22] 无效参数
- google-analytics - 如何按用户 ID(作为自定义维度)按天获取会话?
- github - Github 风格的降价中具有任意位置的表头
- php - 如何将参数传递给关系。参数从控制器传递给关系到laravel中的模型。但现在可以工作了
- postgresql - 构建一个 dockerfile 工作,但从 compose 引用它并运行它失败。不确定是否是 dockerfile 文件路径错误?
- python - Neuropy 库 TypeError:__init__() 缺少 1 个必需的位置参数:“端口”
- python - Athena 为镶木地板文件中的时间戳字段返回错误值
- swift - Realm Swift:如何将不同的 Realm 对象映射到一个符合相同协议的 List<>