MCPcopy Create free account
hub / github.com/brimdata/super / evalArrayOrSlice

Method evalArrayOrSlice

runtime/vam/expr/slice.go:68–111  ·  view source on GitHub ↗
(vec, fromVec, toVec vector.Any, base1 bool)

Source from the content-addressed store, hash-verified

66}
67
68func (s *sliceExpr) evalArrayOrSlice(vec, fromVec, toVec vector.Any, base1 bool) vector.Any {
69 from, constFrom := sliceIsConstIndex(fromVec)
70 to, constTo := sliceIsConstIndex(toVec)
71 slowPath := !constFrom || !constTo
72 var index []uint32
73 n := vec.Len()
74 if view, ok := vec.(*vector.View); ok {
75 vec, index = view.Any, view.Index
76 }
77 offsets, inner := arrayOrSetContents(vec)
78 newOffsets := []uint32{0}
79 var innerIndex []uint32
80 for i := range n {
81 idx := i
82 if index != nil {
83 idx = index[i]
84 }
85 off := offsets[idx]
86 size := int(offsets[idx+1] - off)
87 start, end := 0, size
88 if fromVec != nil {
89 if slowPath {
90 from = int(vector.IntValue(fromVec, i))
91 }
92 start = sliceIndex(from, size, base1)
93 }
94 if toVec != nil {
95 if slowPath {
96 to = int(vector.IntValue(toVec, i))
97 }
98 end = sliceIndex(to, size, base1)
99 }
100 start, end = expr.FixSliceBounds(start, end, size)
101 newOffsets = append(newOffsets, newOffsets[len(newOffsets)-1]+uint32(end-start))
102 for k := start; k < end; k++ {
103 innerIndex = append(innerIndex, off+uint32(k))
104 }
105 }
106 inner = vector.Pick(inner, innerIndex)
107 if vec.Kind() == vector.KindArray {
108 return vector.NewArray(vec.Type().(*super.TypeArray), newOffsets, inner)
109 }
110 return vector.NewSet(vec.Type().(*super.TypeSet), newOffsets, inner)
111}
112
113func (s *sliceExpr) evalStringOrBytes(vec, fromVec, toVec vector.Any, base1 bool) vector.Any {
114 constFrom, isConstFrom := sliceIsConstIndex(fromVec)

Callers 1

evalMethod · 0.95

Calls 11

IntValueFunction · 0.92
FixSliceBoundsFunction · 0.92
PickFunction · 0.92
NewArrayFunction · 0.92
NewSetFunction · 0.92
sliceIsConstIndexFunction · 0.85
arrayOrSetContentsFunction · 0.85
sliceIndexFunction · 0.85
LenMethod · 0.65
KindMethod · 0.65
TypeMethod · 0.65

Tested by

no test coverage detected