| Server IP : 217.160.0.212 / Your IP : 216.73.216.141 Web Server : Apache System : Linux www 6.18.51-i1-ampere #1196 SMP Fri Sep 11 20:43:55 CEST 2026 aarch64 User : sws1073854427 ( 1073854427) PHP Version : 8.4.23 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /lib/go/src/go/parser/testdata/ |
Upload File : |
package metrics
import "sync"
type Metric1[T comparable] struct {
mu sync.Mutex
m map[T]int
}
func (m *Metric1[T]) Add(v T) {
m.mu.Lock()
defer m.mu.Unlock()
if m.m == nil {
m.m = make(map[T]int)
}
m[v]++
}
type key2[T1, T2 comparable] struct {
f1 T1
f2 T2
}
type Metric2[T1, T2 cmp2] struct {
mu sync.Mutex
m map[key2[T1, T2]]int
}
func (m *Metric2[T1, T2]) Add(v1 T1, v2 T2) {
m.mu.Lock()
defer m.mu.Unlock()
if m.m == nil {
m.m = make(map[key2[T1, T2]]int)
}
m[key[T1, T2]{v1, v2}]++
}
type key3[T1, T2, T3 comparable] struct {
f1 T1
f2 T2
f3 T3
}
type Metric3[T1, T2, T3 comparable] struct {
mu sync.Mutex
m map[key3[T1, T2, T3]]int
}
func (m *Metric3[T1, T2, T3]) Add(v1 T1, v2 T2, v3 T3) {
m.mu.Lock()
defer m.mu.Unlock()
if m.m == nil {
m.m = make(map[key3]int)
}
m[key[T1, T2, T3]{v1, v2, v3}]++
}
// Repeat for the maximum number of permitted arguments.