ceremonyclient/bedlam/pkg/bytes/bytes.qcl
Cassandra Heart e51992f3e8
OT
2025-03-23 21:11:16 -05:00

33 lines
492 B
Go

// -*- go -*-
//
// Copyright (c) 2023 Markku Rossi
//
// All rights reserved.
//
package bytes
// Compare compares two byte slices lexicographically. The result is 0
// if a == b, -1 if a < b, and +1 if a > b.
func Compare(a, b []byte) int {
limit := len(a)
if len(b) < limit {
limit = len(b)
}
for i := 0; i < limit; i++ {
if a[i] < b[i] {
return -1
}
if a[i] > b[i] {
return 1
}
}
if len(a) < len(b) {
return -1
}
if len(a) > len(b) {
return 1
}
return 0
}