gofrs / uuid

A UUID package for Go
MIT License
1.58k stars 111 forks source link

Adds Compare and UUID.Equals functions #82

Closed jonfriesen closed 4 years ago

jonfriesen commented 4 years ago

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

niaow commented 4 years ago

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

codecov-io commented 4 years ago

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%> (ø) :arrow_up:

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 commented 4 years ago

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

jonfriesen commented 4 years ago

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

feel free to close this PR