UUID to unique integer id?

前端 未结 6 747
悲哀的现实
悲哀的现实 2021-01-01 08:37

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 un

6条回答
  •  轮回少年
    2021-01-01 08:52

    We had a requirement to convert all our UUIDs into serial numbers. Finally, we tested and used the next algorithm:

    1. Get CRC64 of uuid(16 bytes) using the ECMA polynomial 0xC96C5795D7870F42. Do not use ISO polynomial because it could cause a lot of collisions for some UUID generation algorithms.

    2. Now we have crc64(8 bytes). Take the first N bytes(in our case 5 in yours it will be 4 bytes for int and all bytes for int64)

    We tested this method and it works well for several million UUIDs.

    Our additional step: convert 5 bytes number into a number with base 36 and finally we have SN: 4YD3SOJB.

提交回复
热议问题