all: use set.Set consistently instead of map[T]struct{}

I didn't clean up the more idiomatic map[T]bool with true values, at
least yet.  I just converted the relatively awkward struct{}-valued
maps.

Updates #cleanup

Change-Id: I758abebd2bb1f64bc7a9d0f25c32298f4679c14f
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2023-09-09 09:55:57 -07:00
committed by Brad Fitzpatrick
parent d506a55c8a
commit dc7aa98b76
12 changed files with 40 additions and 26 deletions

View File

@@ -10,6 +10,9 @@ type Set[T comparable] map[T]struct{}
// Add adds e to the set.
func (s Set[T]) Add(e T) { s[e] = struct{}{} }
// Delete removes e from the set.
func (s Set[T]) Delete(e T) { delete(s, e) }
// Contains reports whether s contains e.
func (s Set[T]) Contains(e T) bool {
_, ok := s[e]

View File

@@ -14,6 +14,7 @@ import (
"golang.org/x/sys/windows/svc"
"golang.org/x/sys/windows/svc/mgr"
"tailscale.com/types/logger"
"tailscale.com/util/set"
)
// LogSvcState obtains the state of the Windows service named rootSvcName and
@@ -78,7 +79,7 @@ func walkServices(rootSvcName string, callback walkSvcFunc) error {
}
}()
seen := make(map[string]struct{})
seen := set.Set[string]{}
for err == nil && len(deps) > 0 {
err = func() error {
@@ -87,7 +88,7 @@ func walkServices(rootSvcName string, callback walkSvcFunc) error {
deps = deps[:len(deps)-1]
seen[curSvc.Name] = struct{}{}
seen.Add(curSvc.Name)
curCfg, err := curSvc.Config()
if err != nil {
@@ -97,7 +98,7 @@ func walkServices(rootSvcName string, callback walkSvcFunc) error {
callback(curSvc, curCfg)
for _, depName := range curCfg.Dependencies {
if _, ok := seen[depName]; ok {
if seen.Contains(depName) {
continue
}