lib: sandbox: refactor to memory store
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
parent
b9ffd277b9
commit
d168fc5fec
5 changed files with 173 additions and 24 deletions
31
lib/sandbox/history.go
Normal file
31
lib/sandbox/history.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package sandbox
|
||||
|
||||
import "sort"
|
||||
|
||||
// History is a convenience type for storing a list of sandboxes,
|
||||
// sorted by creation date in descendant order.
|
||||
type History []*Sandbox
|
||||
|
||||
// Len returns the number of sandboxes in the history.
|
||||
func (history *History) Len() int {
|
||||
return len(*history)
|
||||
}
|
||||
|
||||
// Less compares two sandboxes and returns true if the second one
|
||||
// was created before the first one.
|
||||
func (history *History) Less(i, j int) bool {
|
||||
sandboxes := *history
|
||||
// FIXME: state access should be serialized
|
||||
return sandboxes[j].created.Before(sandboxes[i].created)
|
||||
}
|
||||
|
||||
// Swap switches sandboxes i and j positions in the history.
|
||||
func (history *History) Swap(i, j int) {
|
||||
sandboxes := *history
|
||||
sandboxes[i], sandboxes[j] = sandboxes[j], sandboxes[i]
|
||||
}
|
||||
|
||||
// sort orders the history by creation date in descendant order.
|
||||
func (history *History) sort() {
|
||||
sort.Sort(history)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue