Debian Codegraph @

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