Skip to content

Commit 3a36ffa

Browse files
committed
Merge branch 'spakin-master'
2 parents a4b9a94 + a0663d7 commit 3a36ffa

File tree

7 files changed

+28
-11
lines changed

7 files changed

+28
-11
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[![Build Status](https://travis-ci.org/deckarep/golang-set.svg?branch=master)](https://travis-ci.org/deckarep/golang-set)
2+
[![Go Report Card](https://goreportcard.com/badge/github.com/deckarep/golang-set)](https://goreportcard.com/report/github.com/deckarep/golang-set)
23
[![GoDoc](https://godoc.org/github.com/deckarep/golang-set?status.svg)](http://godoc.org/github.com/deckarep/golang-set)
34

45
## golang-set

bench_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ func benchString(b *testing.B, n int, s Set) {
587587

588588
b.ResetTimer()
589589
for i := 0; i < b.N; i++ {
590-
s.String()
590+
_ = s.String()
591591
}
592592
}
593593

iterator_example_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func ExampleIterator() {
1616
&YourType{Name: "Nick"},
1717
})
1818

19-
var found *YourType = nil
19+
var found *YourType
2020
it := set.Iterator()
2121

2222
for elem := range it.C {

set.go

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,16 @@ SOFTWARE.
2828
// typical set operations: membership testing, intersection, union,
2929
// difference, symmetric difference and cloning.
3030
//
31-
// Package mapset provides two implementations. The default
32-
// implementation is safe for concurrent access. There is a non-threadsafe
33-
// implementation which is slightly more performant.
31+
// Package mapset provides two implementations of the Set
32+
// interface. The default implementation is safe for concurrent
33+
// access, but a non-thread-safe implementation is also provided for
34+
// programs that can benefit from the slight speed improvement and
35+
// that can enforce mutual exclusion through other means.
3436
package mapset
3537

38+
// Set is the primary interface provided by the mapset package. It
39+
// represents an unordered set of data and a large number of
40+
// operations that can be applied to that set.
3641
type Set interface {
3742
// Adds an element to the set. Returns whether
3843
// the item was added.
@@ -42,7 +47,7 @@ type Set interface {
4247
Cardinality() int
4348

4449
// Removes all elements from the set, leaving
45-
// the emtpy set.
50+
// the empty set.
4651
Clear()
4752

4853
// Returns a clone of the set using the same
@@ -163,7 +168,8 @@ type Set interface {
163168
ToSlice() []interface{}
164169
}
165170

166-
// Creates and returns a reference to an empty set.
171+
// NewSet creates and returns a reference to an empty set. Operations
172+
// on the resulting set are thread-safe.
167173
func NewSet(s ...interface{}) Set {
168174
set := newThreadSafeSet()
169175
for _, item := range s {
@@ -172,22 +178,29 @@ func NewSet(s ...interface{}) Set {
172178
return &set
173179
}
174180

175-
// Creates and returns a new set with the given elements
181+
// NewSetWith creates and returns a new set with the given elements.
182+
// Operations on the resulting set are thread-safe.
176183
func NewSetWith(elts ...interface{}) Set {
177184
return NewSetFromSlice(elts)
178185
}
179186

180-
// Creates and returns a reference to a set from an existing slice
187+
// NewSetFromSlice creates and returns a reference to a set from an
188+
// existing slice. Operations on the resulting set are thread-safe.
181189
func NewSetFromSlice(s []interface{}) Set {
182190
a := NewSet(s...)
183191
return a
184192
}
185193

194+
// NewThreadUnsafeSet creates and returns a reference to an empty set.
195+
// Operations on the resulting set are not thread-safe.
186196
func NewThreadUnsafeSet() Set {
187197
set := newThreadUnsafeSet()
188198
return &set
189199
}
190200

201+
// NewThreadUnsafeSetFromSlice creates and returns a reference to a
202+
// set from an existing slice. Operations on the resulting set are
203+
// not thread-safe.
191204
func NewThreadUnsafeSetFromSlice(s []interface{}) Set {
192205
a := NewThreadUnsafeSet()
193206
for _, item := range s {

set_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ func Test_CartesianProduct(t *testing.T) {
10311031
d = empty.CartesianProduct(b)
10321032

10331033
if c.Cardinality() != 0 || d.Cardinality() != 0 {
1034-
t.Error("Cartesian product of any set and the emtpy set Ax0 || 0xA must be the empty set")
1034+
t.Error("Cartesian product of any set and the empty set Ax0 || 0xA must be the empty set")
10351035
}
10361036
}
10371037

threadsafe_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ func Test_StringConcurrent(t *testing.T) {
364364
wg.Add(len(ints))
365365
for range ints {
366366
go func() {
367-
s.String()
367+
_ = s.String()
368368
wg.Done()
369369
}()
370370
}

threadunsafe.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535

3636
type threadUnsafeSet map[interface{}]struct{}
3737

38+
// An OrderedPair represents a 2-tuple of values.
3839
type OrderedPair struct {
3940
First interface{}
4041
Second interface{}
@@ -44,6 +45,7 @@ func newThreadUnsafeSet() threadUnsafeSet {
4445
return make(threadUnsafeSet)
4546
}
4647

48+
// Equal says whether two 2-tuples contain the same values in the same order.
4749
func (pair *OrderedPair) Equal(other OrderedPair) bool {
4850
if pair.First == other.First &&
4951
pair.Second == other.Second {
@@ -218,6 +220,7 @@ func (set *threadUnsafeSet) String() string {
218220
return fmt.Sprintf("Set{%s}", strings.Join(items, ", "))
219221
}
220222

223+
// String outputs a 2-tuple in the form "(A, B)".
221224
func (pair OrderedPair) String() string {
222225
return fmt.Sprintf("(%v, %v)", pair.First, pair.Second)
223226
}

0 commit comments

Comments
 (0)