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