github.com/franono/tendermint@v0.32.2-0.20200527150959-749313264ce9/abci/types/util.go (about)

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