MCPcopy
hub / github.com/grafana/tempo / get

Method get

pkg/traceql/engine_metrics_compare.go:548–564  ·  view source on GitHub ↗

get the top N values. Given as a callback to avoid allocating. bool result indicates if there were more than N values

(n int, cb func(key T))

Source from the content-addressed store, hash-verified

546// get the top N values. Given as a callback to avoid allocating.
547// bool result indicates if there were more than N values
548func (t *topN[T]) get(n int, cb func(key T)) {
549 if len(t.entries) <= n {
550 // <= N, no need to sort
551 for _, e := range t.entries {
552 cb(e.key)
553 }
554 return
555 }
556
557 sort.Slice(t.entries, func(i, j int) bool {
558 return t.entries[i].total > t.entries[j].total // Sort descending
559 })
560
561 for i := 0; i < n; i++ {
562 cb(t.entries[i].key)
563 }
564}
565
566func (t *topN[T]) reset() {
567 t.entries = t.entries[:0]

Callers 8

resultMethod · 0.45
ResultsMethod · 0.45
setFunction · 0.45
removeFunction · 0.45
getInstanceMethod · 0.45
jFunction · 0.45
sFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected