aboutsummaryrefslogtreecommitdiffstats
path: root/library/go/slices/equal.go
blob: 3c698c78655c0aa2ac2d927a7cc541e7484e20aa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package slices

// EqualUnordered checks if slices of type E are equal, order independent.
func EqualUnordered[E comparable](a []E, b []E) bool {
	if len(a) != len(b) {
		return false
	}

	ma := make(map[E]struct{})
	for _, v := range a {
		ma[v] = struct{}{}
	}
	l := len(ma)
	for _, v := range b {
		ma[v] = struct{}{}
	}
	return len(ma) == l
}

// EqualAnyOrderStrings checks if string slices are equal, order independent.
// Deprecated: use EqualUnordered instead.
var EqualAnyOrderStrings = EqualUnordered[string]