Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sidecar
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
sidecar
Commits
dc9b6472
Commit
dc9b6472
authored
Sep 26, 2021
by
suyanlong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
set collection
parent
f957a88a
Pipeline
#8063
canceled with stages
Changes
4
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
0 deletions
+56
-0
go.mod
go.mod
+1
-0
go.sum
go.sum
+4
-0
set.go
tool/set.go
+4
-0
set_test.go
tool/set_test.go
+47
-0
No files found.
go.mod
View file @
dc9b6472
...
...
@@ -46,6 +46,7 @@ require (
github.com/creasty/defaults v1.5.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davidlazar/go-crypto v0.0.0-20190912175916-7055855a373f // indirect
github.com/deckarep/golang-set v1.7.2-0.20201129021324-03b572015f8e // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.13.0 // indirect
github.com/go-playground/universal-translator v0.17.0 // indirect
...
...
go.sum
View file @
dc9b6472
...
...
@@ -106,6 +106,10 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davidlazar/go-crypto v0.0.0-20170701192655-dcfb0a7ac018/go.mod h1:rQYf4tfk5sSwFsnDg3qYaBxSjsD9S8+59vW0dKUgme4=
github.com/davidlazar/go-crypto v0.0.0-20190912175916-7055855a373f h1:BOaYiTvg8p9vBUXpklC22XSK/mifLF7lG9jtmYYi3Tc=
github.com/davidlazar/go-crypto v0.0.0-20190912175916-7055855a373f/go.mod h1:rQYf4tfk5sSwFsnDg3qYaBxSjsD9S8+59vW0dKUgme4=
github.com/deckarep/golang-set v1.7.1 h1:SCQV0S6gTtp6itiFrTqI+pfmJ4LN85S1YzhDf9rTHJQ=
github.com/deckarep/golang-set v1.7.1/go.mod h1:93vsz/8Wt4joVM7c2AVqh+YRMiUSc14yDtF28KmMOgQ=
github.com/deckarep/golang-set v1.7.2-0.20201129021324-03b572015f8e h1:cZH/C3SR4/BGzKwFwtq5PfYqbKYeJpSFw/4coUAV0/A=
github.com/deckarep/golang-set v1.7.2-0.20201129021324-03b572015f8e/go.mod h1:93vsz/8Wt4joVM7c2AVqh+YRMiUSc14yDtF28KmMOgQ=
github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218=
github.com/dgraph-io/badger v1.5.5-0.20190226225317-8115aed38f8f/go.mod h1:VZxzAIRPHRVNRKRo6AXrX9BJegn6il06VMTZVJYCIjQ=
github.com/dgraph-io/badger v1.6.0-rc1/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhYy6psNgSztDR4=
...
...
tool/set.go
0 → 100644
View file @
dc9b6472
package
tool
// The missing set collection for the Go language. Until Go has sets built-in...use this.
// https://github.com/deckarep/golang-set
tool/set_test.go
0 → 100644
View file @
dc9b6472
package
tool
import
(
"fmt"
"testing"
mapset
"github.com/deckarep/golang-set"
)
func
TestSet
(
t
*
testing
.
T
)
{
requiredClasses
:=
mapset
.
NewSet
()
requiredClasses
.
Add
(
"Cooking"
)
requiredClasses
.
Add
(
"English"
)
requiredClasses
.
Add
(
"Math"
)
requiredClasses
.
Add
(
"Biology"
)
scienceSlice
:=
[]
interface
{}{
"Biology"
,
"Chemistry"
}
scienceClasses
:=
mapset
.
NewSetFromSlice
(
scienceSlice
)
electiveClasses
:=
mapset
.
NewSet
()
electiveClasses
.
Add
(
"Welding"
)
electiveClasses
.
Add
(
"Music"
)
electiveClasses
.
Add
(
"Automotive"
)
bonusClasses
:=
mapset
.
NewSet
()
bonusClasses
.
Add
(
"Go Programming"
)
bonusClasses
.
Add
(
"Python Programming"
)
// Show me all the available classes I can take
allClasses
:=
requiredClasses
.
Union
(
scienceClasses
)
.
Union
(
electiveClasses
)
.
Union
(
bonusClasses
)
fmt
.
Println
(
allClasses
)
// Set{Cooking, English, Math, Chemistry, Welding, Biology, Music, Automotive, Go Programming, Python Programming}
// Is cooking considered a science class?
fmt
.
Println
(
scienceClasses
.
Contains
(
"Cooking"
))
// false
// Show me all classes that are not science classes, since I hate science.
fmt
.
Println
(
allClasses
.
Difference
(
scienceClasses
))
// Set{Music, Automotive, Go Programming, Python Programming, Cooking, English, Math, Welding}
// Which science classes are also required classes?
fmt
.
Println
(
scienceClasses
.
Intersect
(
requiredClasses
))
// Set{Biology}
// How many bonus classes do you offer?
fmt
.
Println
(
bonusClasses
.
Cardinality
())
// 2
// Do you have the following classes? Welding, Automotive and English?
fmt
.
Println
(
allClasses
.
IsSuperset
(
mapset
.
NewSetFromSlice
([]
interface
{}{
"Welding"
,
"Automotive"
,
"English"
})))
// 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