[英]How to map two positive integers to a unique integer?
I need to find a unique integer given two integers. 我需要找到给定两个整数的唯一整数。 That is, given two integers x and y..I want to find a function f...which maps these integers uniquely to another integer z. 也就是说,给定两个整数x和y。我想找到一个函数f ...,它将这些整数唯一地映射到另一个整数z。 That is, z=f(x,y) 也就是说,z = f(x,y)
Here x=64 bit integer and y=64 bit integer. 在此,x = 64位整数,y = 64位整数。 I want to map these numbers to z such it is again a 64 bit integer. 我想将这些数字映射到z,所以它又是一个64位整数。
I tried Cantors pairing function, but Cantors pairing function returns to me a 'z' which is 128 bit as there is a multiplication involved in Cantors pairing function. 我尝试了Cantors配对功能,但是Cantors配对功能返回给我一个128位的“ z”,因为Cantors配对功能涉及乘法。 I do not want z to map to 128 bit as modern computers have processing limitation of only upto 64 bit. 我不希望z映射到128位,因为现代计算机的处理限制仅为64位。
Is there some way out. 有没有出路。 A little bit of collision is acceptable to me. 我可以接受一点碰撞。
If you want to do that for the whole range of 64 bit integer, then this is impossible. 如果要对整个64位整数范围执行此操作,那么这是不可能的。
There are 2^64 * 2^64 = 2^128
possible inputs for your function, but you have only 2^64
different outputs, which means that there have to be at least 2^64
numbers mapped to the same integer which is far more than a little bit of collision
您的函数有2^64 * 2^64 = 2^128
可能的输入,但是您只有2^64
不同的输出,这意味着必须至少有2^64
数字映射到远的同一整数超过a little bit of collision
You are essentially looking for a 64bit hash function. 实际上,您正在寻找64位哈希函数。 Here is a list http://en.wikipedia.org/wiki/List_of_hash_functions 这是一个列表http://en.wikipedia.org/wiki/List_of_hash_functions
Perhaps this function 'boiler-plate' will help? 也许这个“样板”功能会有所帮助?
unsigned long long f(
unsigned long long x,
unsigned long long y
)
{
/** many options here, including those in link provided by @xosp7tom's answer... **/
return(x*y);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.