Debian Codegraph @

pdata/pprofile/links.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 errTooManyLinkTableEntries = errors.New("too many entries in LinkTable")
12
13 // SetLink updates a LinkTable, adding or providing a value and returns its
14 // index.
15 func SetLink(table LinkSlice, li Link) (int32, error) {
16 for j, l := range table.All() {
17 if l.Equal(li) {
18 if j > math.MaxInt32 {
19 return 0, errTooManyLinkTableEntries
20 }
21 return int32(j), nil
22 }
23 }
24
25 if table.Len() >= math.MaxInt32 {
26 return 0, errTooManyLinkTableEntries
27 }
28
29 li.CopyTo(table.AppendEmpty())
30 return int32(table.Len() - 1), nil
31 }