set: introduce set union #2

merged
opened by oppi.li targeting main from push-soqmukrvport
Changed files
+12
+12
set.go
···
package hashset
+
import (
+
"maps"
+
)
+
type Set[T comparable] map[T]struct{}
// New creates and returns a new empty Set.
···
func (s Set[T]) Size() int {
return len(s)
}
+
+
// Union returns a new set containing all elements from s and other.
+
func (s Set[T]) Union(other Set[T]) Set[T] {
+
result := make(Set[T], len(s)+len(other))
+
maps.Copy(result, s)
+
maps.Copy(result, other)
+
return result
+
}