use an in memory store for containers

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
Antonio Murdaca 2016-09-19 13:09:30 +02:00
parent 7fc874e05e
commit 35ef46f805
No known key found for this signature in database
GPG key ID: B2BEAD150DE936B9
5 changed files with 173 additions and 38 deletions

31
oci/history.go Normal file
View file

@ -0,0 +1,31 @@
package oci
import "sort"
// History is a convenience type for storing a list of containers,
// sorted by creation date in descendant order.
type History []*Container
// Len returns the number of containers in the history.
func (history *History) Len() int {
return len(*history)
}
// Less compares two containers and returns true if the second one
// was created before the first one.
func (history *History) Less(i, j int) bool {
containers := *history
// FIXME: state access should be serialized
return containers[j].state.Created.Before(containers[i].state.Created)
}
// Swap switches containers i and j positions in the history.
func (history *History) Swap(i, j int) {
containers := *history
containers[i], containers[j] = containers[j], containers[i]
}
// sort orders the history by creation date in descendant order.
func (history *History) sort() {
sort.Sort(history)
}