aboutsummaryrefslogtreecommitdiffstats
path: root/library/go/slices/equal.go
diff options
context:
space:
mode:
authorqrort <qrort@yandex-team.com>2022-11-30 23:47:12 +0300
committerqrort <qrort@yandex-team.com>2022-11-30 23:47:12 +0300
commit22f8ae0e3f5d68b92aecccdf96c1d841a0334311 (patch)
treebffa27765faf54126ad44bcafa89fadecb7a73d7 /library/go/slices/equal.go
parent332b99e2173f0425444abb759eebcb2fafaa9209 (diff)
downloadydb-22f8ae0e3f5d68b92aecccdf96c1d841a0334311.tar.gz
validate canons without yatest_common
Diffstat (limited to 'library/go/slices/equal.go')
-rw-r--r--library/go/slices/equal.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/library/go/slices/equal.go b/library/go/slices/equal.go
new file mode 100644
index 0000000000..3c698c7865
--- /dev/null
+++ b/library/go/slices/equal.go
@@ -0,0 +1,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]