Debian Codegraph @

pdata/pcommon/generated_int64slice.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 // Int64Slice represents a []int64 slice.
17 // The instance of Int64Slice can be assigned to multiple objects since it's immutable.
18 //
19 // Must use NewInt64Slice function to create new instances.
20 // Important: zero-initialized instance is not valid for use.
21 type Int64Slice internal.Int64SliceWrapper
22
23 func (ms Int64Slice) getOrig() *[]int64 {
24 return internal.GetInt64SliceOrig(internal.Int64SliceWrapper(ms))
25 }
26
27 func (ms Int64Slice) getState() *internal.State {
28 return internal.GetInt64SliceState(internal.Int64SliceWrapper(ms))
29 }
30
31 // NewInt64Slice creates a new empty Int64Slice.
32 func NewInt64Slice() Int64Slice {
33 orig := []int64(nil)
34 return Int64Slice(internal.NewInt64SliceWrapper(&orig, internal.NewState()))
35 }
36
37 // AsRaw returns a copy of the []int64 slice.
38 func (ms Int64Slice) AsRaw() []int64 {
39 return copyInt64Slice(nil, *ms.getOrig())
40 }
41
42 // FromRaw copies raw []int64 into the slice Int64Slice.
43 func (ms Int64Slice) FromRaw(val []int64) {
44 ms.getState().AssertMutable()
45 *ms.getOrig() = copyInt64Slice(*ms.getOrig(), val)
46 }
47
48 // Len returns length of the []int64 slice value.
49 // Equivalent of len(int64Slice).
50 func (ms Int64Slice) Len() int {
51 return len(*ms.getOrig())
52 }
53
54 // At returns an item from particular index.
55 // Equivalent of int64Slice[i].
56 func (ms Int64Slice) At(i int) int64 {
57 return (*ms.getOrig())[i]
58 }
59
60 // All returns an iterator over index-value pairs in the slice.
61 func (ms Int64Slice) All() iter.Seq2[int, int64] {
62 return func(yield func(int, int64) 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 int64 item at particular index.
72 // Equivalent of int64Slice[i] = val
73 func (ms Int64Slice) SetAt(i int, val int64) {
74 ms.getState().AssertMutable()
75 (*ms.getOrig())[i] = val
76 }
77
78 // EnsureCapacity ensures Int64Slice 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([]int64, len(int64Slice), newCap)
82 // copy(buf, int64Slice)
83 // int64Slice = buf
84 func (ms Int64Slice) EnsureCapacity(newCap int) {
85 ms.getState().AssertMutable()
86 oldCap := cap(*ms.getOrig())
87 if newCap <= oldCap {
88 return
89 }
90
91 newOrig := make([]int64, len(*ms.getOrig()), newCap)
92 copy(newOrig, *ms.getOrig())
93 *ms.getOrig() = newOrig
94 }
95
96 // Append appends extra elements to Int64Slice.
97 // Equivalent of int64Slice = append(int64Slice, elms...)
98 func (ms Int64Slice) Append(elms ...int64) {
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 Int64Slice) MoveTo(dest Int64Slice) {
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 Int64Slice) MoveAndAppendTo(dest Int64Slice) {
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 Int64Slice) RemoveIf(f func(int64) 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 int64
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 Int64Slice) CopyTo(dest Int64Slice) {
154 dest.getState().AssertMutable()
155 if ms.getOrig() == dest.getOrig() {
156 return
157 }
158 *dest.getOrig() = copyInt64Slice(*dest.getOrig(), *ms.getOrig())
159 }
160
161 // Equal checks equality with another Int64Slice
162 func (ms Int64Slice) Equal(val Int64Slice) bool {
163 return slices.Equal(*ms.getOrig(), *val.getOrig())
164 }
165
166 func copyInt64Slice(dst, src []int64) []int64 {
167 return append(dst[:0], src...)
168 }