Skip to content
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

Incorrect lexical ordering #50

Closed
ataggart opened this issue Oct 28, 2019 · 1 comment
Closed

Incorrect lexical ordering #50

ataggart opened this issue Oct 28, 2019 · 1 comment

Comments

@ataggart
Copy link

Per RFC 4122, section 3, "Rules for Lexical Equivalence":

Consider each field of the UUID to be an unsigned integer as shown
in the table in section Section 4.1.2.

IIUC, the following should be the correct ordering (0x7d < 0xb6):

  1. 7d7d081d-7440-441d-9828-26e57c614219
  2. b6be8d3b-7bad-4499-8a33-50634dc9e3a9

And yet:

user=> (def x #uuid "7d7d081d-7440-441d-9828-26e57c614219")
#'user/x
user=> (def y #uuid "b6be8d3b-7bad-4499-8a33-50634dc9e3a9")
#'user/y
user=> (sort (comparator uuid<) [x y])
(#uuid "b6be8d3b-7bad-4499-8a33-50634dc9e3a9" #uuid "7d7d081d-7440-441d-9828-26e57c614219")

This is a consequence of using signed comparison:

user=> (.getMostSignificantBits x)
9042392549427266589
user=> (.getMostSignificantBits y)
-5278626426614102887
user=> (Long/compare (.getMostSignificantBits x) (.getMostSignificantBits y))
1
user=> (Long/compareUnsigned (.getMostSignificantBits x) (.getMostSignificantBits y))
-1

This is also an issue with the implementation of java.util.UUID/compareTo:

user=> (sort [x y])
(#uuid "b6be8d3b-7bad-4499-8a33-50634dc9e3a9" #uuid "7d7d081d-7440-441d-9828-26e57c614219")

Given the ubiquity of the problem, I suspect providing new, compliant lexical functions would be better than changing the existing behaviour.

@danlentz
Copy link
Owner

For lexical ordering, see #53

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants