Skip to content

chore: implement generalized symmetric difference for set comparison #14407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 23, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use same function for all types
  • Loading branch information
Emyrk committed Aug 22, 2024
commit ed8972f3334f7e05da7dc7ba99e76cafaf1a93a1
10 changes: 2 additions & 8 deletions coderd/util/slice/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,8 @@ func Descending[T constraints.Ordered](a, b T) int {
// fmt.Println(add) // [2]
// fmt.Println(remove) // [3, 4]
func SymmetricDifference[T comparable](a, b []T) (add []T, remove []T) {
return Difference(b, a), Difference(a, b)
}

// Difference returns the elements in 'a' that are not in 'b'.
func Difference[T comparable](a []T, b []T) []T {
return DifferenceFunc(a, b, func(a, b T) bool {
return a == b
})
f := func(a, b T) bool { return a == b }
return SymmetricDifferenceFunc(a, b, f)
}

func SymmetricDifferenceFunc[T any](a, b []T, equal func(a, b T) bool) (add []T, remove []T) {
Expand Down
Loading