WIP: set container using 1.18 generics

This commit is contained in:
Colin Henry 2022-03-28 19:39:13 -07:00
parent 19860f713c
commit f4316cc13a

View 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)
}