From 6e37678c349ca1339b7a75afb9a3b1013681d1a8 Mon Sep 17 00:00:00 2001 From: nikkiing <1031497516@qq.com> Date: Mon, 24 Apr 2023 16:15:09 +0800 Subject: [PATCH] NewSet --- pkg/set/set.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkg/set/set.go b/pkg/set/set.go index c812f96..bcd6099 100644 --- a/pkg/set/set.go +++ b/pkg/set/set.go @@ -2,6 +2,16 @@ package set type Set[T comparable] map[T]struct{} +func NewSet[T comparable]() Set[T] { + return make(map[T]struct{}) +} + +func NewSetWithItems[T comparable](items ...T) Set[T] { + s := make(Set[T]) + s.AddWithOutEmpty(items...) + return s +} + func (s Set[T]) Add(items ...T) { for _, v := range items { s[v] = struct{}{}