Created
December 11, 2022 21:38
-
-
Save crhntr/d6d51d1b1eda04c82aa1e5d8ca606074 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "golang.org/x/exp/maps" | |
type Set[T comparable] map[T]struct{} | |
func (s Set[T]) Add(v T) { s[v] = struct{}{} } | |
func (s Set[T]) Remove(v T) { delete(s, v) } | |
func (s Set[T]) Has(v T) bool { _, has := s[v]; return has } | |
func (s Set[T]) List() []T { return maps.Keys(s) } | |
func (s Set[T]) IsEmpty() bool { return len(s) == 0 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment