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