add watch orphans

This commit is contained in:
Alexis Couvreur
2025-01-08 17:53:33 -05:00
parent 1ff2876cc8
commit 970f8b5831
6 changed files with 201 additions and 9 deletions

35
pkg/array/diff.go Normal file
View File

@@ -0,0 +1,35 @@
package array
type DiffResult[T comparable] struct {
Added []T
Removed []T
}
func Diff[T comparable](old []T, new []T) DiffResult[T] {
oldMap := make(map[T]struct{})
newMap := make(map[T]struct{})
for _, item := range old {
oldMap[item] = struct{}{}
}
for _, item := range new {
newMap[item] = struct{}{}
}
var result DiffResult[T]
for item := range newMap {
if _, found := oldMap[item]; !found {
result.Added = append(result.Added, item)
}
}
for item := range oldMap {
if _, found := newMap[item]; !found {
result.Removed = append(result.Removed, item)
}
}
return result
}