From c95db23d2cbb2c1c84179db8310905e021fca997 Mon Sep 17 00:00:00 2001 From: IceCafeCup Date: Sat, 13 Aug 2022 12:39:30 +0800 Subject: [PATCH] feat: Set struct uses empty struct as value (#55) --- datastructure/set/set.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/datastructure/set/set.go b/datastructure/set/set.go index 6eabffa..4b351e7 100644 --- a/datastructure/set/set.go +++ b/datastructure/set/set.go @@ -1,7 +1,7 @@ package datastructure // Set is a data container, like slice, but element of set is not duplicate -type Set[T comparable] map[T]bool +type Set[T comparable] map[T]struct{} // NewSet return a instance of set func NewSet[T comparable](values ...T) Set[T] { @@ -13,7 +13,7 @@ func NewSet[T comparable](values ...T) Set[T] { // Add value to set func (s Set[T]) Add(values ...T) { for _, v := range values { - s[v] = true + s[v] = struct{}{} } }