forked from kubernetes-sigs/aws-load-balancer-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kubernetes-sigs#3775 from alloveras/main
fixup(sg-resolver): Allow multiple SGs with the same Name tag
- Loading branch information
Showing
4 changed files
with
217 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package algorithm | ||
|
||
import "cmp" | ||
|
||
// RemoveSliceDuplicates returns a copy of the slice without duplicate entries. | ||
func RemoveSliceDuplicates[S ~[]E, E cmp.Ordered](s S) []E { | ||
result := make([]E, 0, len(s)) | ||
found := make(map[E]struct{}, len(s)) | ||
|
||
for _, x := range s { | ||
if _, ok := found[x]; !ok { | ||
found[x] = struct{}{} | ||
result = append(result, x) | ||
} | ||
} | ||
|
||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package algorithm | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_RemoveSliceDuplicates(t *testing.T) { | ||
type args struct { | ||
data []string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want []string | ||
}{ | ||
{ | ||
name: "empty", | ||
args: args{ | ||
data: []string{}, | ||
}, | ||
want: []string{}, | ||
}, | ||
{ | ||
name: "no duplicate entries", | ||
args: args{ | ||
data: []string{"a", "b", "c", "d"}, | ||
}, | ||
want: []string{"a", "b", "c", "d"}, | ||
}, | ||
{ | ||
name: "with duplicates", | ||
args: args{ | ||
data: []string{"a", "b", "a", "c", "b"}, | ||
}, | ||
want: []string{"a", "b", "c"}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got := RemoveSliceDuplicates(tt.args.data) | ||
assert.Equal(t, tt.want, got) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters