From c2b89f69fcd9977c2561af7665bdb6a4682c46b8 Mon Sep 17 00:00:00 2001 From: Gabe Date: Tue, 14 Aug 2018 16:59:33 -0600 Subject: [PATCH] Update use of set.v0 to latest code - Migrate gopkg.in/fatih/set.v0 -> github.com/fatih/set in code - Remove gopkg.in/fatih/set.v0 from vendor/ - Add github.com/fatih/set to vendor/ --- .../components/versions/3_1_0/component.go | 6 +- tools/mapset/map.go | 4 +- vendor.conf | 2 +- .../fatih/set}/LICENSE.md | 0 .../set.v0 => github.com/fatih/set}/README.md | 65 ++++++++----------- .../set.v0 => github.com/fatih/set}/set.go | 29 ++++++++- .../fatih/set}/set_nots.go | 28 ++++---- .../set.v0 => github.com/fatih/set}/set_ts.go | 20 ++---- 8 files changed, 80 insertions(+), 74 deletions(-) rename vendor/{gopkg.in/fatih/set.v0 => github.com/fatih/set}/LICENSE.md (100%) rename vendor/{gopkg.in/fatih/set.v0 => github.com/fatih/set}/README.md (80%) rename vendor/{gopkg.in/fatih/set.v0 => github.com/fatih/set}/set.go (84%) rename vendor/{gopkg.in/fatih/set.v0 => github.com/fatih/set}/set_nots.go (87%) rename vendor/{gopkg.in/fatih/set.v0 => github.com/fatih/set}/set_ts.go (91%) diff --git a/pkg/lib/components/versions/3_1_0/component.go b/pkg/lib/components/versions/3_1_0/component.go index 62ed2629..f1e9d3f6 100644 --- a/pkg/lib/components/versions/3_1_0/component.go +++ b/pkg/lib/components/versions/3_1_0/component.go @@ -8,8 +8,8 @@ import ( "sort" "github.com/blang/semver" + "github.com/fatih/set" "github.com/opencontrol/compliance-masonry/pkg/lib/common" - "gopkg.in/fatih/set.v0" ) // Component struct is an individual component requiring documentation @@ -132,7 +132,7 @@ func (s Satisfies) GetControlOrigin() string { // GetControlOrigins returns all the control origins func (s Satisfies) GetControlOrigins() []string { - controlOrigins := set.New() + controlOrigins := set.New(set.ThreadSafe) for i := range s.ControlOrigins { controlOrigins.Add(s.ControlOrigins[i]) } @@ -151,7 +151,7 @@ func (s Satisfies) GetImplementationStatus() string { // GetImplementationStatuses returns all implementation statuses func (s Satisfies) GetImplementationStatuses() []string { - implementationStatuses := set.New() + implementationStatuses := set.New(set.ThreadSafe) for i := range s.ImplementationStatuses { implementationStatuses.Add(s.ImplementationStatuses[i]) } diff --git a/tools/mapset/map.go b/tools/mapset/map.go index 953e8fe9..17bae26d 100644 --- a/tools/mapset/map.go +++ b/tools/mapset/map.go @@ -6,7 +6,7 @@ package mapset import ( "errors" - "gopkg.in/fatih/set.v0" + "github.com/fatih/set" ) // MapSet is the map with each value being a set. @@ -39,7 +39,7 @@ func (m *MapSet) Reserve(key string, value string) (result Result) { } var innerSet *set.Set if _, ok := m.mapOfSet[key]; !ok { - innerSet = set.New() + innerSet = set.New(set.ThreadSafe).(*set.Set) m.mapOfSet[key] = innerSet } if m.mapOfSet[key].Has(value) { diff --git a/vendor.conf b/vendor.conf index 099a1598..40125c47 100644 --- a/vendor.conf +++ b/vendor.conf @@ -1,4 +1,4 @@ -gopkg.in/fatih/set.v0 master +github.com/fatih/set master github.com/stretchr/testify master github.com/stretchr/objx master github.com/davecgh/go-spew master diff --git a/vendor/gopkg.in/fatih/set.v0/LICENSE.md b/vendor/github.com/fatih/set/LICENSE.md similarity index 100% rename from vendor/gopkg.in/fatih/set.v0/LICENSE.md rename to vendor/github.com/fatih/set/LICENSE.md diff --git a/vendor/gopkg.in/fatih/set.v0/README.md b/vendor/github.com/fatih/set/README.md similarity index 80% rename from vendor/gopkg.in/fatih/set.v0/README.md rename to vendor/github.com/fatih/set/README.md index 3bdc9f95..b067d3a6 100644 --- a/vendor/gopkg.in/fatih/set.v0/README.md +++ b/vendor/github.com/fatih/set/README.md @@ -5,7 +5,7 @@ This project is not maintained anymore and is archived.. Please create your own Thanks all for their work on this project. -# Set [![GoDoc](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)](https://godoc.org/gopkg.in/fatih/set.v0) [![Build Status](http://img.shields.io/travis/fatih/set.svg?style=flat-square)](https://travis-ci.org/fatih/set) +# Set [![GoDoc](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)](https://godoc.org/github.com/fatih/set) [![Build Status](http://img.shields.io/travis/fatih/set.svg?style=flat-square)](https://travis-ci.org/fatih/set) Set is a basic and simple, hash-based, **Set** data structure implementation in Go (Golang). @@ -24,13 +24,13 @@ For usage see examples below or click on the godoc badge. Install the package with: ```bash -go get gopkg.in/fatih/set.v0 +go get github.com/fatih/set ``` Import it with: ```go -import "gopkg.in/fatih/set.v0" +import "githug.com/fatih/set" ``` and use `set` as the package name inside the code. @@ -40,15 +40,9 @@ and use `set` as the package name inside the code. #### Initialization of a new Set ```go - // create a set with zero items -s := set.New() -s := set.NewNonTS() // non thread-safe version - -// ... or with some initial values -s := set.New("istanbul", "frankfurt", 30.123, "san francisco", 1234) -s := set.NewNonTS("kenya", "ethiopia", "sumatra") - +s := set.New(set.ThreadSafe) // thread safe version +s := set.New(set.NonThreadSafe) // non thread-safe version ``` #### Basic Operations @@ -63,7 +57,7 @@ s.Add("ankara", "san francisco", 3.14) // remove item s.Remove("frankfurt") -s.Remove("frankfurt") // nothing happes if you remove a nonexisting item +s.Remove("frankfurt") // nothing happens if you remove a nonexisting item // remove multiple items s.Remove("barcelona", 3.14, "ankara") @@ -85,7 +79,6 @@ items := s.List() // string representation of set fmt.Printf("set is %s", s.String()) - ``` #### Check Operations @@ -104,7 +97,6 @@ s.Has("istanbul", "san francisco", 3.14) s := s.New("1", "2", "3", "4", "5") t := s.New("1", "2", "3") - // check if they are the same if !s.IsEqual(t) { fmt.Println("s is not equal to t") @@ -119,17 +111,16 @@ if s.IsSubset(t) { if t.IsSuperset(s) { fmt.Println("s is a superset of t") } - - ``` #### Set Operations - ```go // let us initialize two sets with some values -a := set.New("ankara", "berlin", "san francisco") -b := set.New("frankfurt", "berlin") +a := set.New(set.ThreadSafe) +a := set.Add("ankara", "berlin", "san francisco") +b := set.New(set.NonThreadSafe) +b := set.Add("frankfurt", "berlin") // creates a new set with the items in a and b combined. // [frankfurt, berlin, ankara, san francisco] @@ -146,7 +137,6 @@ c := set.Difference(a, b) // contains items which are in one of either, but not in both. // [frankfurt, ankara, san francisco] c := set.SymmetricDifference(a, b) - ``` ```go @@ -155,15 +145,17 @@ a.Merge(b) // removes the set items which are in b from a and saves the result back into a. a.Separate(b) - ``` #### Multiple Set Operations ```go -a := set.New("1", "3", "4", "5") -b := set.New("2", "3", "4", "5") -c := set.New("4", "5", "6", "7") +a := set.New(set.ThreadSafe) +a := set.Add("1", "3", "4", "5") +b := set.New(set.ThreadSafe) +b := set.Add("2", "3", "4", "5") +c := set.New(set.ThreadSafe) +c := set.Add("4", "5", "6", "7") // creates a new set with items in a, b and c // [1 2 3 4 5 6 7] @@ -183,21 +175,18 @@ u := set.Intersection(a, b, c) The Slice functions below are a convenient way to extract or convert your Set data into basic data types. - ```go // create a set of mixed types -s := set.New("ankara", "5", "8", "san francisco", 13, 21) - +s := set.New(set.ThreadSafe) +s := set.Add("ankara", "5", "8", "san francisco", 13, 21) // convert s into a slice of strings (type is []string) // [ankara 5 8 san francisco] t := set.StringSlice(s) - // u contains a slice of ints (type is []int) // [13, 21] u := set.IntSlice(s) - ``` #### Concurrent safe usage @@ -211,25 +200,28 @@ package main import ( "fmt" - "github.com/fatih/set" "strconv" "sync" + + "github.com/fatih/set" ) func main() { var wg sync.WaitGroup // this is just for waiting until all goroutines finish // Initialize our thread safe Set - s := set.New() + s := set.New(set.ThreadSafe) // Add items concurrently (item1, item2, and so on) for i := 0; i < 10; i++ { wg.Add(1) + go func(i int) { + defer wg.Done() + item := "item" + strconv.Itoa(i) fmt.Println("adding", item) s.Add(item) - wg.Done() }(i) } @@ -241,12 +233,11 @@ func main() { ## Credits - * [Fatih Arslan](https://github.com/fatih) - * [Arne Hormann](https://github.com/arnehormann) - * [Sam Boyer](https://github.com/sdboyer) - * [Ralph Loizzo](https://github.com/friartech) +* [Fatih Arslan](https://github.com/fatih) +* [Arne Hormann](https://github.com/arnehormann) +* [Sam Boyer](https://github.com/sdboyer) +* [Ralph Loizzo](https://github.com/friartech) ## License The MIT License (MIT) - see LICENSE.md for more details - diff --git a/vendor/gopkg.in/fatih/set.v0/set.go b/vendor/github.com/fatih/set/set.go similarity index 84% rename from vendor/gopkg.in/fatih/set.v0/set.go rename to vendor/github.com/fatih/set/set.go index ac0240ce..0a31e268 100644 --- a/vendor/gopkg.in/fatih/set.v0/set.go +++ b/vendor/github.com/fatih/set/set.go @@ -5,9 +5,26 @@ // between the start and the end of the operation. package set +// SetType denotes which type of set is created. ThreadSafe or NonThreadSafe +type SetType int + +const ( + ThreadSafe = iota + NonThreadSafe +) + +func (s SetType) String() string { + switch s { + case ThreadSafe: + return "ThreadSafe" + case NonThreadSafe: + return "NonThreadSafe" + } + return "" +} + // Interface is describing a Set. Sets are an unordered, unique list of values. type Interface interface { - New(items ...interface{}) Interface Add(items ...interface{}) Remove(items ...interface{}) Pop() interface{} @@ -29,6 +46,16 @@ type Interface interface { // helpful to not write everywhere struct{}{} var keyExists = struct{}{} +// New creates and initalizes a new Set interface. Its single parameter +// denotes the type of set to create. Either ThreadSafe or +// NonThreadSafe. The default is ThreadSafe. +func New(settype SetType) Interface { + if settype == NonThreadSafe { + return newNonTS() + } + return newTS() +} + // Union is the merger of multiple sets. It returns a new set with all the // elements present in all the sets that are passed. // diff --git a/vendor/gopkg.in/fatih/set.v0/set_nots.go b/vendor/github.com/fatih/set/set_nots.go similarity index 87% rename from vendor/gopkg.in/fatih/set.v0/set_nots.go rename to vendor/github.com/fatih/set/set_nots.go index ec1ab228..562971a1 100644 --- a/vendor/gopkg.in/fatih/set.v0/set_nots.go +++ b/vendor/github.com/fatih/set/set_nots.go @@ -15,27 +15,17 @@ type SetNonTS struct { set } -// NewNonTS creates and initialize a new non-threadsafe Set. -// It accepts a variable number of arguments to populate the initial set. -// If nothing is passed a SetNonTS with zero size is created. -func NewNonTS(items ...interface{}) *SetNonTS { +// NewNonTS creates and initializes a new non-threadsafe Set. +func newNonTS() *SetNonTS { s := &SetNonTS{} s.m = make(map[interface{}]struct{}) // Ensure interface compliance var _ Interface = s - s.Add(items...) return s } -// New creates and initalizes a new Set interface. It accepts a variable -// number of arguments to populate the initial set. If nothing is passed a -// zero size Set based on the struct is created. -func (s *set) New(items ...interface{}) Interface { - return NewNonTS(items...) -} - // Add includes the specified items (one or more) to the set. The underlying // Set s is modified. If passed nothing it silently returns. func (s *set) Add(items ...interface{}) { @@ -152,6 +142,15 @@ func (s *set) Each(f func(item interface{}) bool) { } } +// Copy returns a new Set with a copy of s. +func (s *set) Copy() Interface { + u := newNonTS() + for item := range s.m { + u.Add(item) + } + return u +} + // String returns a string representation of s func (s *set) String() string { t := make([]string, 0, len(s.List())) @@ -174,11 +173,6 @@ func (s *set) List() []interface{} { return list } -// Copy returns a new Set with a copy of s. -func (s *set) Copy() Interface { - return NewNonTS(s.List()...) -} - // Merge is like Union, however it modifies the current set it's applied on // with the given t set. func (s *set) Merge(t Interface) { diff --git a/vendor/gopkg.in/fatih/set.v0/set_ts.go b/vendor/github.com/fatih/set/set_ts.go similarity index 91% rename from vendor/gopkg.in/fatih/set.v0/set_ts.go rename to vendor/github.com/fatih/set/set_ts.go index 50f53256..3a4e02a6 100644 --- a/vendor/gopkg.in/fatih/set.v0/set_ts.go +++ b/vendor/github.com/fatih/set/set_ts.go @@ -1,8 +1,6 @@ package set -import ( - "sync" -) +import "sync" // Set defines a thread safe set data structure. type Set struct { @@ -13,24 +11,16 @@ type Set struct { // New creates and initialize a new Set. It's accept a variable number of // arguments to populate the initial set. If nothing passed a Set with zero // size is created. -func New(items ...interface{}) *Set { +func newTS() *Set { s := &Set{} s.m = make(map[interface{}]struct{}) // Ensure interface compliance var _ Interface = s - s.Add(items...) return s } -// New creates and initalizes a new Set interface. It accepts a variable -// number of arguments to populate the initial set. If nothing is passed a -// zero size Set based on the struct is created. -func (s *Set) New(items ...interface{}) Interface { - return New(items...) -} - // Add includes the specified items (one or more) to the set. The underlying // Set s is modified. If passed nothing it silently returns. func (s *Set) Add(items ...interface{}) { @@ -184,7 +174,11 @@ func (s *Set) List() []interface{} { // Copy returns a new Set with a copy of s. func (s *Set) Copy() Interface { - return New(s.List()...) + u := newTS() + for item := range s.m { + u.Add(item) + } + return u } // Merge is like Union, however it modifies the current set it's applied on