UUID到唯一的整数id? [英] UUID to unique integer id?
问题描述
我想知道将UUID转换为唯一整数的最简单方法是什么?我尝试过使用哈希码,但人们告诉我,如果我使用哈希码,它并不总是唯一的?
I was wondering what the easiest way to convert a UUID to a unique integer would be? I have tried using the hash code but people tell me that it is not going to always be unique if i use the hash code?
那么最简单的方法是什么?哈希码是唯一的吗?
So what is the easiest way? Is the hash code unique?
推荐答案
您将遇到问题,因为UUID是128位且int只有32位。您要么必须接受碰撞的风险并尝试将其捏到较小的空间( hashCode
可能是一个很好的方法)或者找到替代方案(使用直接 UUID
,映射到 BigInteger
- 在不知道原因的情况下很难说出来。
You are going to have a problem since the UUID is 128 bits and the int is only 32bit. You'll either have to accept the risk of collisions and try to fudge it to a smaller space (hashCode
is probably a good way to do that) or find an alternative (use the UUID
directly, map to a BigInteger
- difficult to tell without knowing why)
这篇关于UUID到唯一的整数id?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!