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

Adds Compare and UUID.Equals functions #82

Closed
wants to merge 2 commits into from

Conversation

jonfriesen
Copy link

Hello! I didn't see a section on contributions, I hope I'm not overstepping with this proposal.

This change adds two functions, a Compare(UUID, UUID) int, and UUID attached UUID.Equal(UUID) bool:

Compare takes two UUID's and returns -1 if the first UUID is lexically before the second, 0 if they are equal, and 1 if the first UUID is lexically after the second.

Equal takes a single UUID and compares to the attached returning true if they are equal and false if not. Equal makes use of Compare.

This implementation follows RFC 4122 where equality and order checks should be done by converting the UUID to a unsigned 128-bit integer and compared.

Tests included

Cheers!
Jon

Jon Friesen added 2 commits October 21, 2019 14:01
Adds a Compare and UUID.Equal functions:

Compare takes two UUID's and returns -1 if the first UUID is lexically
before the second, 0 if they are equal, and 1 if the first UUID is
lexically after the second.

This implementation follows RFC 4122 section 4.5 where equality and
order checks should be done by converting the UUID to a unsigned 128-bit
integer and compared.

Tests included.
Adds a Compare and UUID.Equal functions:

Compare takes two UUID's and returns -1 if the first UUID is lexically
before the second, 0 if they are equal, and 1 if the first UUID is
lexically after the second.

This implementation follows RFC 4122 section 4.5 where equality and
order checks should be done by converting the UUID to a unsigned 128-bit
integer and compared.

Tests included.
@niaow
Copy link
Member

niaow commented Oct 21, 2019

Equal used to be here, but was removed because you can just use the == operator. See #36.

@codecov-io
Copy link

codecov-io commented Oct 21, 2019

Codecov Report

Merging #82 into master will increase coverage by 0.03%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #82      +/-   ##
==========================================
+ Coverage   99.05%   99.09%   +0.03%     
==========================================
  Files           4        4              
  Lines         318      330      +12     
==========================================
+ Hits          315      327      +12     
  Misses          2        2              
  Partials        1        1
Impacted Files Coverage Δ
uuid.go 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update abfe188...65cfd5a. Read the comment docs.

@niaow
Copy link
Member

niaow commented Oct 21, 2019

Also, comparing UUIDs should just be bytes.Compare I think.

@jonfriesen
Copy link
Author

@jadr2ddude thanks for responding! You make good points, my attempt to follow the RFC clouded more obvious solutions like == and bytes.Compare 😛

feel free to close this PR

@theckman theckman closed this Oct 21, 2019
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

Successfully merging this pull request may close these issues.

4 participants