Mapping two integers to one, in a unique and deterministic way

前端 未结 19 2440
不知归路
不知归路 2020-11-22 09:35

Imagine two positive integers A and B. I want to combine these two into a single integer C.

There can be no other integers D and E which combine to C. So combining

19条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-22 10:13

    Check this: http://en.wikipedia.org/wiki/Pigeonhole_principle. If A, B and C are of same type, it cannot be done. If A and B are 16-bit integers, and C is 32-bit, then you can simply use shifting.

    The very nature of hashing algorithms is that they cannot provide a unique hash for each different input.

提交回复
热议问题