本文介绍了四个无符号整数的哈希函数(C ++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在编写一个程序,它产生四个无符号的32位整数作为某个函数的输出。我想要哈希这四个整数,所以我可以比较这个函数的输出到未来的输出。I'm writing a program right now which produces four unsigned 32-bit integers as output from a certain function. I'm wanting to hash these four integers, so I can compare the output of this function to future outputs.我有麻烦写一个体面的哈希函数。当我最初写这段代码时,我简单地添加了四个整数,我知道这是不够的。我试过几种其他的技术,如移位和添加,没有效果。我得到一个哈希,但是质量很差,并且该函数产生了大量的冲突。I'm having trouble writing a decent hashing function though. When I originally wrote this code, I threw in a simple addition of each of the four integers, which I knew would not suffice. I've tried several other techniques, such as shifting and adding, to no avail. I get a hash, but it's of poor quality, and the function generate a ton of collisions.哈希输出可以是32位或64位整数。这个函数产生了数十亿的哈希,所以碰撞是一个真正的问题,我愿意使用一个更大的变量,以确保尽可能少的碰撞。The hash output can be either a 32-bit or 64-bit integer. The function in question generates many billions of hashes, so collisions are a real problem here, and I'm willing to use a larger variable to ensure that there are as few collisions as possible.任何人都可以帮我找出如何写一个质量哈希函数?Can anyone help me figure out how to write a quality hash function?推荐答案四个整数在一个合适的数据结构和比较他们所有?在这种情况下散列他们的好处对我来说是可疑的,除非存储是一个问题。Why don't you store the four integers in a suitable data structure and compare them all? The benefit of hashing them in this case appears dubious to me, unless storage is a problem.如果存储是问题,您可以使用散列函数分析此处。If storage is the issue, you can use one of the hash functions analyzed here. 这篇关于四个无符号整数的哈希函数(C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-20 11:09