-
Notifications
You must be signed in to change notification settings - Fork 2
exSDK use its own uid generate algorithm. The uid(in type ex_uid_t) is basically calculate by time and designed for limited number of machine used on it. In general, if you generate your uid on your pc, it can give you unique id for about 179 years since 1/1/2010.
The uid is a unsigned int64 variable consisted by the bitfield defined below:
serverID (64-56) | offset (55-48) | days (47-32) | msecs (31-0)
server ID
The serverID can be defined by user, so if they are running uid in several server, these machine can generate different ID based on what the server ID the get.
offset
The offset is a variable that calculated by exsdk automatically. Since we generate uid based on time, and the minimal unit in our generate algorithm is milli-second(ms), the ms unit can't guarantee that each instruction can run on different ms unit (even u-second can't). So we first generate the ID, and compare it with the last generated time, check if they are the same, and simply add the offset by 1 for difference. Since the offset only take 8 bits, we can accept you generate 255 unique id in 1 milli-second(ms), and this can be acceptable in most of the computer around the world.
days
The days took calculate the days from year 2010/1/1 till today, and since its a 32-bits integer, we should have about (2^32-1)/365 = 179 years plus 200 days long time to generate our unique id.
msecs
The msecs is the milli-seconds for one day.