Adjust code style

This commit is contained in:
Marius 2015-11-26 12:43:31 +01:00
parent 38e0a4759b
commit 7b1cf1f639
1 changed files with 17 additions and 17 deletions

View File

@ -14,8 +14,8 @@ package limitedstore
import ( import (
"github.com/tus/tusd" "github.com/tus/tusd"
"sort"
"sync" "sync"
"sort"
) )
type LimitedStore struct { type LimitedStore struct {
@ -30,16 +30,15 @@ type LimitedStore struct {
// pair structure to perform map-sorting // pair structure to perform map-sorting
type pair struct { type pair struct {
key string key string
value int64 value int64
} }
type pairlist []pair type pairlist []pair
func (p pairlist) Len() int { return len(p) } func (p pairlist) Len() int { return len(p) }
func (p pairlist) Swap(i, j int) { p[i], p[j] = p[j], p[i] } func (p pairlist) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
func (p pairlist) Less(i, j int) bool { return p[i].value < p[j].value } func (p pairlist) Less(i, j int) bool { return p[i].value < p[j].value }
// Create a new limited store with the given size as the maximum storage size // Create a new limited store with the given size as the maximum storage size
func New(storeSize int64, dataStore tusd.DataStore) *LimitedStore { func New(storeSize int64, dataStore tusd.DataStore) *LimitedStore {
@ -97,18 +96,19 @@ func (store *LimitedStore) ensureSpace(size int64) error {
// Enough space is available to store the new upload // Enough space is available to store the new upload
return nil return nil
} }
sorted_uploads := make(pairlist, len(store.uploads))
i := 0
for u,h := range store.uploads {
sorted_uploads[i] = pair{u, h}
i++
}
sort.Sort(sort.Reverse(sorted_uploads))
// Forward traversal through the sortedUploads := make(pairlist, len(store.uploads))
// uploads in terms of size, biggest upload first i := 0
for _,k := range sorted_uploads { for u, h := range store.uploads {
id := k.key sortedUploads[i] = pair{u, h}
i++
}
sort.Sort(sort.Reverse(sortedUploads))
// Forward traversal through the uploads in terms of size, biggest upload first
for _, k := range sortedUploads {
id := k.key
if err := store.terminate(id); err != nil { if err := store.terminate(id); err != nil {
return err return err
} }