github.com/decred/dcrd/blockchain@v1.2.1/timesorter.go (about) 1 // Copyright (c) 2013-2014 The btcsuite developers 2 // Copyright (c) 2015-2018 The Decred developers 3 // Use of this source code is governed by an ISC 4 // license that can be found in the LICENSE file. 5 6 package blockchain 7 8 // timeSorter implements sort.Interface to allow a slice of timestamps to 9 // be sorted. 10 type timeSorter []int64 11 12 // Len returns the number of timestamps in the slice. It is part of the 13 // sort.Interface implementation. 14 func (s timeSorter) Len() int { 15 return len(s) 16 } 17 18 // Swap swaps the timestamps at the passed indices. It is part of the 19 // sort.Interface implementation. 20 func (s timeSorter) Swap(i, j int) { 21 s[i], s[j] = s[j], s[i] 22 } 23 24 // Less returns whether the timstamp with index i should sort before the 25 // timestamp with index j. It is part of the sort.Interface implementation. 26 func (s timeSorter) Less(i, j int) bool { 27 return s[i] < s[j] 28 }