WIP: set container using 1.18 generics
This commit is contained in:
parent
19860f713c
commit
f4316cc13a
28
container/set/interface.go
Normal file
28
container/set/interface.go
Normal file
@ -0,0 +1,28 @@
|
||||
package set
|
||||
|
||||
var x = struct{}{}
|
||||
|
||||
type Set map[any]struct{}
|
||||
|
||||
func (s *Set) Init() {
|
||||
for k := range *s {
|
||||
delete(*s, k)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Set) Add(e any) {
|
||||
(*s)[e] = x
|
||||
}
|
||||
|
||||
func (s *Set) Remove(e any) {
|
||||
delete(*s, e)
|
||||
}
|
||||
|
||||
func (s *Set) Contains(e any) bool {
|
||||
_, c := (*s)[e]
|
||||
return c
|
||||
}
|
||||
|
||||
func New() *Set {
|
||||
return new(Set)
|
||||
}
|
Loading…
Reference in New Issue
Block a user