ceremonyclient/bedlam/pkg/bytes/bytes.qcl
Cassandra Heart dbd95bd9e9
v2.1.0 (#439)
* v2.1.0 [omit consensus and adjacent] - this commit will be amended with the full release after the file copy is complete

* 2.1.0 main node rollup
2025-09-30 02:48:15 -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
}