Debian Codegraph @

pdata/pprofile/stack.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 "fmt"
8 )
9
10 // Equal checks equality with another Stack
11 func (ms Stack) Equal(val Stack) bool {
12 if ms.LocationIndices().Len() != val.LocationIndices().Len() {
13 return false
14 }
15
16 for i := range ms.LocationIndices().Len() {
17 if ms.LocationIndices().At(i) != val.LocationIndices().At(i) {
18 return false
19 }
20 }
21
22 return true
23 }
24
25 // switchDictionary updates the Stack, switching its indices from one
26 // dictionary to another.
27 func (ms Stack) switchDictionary(src, dst ProfilesDictionary) error {
28 for i, v := range ms.LocationIndices().All() {
29 if src.LocationTable().Len() < int(v) {
30 return fmt.Errorf("invalid location index %d", v)
31 }
32
33 loc := src.LocationTable().At(int(v))
34 err := loc.switchDictionary(src, dst)
35 if err != nil {
36 return fmt.Errorf("couldn't switch dictionary for location: %w", err)
37 }
38 idx, err := SetLocation(dst.LocationTable(), loc)
39 if err != nil {
40 return fmt.Errorf("couldn't set location %d: %w", i, err)
41 }
42 ms.LocationIndices().SetAt(i, idx)
43 }
44
45 return nil
46 }