C的最小哈希函数? [英] A minimal hash function for C?

查看:86
本文介绍了C的最小哈希函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能使用boost:hash,因为我必须坚持使用C并且不能使用C ++.

I can't use boost:hash because I have to stick with C and can't use C++.

但是,我需要对大量(10K到100k)令牌字符串(5到40个字节的长度)进行哈希处理,以便在其中快速搜索.

But, I need to hash a large number (10K to 100k) of tokens strings (5 to 40 bytes length) so that search within those are fastest.

MD5,SHA1或任何长哈希函数对于一个简单的任务来说似乎太重了,我没有在做密码学.再加上存储和计算成本.

MD5, SHA1 or any long hash function seems too heavy for a simple task, I am not doing cryptography. Plus there is the storage and computing cost.

因此我的问题:

  1. 最简单的哈希算法是什么,它将在大多数实际情况下确保预防冲突.

  1. What might be the simplest hash algorithm that will ensure collision prevention in most practical cases.

哈希值使用多少位?我正在为32位系统开发. Perl/Python中的哈希算法是否也使用32位哈希?还是我必须跳到64位?

How many bit to use for the hash value? I am developing for 32 bit systems. Does hash algorithm in Perl/Python use 32 bit hashes too? Or do I have to jump to 64?

关于常见脚本语言中哈希表的实现:该实现是否检查冲突,还是可以完全避免该部分?

Regarding implementation of hash tables in common scripting languages: does the implementation check for collisions or can I avoid that part altogether?

推荐答案

您可以在 http://www.azillionmonkeys.com/qed/hash.html

唯一一次不应该检查冲突的地方是,如果您使用完美的哈希值-一个很好的老式查找表,例如 gperf .

The only time you should not check for collisions, is if you use a perfect hash -- a good old fashioned lookup table, like gperf.

这篇关于C的最小哈希函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆