Debian Codegraph @

pdata/pprofile/functions.go

raw
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package pprofile // import "go.opentelemetry.io/collector/pdata/pprofile"
5
6 import (
7 "errors"
8 "math"
9 )
10
11 var errTooManyFunctionTableEntries = errors.New("too many entries in FunctionTable")
12
13 // SetFunction updates a FunctionTable, adding or providing a value and returns
14 // its index.
15 func SetFunction(table FunctionSlice, fn Function) (int32, error) {
16 for j, m := range table.All() {
17 if m.Equal(fn) {
18 if j > math.MaxInt32 {
19 return 0, errTooManyFunctionTableEntries
20 }
21 return int32(j), nil
22 }
23 }
24
25 if table.Len() >= math.MaxInt32 {
26 return 0, errTooManyFunctionTableEntries
27 }
28
29 fn.CopyTo(table.AppendEmpty())
30 return int32(table.Len() - 1), nil
31 }