github.com/AndrienkoAleksandr/go@v0.0.19/src/go/parser/testdata/metrics.go2 (about) 1 package metrics 2 3 import "sync" 4 5 type Metric1[T comparable] struct { 6 mu sync.Mutex 7 m map[T]int 8 } 9 10 func (m *Metric1[T]) Add(v T) { 11 m.mu.Lock() 12 defer m.mu.Unlock() 13 if m.m == nil { 14 m.m = make(map[T]int) 15 } 16 m[v]++ 17 } 18 19 type key2[T1, T2 comparable] struct { 20 f1 T1 21 f2 T2 22 } 23 24 type Metric2[T1, T2 cmp2] struct { 25 mu sync.Mutex 26 m map[key2[T1, T2]]int 27 } 28 29 func (m *Metric2[T1, T2]) Add(v1 T1, v2 T2) { 30 m.mu.Lock() 31 defer m.mu.Unlock() 32 if m.m == nil { 33 m.m = make(map[key2[T1, T2]]int) 34 } 35 m[key[T1, T2]{v1, v2}]++ 36 } 37 38 type key3[T1, T2, T3 comparable] struct { 39 f1 T1 40 f2 T2 41 f3 T3 42 } 43 44 type Metric3[T1, T2, T3 comparable] struct { 45 mu sync.Mutex 46 m map[key3[T1, T2, T3]]int 47 } 48 49 func (m *Metric3[T1, T2, T3]) Add(v1 T1, v2 T2, v3 T3) { 50 m.mu.Lock() 51 defer m.mu.Unlock() 52 if m.m == nil { 53 m.m = make(map[key3]int) 54 } 55 m[key[T1, T2, T3]{v1, v2, v3}]++ 56 } 57 58 // Repeat for the maximum number of permitted arguments.