Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions iterator_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ type yourType struct {

func Test_ExampleIterator(t *testing.T) {

s := NewSetFromSlice[*yourType]([]*yourType{
&yourType{name: "Alise"},
&yourType{name: "Bob"},
&yourType{name: "John"},
&yourType{name: "Nick"},
})
s := NewSet[*yourType](
[]*yourType{
&yourType{name: "Alise"},
&yourType{name: "Bob"},
&yourType{name: "John"},
&yourType{name: "Nick"},
}...,
)

var found *yourType
it := s.Iterator()
Expand Down
24 changes: 0 additions & 24 deletions set.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,19 +185,6 @@ func NewSet[T comparable](vals ...T) Set[T] {
return &s
}

// NewSetWith creates and returns a new set with the given elements.
// Operations on the resulting set are thread-safe.
func NewSetWith[T comparable](vals ...T) Set[T] {
return NewSetFromSlice(vals)
}

// NewSetFromSlice creates and returns a reference to a set from an
// existing slice. Operations on the resulting set are thread-safe.
func NewSetFromSlice[T comparable](v []T) Set[T] {
s := NewSet(v...)
return s
}

// NewThreadUnsafeSet creates and returns a new set with the given elements.
// Operations on the resulting set are not thread-safe.
func NewThreadUnsafeSet[T comparable](vals ...T) Set[T] {
Expand All @@ -207,14 +194,3 @@ func NewThreadUnsafeSet[T comparable](vals ...T) Set[T] {
}
return &s
}

// NewThreadUnsafeSetFromSlice creates and returns a reference to a
// set from an existing slice. Operations on the resulting set are
// not thread-safe.
func NewThreadUnsafeSetFromSlice[T comparable](v []T) Set[T] {
s := NewThreadUnsafeSet[T]()
for _, item := range v {
s.Add(item)
}
return s
}
12 changes: 6 additions & 6 deletions set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ func Test_NewSet(t *testing.T) {
t.Error("NewSet should start out as an empty set")
}

assertEqual(NewSetFromSlice[int]([]int{}), NewSet[int](), t)
assertEqual(NewSetFromSlice[int]([]int{1}), NewSet[int](1), t)
assertEqual(NewSetFromSlice[int]([]int{1, 2}), NewSet[int](1, 2), t)
assertEqual(NewSetFromSlice[string]([]string{"a"}), NewSet[string]("a"), t)
assertEqual(NewSetFromSlice[string]([]string{"a", "b"}), NewSet[string]("a", "b"), t)
assertEqual(NewSet([]int{}...), NewSet[int](), t)
assertEqual(NewSet([]int{1}...), NewSet(1), t)
assertEqual(NewSet([]int{1, 2}...), NewSet(1, 2), t)
assertEqual(NewSet([]string{"a"}...), NewSet("a"), t)
assertEqual(NewSet([]string{"a", "b"}...), NewSet("a", "b"), t)
}

func Test_NewUnsafeSet(t *testing.T) {
Expand Down Expand Up @@ -1105,7 +1105,7 @@ func Test_Example(t *testing.T) {
requiredClasses.Add("Biology")

scienceSlice := []interface{}{"Biology", "Chemistry"}
scienceClasses := NewSetFromSlice(scienceSlice)
scienceClasses := NewSet(scienceSlice)

electiveClasses := NewSet()
electiveClasses.Add("Welding")
Expand Down
12 changes: 6 additions & 6 deletions threadsafe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,13 +473,13 @@ func Test_ToSliceDeadlock(t *testing.T) {

func Test_UnmarshalJSON(t *testing.T) {
s := []byte(`["test", "1", "2", "3"]`) //,["4,5,6"]]`)
expected := NewSetFromSlice(
expected := NewSet(
[]string{
string(json.Number("1")),
string(json.Number("2")),
string(json.Number("3")),
"test",
},
}...,
)

actual := NewSet[string]()
Expand All @@ -494,19 +494,19 @@ func Test_UnmarshalJSON(t *testing.T) {
}

func Test_MarshalJSON(t *testing.T) {
expected := NewSetFromSlice(
expected := NewSet(
[]string{
string(json.Number("1")),
"test",
},
}...,
)

b, err := json.Marshal(
NewSetFromSlice(
NewSet(
[]string{
"1",
"test",
},
}...,
),
)
if err != nil {
Expand Down