github.com/Bytom/bytom@v1.1.2-0.20210127130405-ae40204c0b09/common/sort.go (about) 1 package common 2 3 // timeSorter implements sort.Interface to allow a slice of timestamps to 4 // be sorted. 5 type TimeSorter []uint64 6 7 // Len returns the number of timestamps in the slice. It is part of the 8 // sort.Interface implementation. 9 func (s TimeSorter) Len() int { 10 return len(s) 11 } 12 13 // Swap swaps the timestamps at the passed indices. It is part of the 14 // sort.Interface implementation. 15 func (s TimeSorter) Swap(i, j int) { 16 s[i], s[j] = s[j], s[i] 17 } 18 19 // Less returns whether the timstamp with index i should sort before the 20 // timestamp with index j. It is part of the sort.Interface implementation. 21 func (s TimeSorter) Less(i, j int) bool { 22 return s[i] < s[j] 23 }