mirror of
https://github.com/google/uuid.git
synced 2024-11-21 17:16:42 +02:00
feat: add Compare function (#163)
* feat: add Compare function * fix comment
This commit is contained in:
parent
53dda83ebe
commit
e8d82d30a3
6
util.go
6
util.go
@ -5,6 +5,7 @@
|
||||
package uuid
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
)
|
||||
|
||||
@ -41,3 +42,8 @@ func xtob(x1, x2 byte) (byte, bool) {
|
||||
b2 := xvalues[x2]
|
||||
return (b1 << 4) | b2, b1 != 255 && b2 != 255
|
||||
}
|
||||
|
||||
// Compare returns an integer comparing two uuids lexicographically. The result will be 0 if a == b, -1 if a < b, and +1 if a > b.
|
||||
func Compare(a, b UUID) int {
|
||||
return bytes.Compare(a[:], b[:])
|
||||
}
|
||||
|
@ -918,10 +918,10 @@ func TestVersion7MonotonicityStrict(t *testing.T) {
|
||||
defer SetRand(nil)
|
||||
|
||||
length := 100000 // > 3906
|
||||
u1 := Must(NewV7()).String()
|
||||
u1 := Must(NewV7())
|
||||
for i := 0; i < length; i++ {
|
||||
u2 := Must(NewV7()).String()
|
||||
if u2 <= u1 {
|
||||
u2 := Must(NewV7())
|
||||
if Compare(u1, u2) >= 0 {
|
||||
t.Errorf("monotonicity failed at #%d: %s(next) < %s(before)", i, u2, u1)
|
||||
break
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user