um/tag/set.go

37 lines
535 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package tag
import (
"maps"
"slices"
)
// convenience shorthand for this awkward map type.
type Set map[string]bool
// add members to the "set"
func (s Set) Add(mems ...string) {
for _, m := range mems {
s[m] = true
}
}
// get all members in a slice
func (s Set) Members() []string {
return slices.Collect(maps.Keys(s))
}
// s ∪ t
func (s Set) Union(tt ...Set) {
for _, t := range tt {
s.Add(t.Members()...)
}
}
// s ∩ t
func (s Set) Intersect(t Set) {
for m, _ := range s {
if !t[m] {
delete(s, m)
}
}
}