18
19
// NewMapCounter creates a mapCounter that also tracks the top K entries.
21
>
return &mapCounter{
22
>
m: make(map[string]int),
23
>
limit: limit,
24
>
}
25
>
}
26
28
>
c, _ := m.getPassWithOverflow(key, base, inc)
29
>
return c
30
>
}
31
33
>
if idx, ok := m.m[key]; ok {
35
>
count := max(base, prev+inc)
36
>
// inline simple case of updateHeap
37
>
m.heap[idx].Count = count
38
>
heap.Fix(m, idx)
39
>
return count, false
40
>
}
41
// not present, fall back to full updateHeap
43
>
return count, m.updateHeap(key, count)
44
}
45