You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
432 B

package genutils
type Set[T comparable] struct {
m map[T]bool
a []T
}
func (set *Set[T]) Add(values ...T) {
if set.m == nil {
set.m = make(map[T]bool, len(values)*4)
}
for _, value := range values {
if set.m[value] {
continue
}
set.m[value] = true
set.a = append(set.a, value)
}
}
func (set *Set[T]) Len() int {
return len(set.a)
}
func (set *Set[T]) Values() []T {
return set.a[:len(set.a):len(set.a)]
}