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
c07896ee
Commit
c07896ee
authored
May 04, 2015
by
Clayton Coleman
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7509 from deads2k/deads-has-any
add StringSet.HasAny
parents
93a781ff
f258717f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
0 deletions
+22
-0
set.go
pkg/util/set.go
+10
-0
set_test.go
pkg/util/set_test.go
+12
-0
No files found.
pkg/util/set.go
View file @
c07896ee
...
@@ -75,6 +75,16 @@ func (s StringSet) HasAll(items ...string) bool {
...
@@ -75,6 +75,16 @@ func (s StringSet) HasAll(items ...string) bool {
return
true
return
true
}
}
// HasAny returns true if any items are contained in the set.
func
(
s
StringSet
)
HasAny
(
items
...
string
)
bool
{
for
_
,
item
:=
range
items
{
if
s
.
Has
(
item
)
{
return
true
}
}
return
false
}
// Difference returns a set of objects that are not in s2
// Difference returns a set of objects that are not in s2
// For example:
// For example:
// s1 = {1, 2, 3}
// s1 = {1, 2, 3}
...
...
pkg/util/set_test.go
View file @
c07896ee
...
@@ -117,3 +117,15 @@ func TestStringSetDifference(t *testing.T) {
...
@@ -117,3 +117,15 @@ func TestStringSetDifference(t *testing.T) {
t
.
Errorf
(
"Unexpected contents: %#v"
,
d
.
List
())
t
.
Errorf
(
"Unexpected contents: %#v"
,
d
.
List
())
}
}
}
}
func
TestStringSetHasAny
(
t
*
testing
.
T
)
{
a
:=
NewStringSet
(
"1"
,
"2"
,
"3"
)
if
!
a
.
HasAny
(
"1"
,
"4"
)
{
t
.
Errorf
(
"expected true, got false"
)
}
if
a
.
HasAny
(
"0"
,
"4"
)
{
t
.
Errorf
(
"expected false, got true"
)
}
}
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