sony / sonyflake

A distributed unique ID generator inspired by Twitter's Snowflake

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question: uint64 or int64?

theory opened this issue · comments

From the README, sonyflake uses 63 bits. This aligns with the design of Snowflake ID, which is specifically designed to fit in a signed integer:

Snowflakes are 64 bits. (Only 63 are used to fit in a signed integer.)

I notice that sonyflake returns uint64 rather than int64:

func (sf *Sonyflake) NextID() (uint64, error) {

Should it return int64, instead?

I assume not since it has been around for a while. If that's correct, perhaps some documentation could be added to describe how to safely convert the value into an int64 so that it might more easily be used in databases that don't support uint?

The NextID return should return int64,because the result max is int64 length

Thank you for your feedback!
I think it is better to keep the interface for the compatibility. I have added a note instead:
3719d00