From f4316cc13ae1dba937e737fdad1f8a1e17708577 Mon Sep 17 00:00:00 2001 From: Colin Henry Date: Mon, 28 Mar 2022 19:39:13 -0700 Subject: [PATCH] WIP: set container using 1.18 generics --- container/set/interface.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 container/set/interface.go diff --git a/container/set/interface.go b/container/set/interface.go new file mode 100644 index 0000000..eb3646c --- /dev/null +++ b/container/set/interface.go @@ -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) +}