github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/kv/kvserver/reports/zone_key.go (about) 1 // Copyright 2019 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package reports 12 13 import ( 14 "fmt" 15 16 "github.com/cockroachdb/cockroach/pkg/base" 17 ) 18 19 // ZoneKey is the index of the first level in the constraint conformance report. 20 type ZoneKey struct { 21 // ZoneID is the id of the zone this key is referencing. 22 ZoneID uint32 23 // SubzoneID identifies what subzone, if any, this key is referencing. The 24 // zero value (also named NoSubzone) indicates that the key is referring to a 25 // zone, not a subzone. 26 SubzoneID base.SubzoneID 27 } 28 29 // NoSubzone is used inside a zoneKey to indicate that the key represents a 30 // zone, not a subzone. 31 const NoSubzone base.SubzoneID = 0 32 33 // MakeZoneKey creates a zoneKey. 34 // 35 // Use NoSubzone for subzoneID to indicate that the key references a zone, not a 36 // subzone. 37 func MakeZoneKey(zoneID uint32, subzoneID base.SubzoneID) ZoneKey { 38 return ZoneKey{ 39 ZoneID: zoneID, 40 SubzoneID: subzoneID, 41 } 42 } 43 44 func (k ZoneKey) String() string { 45 return fmt.Sprintf("%d,%d", k.ZoneID, k.SubzoneID) 46 } 47 48 // Less compares two ZoneKeys. 49 func (k ZoneKey) Less(other ZoneKey) bool { 50 if k.ZoneID < other.ZoneID { 51 return true 52 } 53 if k.ZoneID > other.ZoneID { 54 return false 55 } 56 return k.SubzoneID < other.SubzoneID 57 }