container/history.go
3c82fad4
 package container
c987aa09
 
3c82fad4
 import "sort"
c987aa09
 
 // History is a convenience type for storing a list of containers,
3c82fad4
 // sorted by creation date in descendant order.
 type History []*Container
c987aa09
 
3c82fad4
 // Len returns the number of containers in the history.
c987aa09
 func (history *History) Len() int {
 	return len(*history)
 }
 
3c82fad4
 // Less compares two containers and returns true if the second one
 // was created before the first one.
c987aa09
 func (history *History) Less(i, j int) bool {
 	containers := *history
71b241cb
 	return containers[j].Created.Before(containers[i].Created)
c987aa09
 }
 
3c82fad4
 // Swap switches containers i and j positions in the history.
c987aa09
 func (history *History) Swap(i, j int) {
 	containers := *history
fc325274
 	containers[i], containers[j] = containers[j], containers[i]
c987aa09
 }
 
3c82fad4
 // sort orders the history by creation date in descendant order.
abd72d40
 func (history *History) sort() {
c987aa09
 	sort.Sort(history)
 }