cowtowncoder / java-uuid-generator

Java Uuid Generator (JUG) is a Java library for generating all standard UUID versions (v1 - v7)
Apache License 2.0
751 stars 103 forks source link

Variant V7 #48

Closed Hellblazer closed 2 years ago

Hellblazer commented 2 years ago

Implements #46.

cowtowncoder commented 2 years ago

Ok thanks; hope to read this later today... sounds like there may be quite a bit to digest again :)

Hellblazer commented 2 years ago

No worries. I’m likely just doing something obviously silly.

cowtowncoder commented 2 years ago

Ok, so, my head is hurting wrt bit/byte shuffling code so I'll check that another day.

But I did notice one problem: code assumes that Variant 7 uses 100nsec granularity, like existing time-based variant 1 (and new 6). But as far as I can read, spec says that V7 uses millisecond granularity for simplicity. This is the reason why those 12 bits of randomness are needed to pad up things.

So, this complicates changes to UUIDTimer a bit; it may be that getTimestamp() method just needs to be mostly copied into getTimestampV7(). That's not a big deal I am guessing. But refactoring it to minimize duplication may result in more awkward code.

Other than that looks good; I hope to look more into this within next couple days; at latest on Juneteenth when I might have a Free OSS Coding Day for a change. :)

Hellblazer commented 2 years ago

Think this should be correct now.

cowtowncoder commented 2 years ago

@Hellblazer I do believe this is correct! Good job & apologies once again for unreliable follow-up. I'll try to re-re-read once over and the only thing I'll probably try to change is figure out how that Random sharing ought to work. But that's a trivial detail.