types/views: add SliceEqual, like std slices.Equal

Updates tailscale/corp#6198

Change-Id: I38614a4552c9fa933036aa493c7cdb57c7ffe2d2
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2023-08-27 16:32:06 -07:00
committed by Brad Fitzpatrick
parent b407fdef70
commit e7d1538a2d
2 changed files with 20 additions and 0 deletions

View File

@@ -10,6 +10,7 @@ import (
"encoding/json"
"errors"
"maps"
"slices"
"go4.org/mem"
)
@@ -275,6 +276,11 @@ func SliceContains[T comparable](v Slice[T], e T) bool {
return false
}
// SliceEqual is like the standard library's slices.Equal, but for two views.
func SliceEqual[T comparable](a, b Slice[T]) bool {
return slices.Equal(a.ж, b.ж)
}
// SliceEqualAnyOrder reports whether a and b contain the same elements, regardless of order.
// The underlying slices for a and b can be nil.
func SliceEqualAnyOrder[T comparable](a, b Slice[T]) bool {