history.go 645 B

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