...

Text file src/go/parser/testdata/metrics.go2

Documentation: go/parser/testdata

     1package metrics
     2
     3import "sync"
     4
     5type Metric1[T comparable] struct {
     6	mu sync.Mutex
     7	m  map[T]int
     8}
     9
    10func (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
    19type key2[T1, T2 comparable] struct {
    20	f1 T1
    21	f2 T2
    22}
    23
    24type Metric2[T1, T2 cmp2] struct {
    25	mu sync.Mutex
    26	m  map[key2[T1, T2]]int
    27}
    28
    29func (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
    38type key3[T1, T2, T3 comparable] struct {
    39	f1 T1
    40	f2 T2
    41	f3 T3
    42}
    43
    44type Metric3[T1, T2, T3 comparable] struct {
    45	mu sync.Mutex
    46	m  map[key3[T1, T2, T3]]int
    47}
    48
    49func (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.

View as plain text