github.com/ruphin/docker@v1.10.1/container/history.go (about)

     1  package 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  // Add the given container to history.
    28  func (history *History) Add(container *Container) {
    29  	*history = append(*history, container)
    30  }
    31  
    32  // sort orders the history by creation date in descendant order.
    33  func (history *History) sort() {
    34  	sort.Sort(history)
    35  }