@@ -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.
3436package 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.
3641type 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.
167173func 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.
176183func 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.
181189func 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.
186196func 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.
191204func NewThreadUnsafeSetFromSlice (s []interface {}) Set {
192205 a := NewThreadUnsafeSet ()
193206 for _ , item := range s {
0 commit comments