mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-12 16:52:29 +08:00
feat: Set struct uses empty struct as value (#55)
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
package datastructure
|
package datastructure
|
||||||
|
|
||||||
// Set is a data container, like slice, but element of set is not duplicate
|
// 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
|
// NewSet return a instance of set
|
||||||
func NewSet[T comparable](values ...T) Set[T] {
|
func NewSet[T comparable](values ...T) Set[T] {
|
||||||
@@ -13,7 +13,7 @@ func NewSet[T comparable](values ...T) Set[T] {
|
|||||||
// Add value to set
|
// Add value to set
|
||||||
func (s Set[T]) Add(values ...T) {
|
func (s Set[T]) Add(values ...T) {
|
||||||
for _, v := range values {
|
for _, v := range values {
|
||||||
s[v] = true
|
s[v] = struct{}{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user