feat: Set struct uses empty struct as value (#55)

This commit is contained in:
IceCafeCup authored and GitHub committed 2022-08-13 12:39:30 +08:00
1 parent fbf251d805
commit c95db23d2c
1 file changed
+2 -2
+2 -2
View File
@@ -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{}{}
}
}