github.com/tompao/docker@v1.9.1/daemon/history.go (about)

     1  package daemon
     2  
     3  import (
     4  	"sort"
     5  )
     6  
     7  // History is a convenience type for storing a list of containers,
     8  // ordered by creation date.
     9  type History []*Container
    10  
    11  func (history *History) Len() int {
    12  	return len(*history)
    13  }
    14  
    15  func (history *History) Less(i, j int) bool {
    16  	containers := *history
    17  	return containers[j].Created.Before(containers[i].Created)
    18  }
    19  
    20  func (history *History) Swap(i, j int) {
    21  	containers := *history
    22  	containers[i], containers[j] = containers[j], containers[i]
    23  }
    24  
    25  // Add the given container to history.
    26  func (history *History) Add(container *Container) {
    27  	*history = append(*history, container)
    28  }
    29  
    30  func (history *History) sort() {
    31  	sort.Sort(history)
    32  }