2018-02-01 13:13:24 +00:00
|
|
|
package accounting
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sort"
|
|
|
|
"strings"
|
2018-05-02 16:01:39 +00:00
|
|
|
"sync"
|
2018-02-01 13:13:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// stringSet holds a set of strings
|
2018-05-02 16:01:39 +00:00
|
|
|
type stringSet struct {
|
|
|
|
mu sync.RWMutex
|
|
|
|
items map[string]struct{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// newStringSet creates a new empty string set of capacity size
|
|
|
|
func newStringSet(size int) *stringSet {
|
|
|
|
return &stringSet{
|
|
|
|
items: make(map[string]struct{}, size),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// add adds remote to the set
|
|
|
|
func (ss *stringSet) add(remote string) {
|
|
|
|
ss.mu.Lock()
|
|
|
|
ss.items[remote] = struct{}{}
|
|
|
|
ss.mu.Unlock()
|
|
|
|
}
|
|
|
|
|
|
|
|
// del removes remote from the set
|
|
|
|
func (ss *stringSet) del(remote string) {
|
|
|
|
ss.mu.Lock()
|
|
|
|
delete(ss.items, remote)
|
|
|
|
ss.mu.Unlock()
|
|
|
|
}
|
|
|
|
|
|
|
|
// empty returns whether the set has any items
|
|
|
|
func (ss *stringSet) empty() bool {
|
|
|
|
ss.mu.RLock()
|
|
|
|
defer ss.mu.RUnlock()
|
|
|
|
return len(ss.items) == 0
|
|
|
|
}
|
2018-02-01 13:13:24 +00:00
|
|
|
|
|
|
|
// Strings returns all the strings in the stringSet
|
2018-05-02 16:01:39 +00:00
|
|
|
func (ss *stringSet) Strings() []string {
|
|
|
|
ss.mu.RLock()
|
|
|
|
defer ss.mu.RUnlock()
|
|
|
|
strings := make([]string, 0, len(ss.items))
|
|
|
|
for name := range ss.items {
|
2018-02-01 13:13:24 +00:00
|
|
|
var out string
|
|
|
|
if acc := Stats.inProgress.get(name); acc != nil {
|
|
|
|
out = acc.String()
|
|
|
|
} else {
|
|
|
|
out = name
|
|
|
|
}
|
|
|
|
strings = append(strings, " * "+out)
|
|
|
|
}
|
|
|
|
sorted := sort.StringSlice(strings)
|
|
|
|
sorted.Sort()
|
|
|
|
return sorted
|
|
|
|
}
|
|
|
|
|
|
|
|
// String returns all the file names in the stringSet joined by newline
|
2018-05-02 16:01:39 +00:00
|
|
|
func (ss *stringSet) String() string {
|
2018-02-01 13:13:24 +00:00
|
|
|
return strings.Join(ss.Strings(), "\n")
|
|
|
|
}
|