MCPcopy Create free account
hub / github.com/adam-hanna/arrayOperations / isEqual

Function isEqual

arrayOperations_unit_test.go:9–58  ·  view source on GitHub ↗
(a, b []T)

Source from the content-addressed store, hash-verified

7)
8
9func isEqual[T comparable](a, b []T) bool {
10 if len(a) != len(b) {
11 return false
12 }
13
14 m1 := make(map[T]int)
15 var (
16 count int
17 ok bool
18 )
19 for idx := range a {
20 count, ok = m1[a[idx]]
21 if !ok {
22 m1[a[idx]] = 1
23 } else {
24 m1[a[idx]] = count + 1
25 }
26 }
27
28 m2 := make(map[T]int)
29 for idx := range b {
30 count, ok = m2[b[idx]]
31 if !ok {
32 m2[b[idx]] = 1
33 } else {
34 m2[b[idx]] = count + 1
35 }
36 }
37
38 for k, v := range m1 {
39 count, ok = m2[k]
40 if !ok {
41 return false
42 }
43 if count != v {
44 return false
45 }
46 }
47 for k, v := range m2 {
48 count, ok = m1[k]
49 if !ok {
50 return false
51 }
52 if count != v {
53 return false
54 }
55 }
56
57 return true
58}
59
60func findOneGuard(i int) bool {
61 return i%2 == 0

Callers 4

TestDistinctFunction · 0.85
TestIntersectFunction · 0.85
TestUnionFunction · 0.85
TestDifferenceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…