|
|
@ -2,6 +2,16 @@ package set |
|
|
|
|
|
|
|
|
|
|
|
type Set[T comparable] map[T]struct{} |
|
|
|
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) { |
|
|
|
func (s Set[T]) Add(items ...T) { |
|
|
|
for _, v := range items { |
|
|
|
for _, v := range items { |
|
|
|
s[v] = struct{}{} |
|
|
|
s[v] = struct{}{} |
|
|
|