github.com/badrootd/nibiru-cometbft@v0.37.5-0.20240307173500-2a75559eee9b/abci/types/util.go (about) 1 package types 2 3 import ( 4 "sort" 5 ) 6 7 //------------------------------------------------------------------------------ 8 9 // ValidatorUpdates is a list of validators that implements the Sort interface 10 type ValidatorUpdates []ValidatorUpdate 11 12 var _ sort.Interface = (ValidatorUpdates)(nil) 13 14 // All these methods for ValidatorUpdates: 15 // Len, Less and Swap 16 // are for ValidatorUpdates to implement sort.Interface 17 // which will be used by the sort package. 18 // See Issue https://github.com/tendermint/abci/issues/212 19 20 func (v ValidatorUpdates) Len() int { 21 return len(v) 22 } 23 24 // XXX: doesn't distinguish same validator with different power 25 func (v ValidatorUpdates) Less(i, j int) bool { 26 return v[i].PubKey.Compare(v[j].PubKey) <= 0 27 } 28 29 func (v ValidatorUpdates) Swap(i, j int) { 30 v[i], v[j] = v[j], v[i] 31 }