twitter-archive / snowflake

Snowflake is a network service for generating unique ID numbers at high scale with some simple guarantees.
http://twitter.com/
7.68k stars 1.13k forks source link

One bit not used #16

Closed codemedic closed 11 years ago

codemedic commented 11 years ago

Is that for any particular reason that one bit is left un-used; just curious?

    //  1111111111111111111111111111111111111111111111111111111111111111
    // |-------------------41--------------------|                      |
    // |                                        |----10----|            |
    // |                                                   |-----12-----|
    //                                                     |
    //                                                     +- 1 bit not used!
jmhodges commented 11 years ago

Ah, easily answered. The top bit is unused because the JVM has no unsigned longs. If it was flipped, the JVM would interpret the id as a negative number and certain systems would behave poorly when they ran into such an id.