-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrapping behavior of impl ClockSequence for Context
#702
Comments
Hi @fef1312 👋 Hmm, the result of |
Oops, you're right about the What I mean by "lower entropy" is that anything modulo N is always less than N, so the largest value this method will ever return in its current implementation is actually self.count.fetch_add(1, Ordering::AcqRel) % (1 << 14)
self.count.fetch_add(1, Ordering::AcqRel) & (u16::MAX >> 2) These are mathematically equivalent because it's a power of two, so rustc will pick the AND version either way. But again, this is merely a technicality and a single division here won't make an observable difference in the grand scheme of things. The main reason I brought it up was because it's technically not compliant with the RFC. |
Aha, thanks for the explanation. It was simply my ignorance that lead to the original implementation and I think your suggested alternative:
would be a great fix. Would you like to submit a PR for it? |
Alright, sure! |
Fixes issue uuid-rs#702
Fixes issue uuid-rs#702
Hi there! First of all, sorry for not using the bug report template; the link in the contribution guide seems broken.
Anyway, I was just browsing your code and noticed a minor oddity in the implementation of
ClockSequence
forContext
, in timestamp.rs:441. Based on what the comment there states,generate_sequence()
is supposed to just truncate the counter to 14 bits before returning it. However, it actually takes the modulus with0x1fff
instead of0x2000
, which decreases entropy by one and compiles to a division instead of a simple bitwise AND.Is this intentional? I realize I'm being a bit pedantic here, but it can't hurt to point out.
The text was updated successfully, but these errors were encountered: