mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-05-24 15:56:42 +00:00
35 lines
750 B
Go
35 lines
750 B
Go
package subnetworks
|
|
|
|
import (
|
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
|
)
|
|
|
|
func cmp(a, b externalapi.DomainSubnetworkID) int {
|
|
// We compare the hashes backwards because Hash is stored as a little endian byte array.
|
|
for i := externalapi.DomainSubnetworkIDSize - 1; i >= 0; i-- {
|
|
switch {
|
|
case a[i] < b[i]:
|
|
return -1
|
|
case a[i] > b[i]:
|
|
return 1
|
|
}
|
|
}
|
|
return 0
|
|
}
|
|
|
|
// Less returns true iff id a is less than id b
|
|
func Less(a, b externalapi.DomainSubnetworkID) bool {
|
|
return cmp(a, b) < 0
|
|
}
|
|
|
|
// IsEqual returns true if a and b are equal or both nil
|
|
func IsEqual(a, b *externalapi.DomainSubnetworkID) bool {
|
|
if a == nil && b == nil {
|
|
return true
|
|
}
|
|
if a == nil || b == nil {
|
|
return false
|
|
}
|
|
return *a == *b
|
|
}
|