github.com/chrislusf/greenpack@v3.7.1-0.20170911073826-ad5bd10b7c47+incompatible/cmd/addzid/sort.go (about)

     1  package main
     2  
     3  type ByFinalOrder []*Field
     4  
     5  func (s ByFinalOrder) Len() int {
     6  	return len(s)
     7  }
     8  func (s ByFinalOrder) Swap(i, j int) {
     9  	s[i], s[j] = s[j], s[i]
    10  }
    11  func (s ByFinalOrder) Less(i, j int) bool {
    12  	return s[i].finalOrder < s[j].finalOrder
    13  }
    14  
    15  type ByOrderOfAppearance []*Field
    16  
    17  func (s ByOrderOfAppearance) Len() int {
    18  	return len(s)
    19  }
    20  func (s ByOrderOfAppearance) Swap(i, j int) {
    21  	s[i], s[j] = s[j], s[i]
    22  }
    23  func (s ByOrderOfAppearance) Less(i, j int) bool {
    24  	return s[i].orderOfAppearance < s[j].orderOfAppearance
    25  }
    26  
    27  type ByGoName []*Struct
    28  
    29  func (s ByGoName) Len() int {
    30  	return len(s)
    31  }
    32  func (s ByGoName) Swap(i, j int) {
    33  	s[i], s[j] = s[j], s[i]
    34  }
    35  func (s ByGoName) Less(i, j int) bool {
    36  	return s[i].goName < s[j].goName
    37  }
    38  
    39  type AlphaHelper struct {
    40  	Name string
    41  	Code []byte
    42  }
    43  
    44  type AlphaHelperSlice []AlphaHelper
    45  
    46  func (s AlphaHelperSlice) Len() int {
    47  	return len(s)
    48  }
    49  func (s AlphaHelperSlice) Swap(i, j int) {
    50  	s[i], s[j] = s[j], s[i]
    51  }
    52  func (s AlphaHelperSlice) Less(i, j int) bool {
    53  	return s[i].Name < s[j].Name
    54  }