OSDN Git Service

add log (#373)
[bytom/vapor.git] / common / sort.go
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 }