Debian Codegraph @

pdata/pcommon/generated_int32slice.go

raw
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 // Code generated by "internal/cmd/pdatagen/main.go". DO NOT EDIT.
5 // To regenerate this file run "make genpdata".
6
7 package pcommon
8
9 import (
10 "iter"
11 "slices"
12
13 "go.opentelemetry.io/collector/pdata/internal"
14 )
15
16 // Int32Slice represents a []int32 slice.
17 // The instance of Int32Slice can be assigned to multiple objects since it's immutable.
18 //
19 // Must use NewInt32Slice function to create new instances.
20 // Important: zero-initialized instance is not valid for use.
21 type Int32Slice internal.Int32SliceWrapper
22
23 func (ms Int32Slice) getOrig() *[]int32 {
24 return internal.GetInt32SliceOrig(internal.Int32SliceWrapper(ms))
25 }
26
27 func (ms Int32Slice) getState() *internal.State {
28 return internal.GetInt32SliceState(internal.Int32SliceWrapper(ms))
29 }
30
31 // NewInt32Slice creates a new empty Int32Slice.
32 func NewInt32Slice() Int32Slice {
33 orig := []int32(nil)
34 return Int32Slice(internal.NewInt32SliceWrapper(&orig, internal.NewState()))
35 }
36
37 // AsRaw returns a copy of the []int32 slice.
38 func (ms Int32Slice) AsRaw() []int32 {
39 return copyInt32Slice(nil, *ms.getOrig())
40 }
41
42 // FromRaw copies raw []int32 into the slice Int32Slice.
43 func (ms Int32Slice) FromRaw(val []int32) {
44 ms.getState().AssertMutable()
45 *ms.getOrig() = copyInt32Slice(*ms.getOrig(), val)
46 }
47
48 // Len returns length of the []int32 slice value.
49 // Equivalent of len(int32Slice).
50 func (ms Int32Slice) Len() int {
51 return len(*ms.getOrig())
52 }
53
54 // At returns an item from particular index.
55 // Equivalent of int32Slice[i].
56 func (ms Int32Slice) At(i int) int32 {
57 return (*ms.getOrig())[i]
58 }
59
60 // All returns an iterator over index-value pairs in the slice.
61 func (ms Int32Slice) All() iter.Seq2[int, int32] {
62 return func(yield func(int, int32) bool) {
63 for i := 0; i < ms.Len(); i++ {
64 if !yield(i, ms.At(i)) {
65 return
66 }
67 }
68 }
69 }
70
71 // SetAt sets int32 item at particular index.
72 // Equivalent of int32Slice[i] = val
73 func (ms Int32Slice) SetAt(i int, val int32) {
74 ms.getState().AssertMutable()
75 (*ms.getOrig())[i] = val
76 }
77
78 // EnsureCapacity ensures Int32Slice has at least the specified capacity.
79 // 1. If the newCap <= cap, then is no change in capacity.
80 // 2. If the newCap > cap, then the slice capacity will be expanded to the provided value which will be equivalent of:
81 // buf := make([]int32, len(int32Slice), newCap)
82 // copy(buf, int32Slice)
83 // int32Slice = buf
84 func (ms Int32Slice) EnsureCapacity(newCap int) {
85 ms.getState().AssertMutable()
86 oldCap := cap(*ms.getOrig())
87 if newCap <= oldCap {
88 return
89 }
90
91 newOrig := make([]int32, len(*ms.getOrig()), newCap)
92 copy(newOrig, *ms.getOrig())
93 *ms.getOrig() = newOrig
94 }
95
96 // Append appends extra elements to Int32Slice.
97 // Equivalent of int32Slice = append(int32Slice, elms...)
98 func (ms Int32Slice) Append(elms ...int32) {
99 ms.getState().AssertMutable()
100 *ms.getOrig() = append(*ms.getOrig(), elms...)
101 }
102
103 // MoveTo moves all elements from the current slice overriding the destination and
104 // resetting the current instance to its zero value.
105 func (ms Int32Slice) MoveTo(dest Int32Slice) {
106 ms.getState().AssertMutable()
107 dest.getState().AssertMutable()
108 // If they point to the same data, they are the same, nothing to do.
109 if ms.getOrig() == dest.getOrig() {
110 return
111 }
112 *dest.getOrig() = *ms.getOrig()
113 *ms.getOrig() = nil
114 }
115
116 // MoveAndAppendTo moves all elements from the current slice and appends them to the dest.
117 // The current slice will be cleared.
118 func (ms Int32Slice) MoveAndAppendTo(dest Int32Slice) {
119 ms.getState().AssertMutable()
120 dest.getState().AssertMutable()
121 if *dest.getOrig() == nil {
122 // We can simply move the entire vector and avoid any allocations.
123 *dest.getOrig() = *ms.getOrig()
124 } else {
125 *dest.getOrig() = append(*dest.getOrig(), *ms.getOrig()...)
126 }
127 *ms.getOrig() = nil
128 }
129
130 // RemoveIf calls f sequentially for each element present in the slice.
131 // If f returns true, the element is removed from the slice.
132 func (ms Int32Slice) RemoveIf(f func(int32) bool) {
133 ms.getState().AssertMutable()
134 newLen := 0
135 for i := 0; i < len(*ms.getOrig()); i++ {
136 if f((*ms.getOrig())[i]) {
137 continue
138 }
139 if newLen == i {
140 // Nothing to move, element is at the right place.
141 newLen++
142 continue
143 }
144 (*ms.getOrig())[newLen] = (*ms.getOrig())[i]
145 var zero int32
146 (*ms.getOrig())[i] = zero
147 newLen++
148 }
149 *ms.getOrig() = (*ms.getOrig())[:newLen]
150 }
151
152 // CopyTo copies all elements from the current slice overriding the destination.
153 func (ms Int32Slice) CopyTo(dest Int32Slice) {
154 dest.getState().AssertMutable()
155 if ms.getOrig() == dest.getOrig() {
156 return
157 }
158 *dest.getOrig() = copyInt32Slice(*dest.getOrig(), *ms.getOrig())
159 }
160
161 // Equal checks equality with another Int32Slice
162 func (ms Int32Slice) Equal(val Int32Slice) bool {
163 return slices.Equal(*ms.getOrig(), *val.getOrig())
164 }
165
166 func copyInt32Slice(dst, src []int32) []int32 {
167 return append(dst[:0], src...)
168 }