how can i generate a unique int from a unique string?

后端 未结 6 1439
生来不讨喜
生来不讨喜 2020-12-24 09:32

I have an object with a String that holds a unique id . (such as \"ocx7gf\" or \"67hfs8\") I need to supply it an implementation of int hascode() which will be unique obvio

6条回答
  •  长情又很酷
    2020-12-24 10:13

    Unless your strings are limited in some way or your integers hold more bits than the strings you're trying to convert, you cannot guarantee the uniqueness.

    Let's say you have a 32 bit integer and a 64-character character set for your strings. That means six bits per character. That will allow you to store five characters into an integer. More than that and it won't fit.

提交回复
热议问题