1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-04 12:52:28 +08:00

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

This commit is contained in:
IceCafeCup
2022-08-13 12:39:30 +08:00
committed by GitHub
parent fbf251d805
commit c95db23d2c

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{}{}
}
}