Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
80d99b8d
Commit
80d99b8d
authored
Jan 20, 2015
by
Clayton Coleman
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3631 from deads2k/deads-add-set-deleteall
make StringSet.Delete accept multiple items
parents
9192a4ce
5b8e38a6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
3 deletions
+28
-3
set.go
pkg/util/set.go
+5
-3
set_test.go
pkg/util/set_test.go
+23
-0
No files found.
pkg/util/set.go
View file @
80d99b8d
...
@@ -39,9 +39,11 @@ func (s StringSet) Insert(items ...string) {
...
@@ -39,9 +39,11 @@ func (s StringSet) Insert(items ...string) {
}
}
}
}
// Delete removes item from the set.
// Delete removes all items from the set.
func
(
s
StringSet
)
Delete
(
item
string
)
{
func
(
s
StringSet
)
Delete
(
items
...
string
)
{
delete
(
s
,
item
)
for
_
,
item
:=
range
items
{
delete
(
s
,
item
)
}
}
}
// Has returns true iff item is contained in the set.
// Has returns true iff item is contained in the set.
...
...
pkg/util/set_test.go
View file @
80d99b8d
...
@@ -59,6 +59,29 @@ func TestStringSet(t *testing.T) {
...
@@ -59,6 +59,29 @@ func TestStringSet(t *testing.T) {
}
}
}
}
func
TestStringSetDeleteMultiples
(
t
*
testing
.
T
)
{
s
:=
StringSet
{}
s
.
Insert
(
"a"
,
"b"
,
"c"
)
if
len
(
s
)
!=
3
{
t
.
Errorf
(
"Expected len=3: %d"
,
len
(
s
))
}
s
.
Delete
(
"a"
,
"c"
)
if
len
(
s
)
!=
1
{
t
.
Errorf
(
"Expected len=1: %d"
,
len
(
s
))
}
if
s
.
Has
(
"a"
)
{
t
.
Errorf
(
"Unexpected contents: %#v"
,
s
)
}
if
s
.
Has
(
"c"
)
{
t
.
Errorf
(
"Unexpected contents: %#v"
,
s
)
}
if
!
s
.
Has
(
"b"
)
{
t
.
Errorf
(
"Missing contents: %#v"
,
s
)
}
}
func
TestNewStringSet
(
t
*
testing
.
T
)
{
func
TestNewStringSet
(
t
*
testing
.
T
)
{
s
:=
NewStringSet
(
"a"
,
"b"
,
"c"
)
s
:=
NewStringSet
(
"a"
,
"b"
,
"c"
)
if
len
(
s
)
!=
3
{
if
len
(
s
)
!=
3
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment