简体   繁体   English

如何将两个正整数映射到唯一整数?

[英]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.

相关问题 对于给定的整数a,找到总和为a的所有唯一正整数组合 - For a given integer a, find all unique combinations of positive integers that sum up to a 正整数N作为使用堆栈的正整数之和 - Positive integer N as the sum of positive integers using stack 给定一个整数数组,找到第一个唯一的整数 - Given an array of integers, find the first integer that is unique 从整数范围映射到任意单个整数 - Map from integer ranges to arbitrary single integers 如何将三个整数组合成一个唯一的标记,以使标记在C ++中保持整数? - How to combine three integers into one unique tag, such that the tag stays integer in C++? 两个正整数相加得到否定答案。为什么? - Adding two positive integers gives negative answer.Why? 将存储为整数向量的两个大整数相乘 - Multiplying two large integers stored as integer vectors 如何以1对1方式将所有64位整数映射到不同的64位整数 - How to map all 64-bit integers to a different 64-bit integer in a 1-to-1 fashion 给定任意数量的整数,如何创建唯一键? 并使用该键存储和以后从地图中查找 - How to create a unique key, given arbitrary number of integers ? And use that key to store and later lookup from the map 如何输出一个前面带有正号和零的整数 - How to ouput an integer with positive sign and zeros preceding it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM