java - Generate unique id from unique string input -
I have a table with a column of unique string values. The maximum length of the string value is 255 characters. I want to generate a unique ID with the string value as input. In other words, I am looking for compact representation for string. Unique ID generated can be alpha-numeric. A useful feature is that it will be able to rebuild the string value from the unique ID.
Is there any skillful work to generate such a unique ID? Some methods can use a checksum or hash function. I want to know that there is a standard way to do this.
I am using MySQL database and Java
Thanks!
- Edit: I'm only looking for more compact representation than using string.
How unique is "unique"? Using any good smearing function (MD5 is good for more uses, and can easily be implemented via Java Asurcity.MessageDigest.Get Instance ("MD5") can reach 128-bit numbers Which is very likely to be unique. With a high probability of confrontation, the hash receives a small ID.
Using an auto_increment field in DB, if it is your D It fits in the design, so it can be easy to implement, in reality the guarantee of specificity, and its use is smaller than the 16 bytes of MD5. You can then fulfill your requirement of finding the string with the key, Which you can not do for a hash.
Comments
Post a Comment