github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/engine/container/history.go (about)

     1  package container // import "github.com/docker/docker/container"
     2  
     3  import "sort"
     4  
     5  // History is a convenience type for storing a list of containers,
     6  // sorted by creation date in descendant order.
     7  type History []*Container
     8  
     9  // Len returns the number of containers in the history.
    10  func (history *History) Len() int {
    11  	return len(*history)
    12  }
    13  
    14  // Less compares two containers and returns true if the second one
    15  // was created before the first one.
    16  func (history *History) Less(i, j int) bool {
    17  	containers := *history
    18  	return containers[j].Created.Before(containers[i].Created)
    19  }
    20  
    21  // Swap switches containers i and j positions in the history.
    22  func (history *History) Swap(i, j int) {
    23  	containers := *history
    24  	containers[i], containers[j] = containers[j], containers[i]
    25  }
    26  
    27  // sort orders the history by creation date in descendant order.
    28  func (history *History) sort() {
    29  	sort.Sort(history)
    30  }