github.com/dashpay/godash@v0.0.0-20160726055534-e038a21e0e3d/blockchain/timesorter.go (about)

     1  // Copyright (c) 2013-2014 The btcsuite developers
     2  // Copyright (c) 2016 The Dash 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  import (
     9  	"time"
    10  )
    11  
    12  // timeSorter implements sort.Interface to allow a slice of timestamps to
    13  // be sorted.
    14  type timeSorter []time.Time
    15  
    16  // Len returns the number of timestamps in the slice.  It is part of the
    17  // sort.Interface implementation.
    18  func (s timeSorter) Len() int {
    19  	return len(s)
    20  }
    21  
    22  // Swap swaps the timestamps at the passed indices.  It is part of the
    23  // sort.Interface implementation.
    24  func (s timeSorter) Swap(i, j int) {
    25  	s[i], s[j] = s[j], s[i]
    26  }
    27  
    28  // Less returns whether the timstamp with index i should sort before the
    29  // timestamp with index j.  It is part of the sort.Interface implementation.
    30  func (s timeSorter) Less(i, j int) bool {
    31  	return s[i].Before(s[j])
    32  }