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

Function Pick

vector/pick.go:9–46  ·  view source on GitHub ↗

Pick takes any vector vec and an index and returns a new vector consisting of the elements in the index.

(val Any, index []uint32)

Source from the content-addressed store, hash-verified

7// Pick takes any vector vec and an index and returns a new vector consisting of the
8// elements in the index.
9func Pick(val Any, index []uint32) Any {
10 switch val := val.(type) {
11 case *Bool:
12 return NewBool(val.Bits.Pick(index))
13 case *Const:
14 return NewConst(val.Any, uint32(len(index)))
15 case *Dict:
16 index2 := make([]byte, len(index))
17 counts := make([]uint32, val.Any.Len())
18 for k, idx := range index {
19 v := val.Index[idx]
20 index2[k] = v
21 counts[v]++
22 }
23 return NewDict(val.Any, index2, counts)
24 case *Error:
25 return NewError(val.Typ, Pick(val.Vals, index))
26 case *None:
27 return NewNoneWithError(OptType(val), NewError(val.Typ, Pick(val.Vals, index)))
28 case *Union:
29 tags, values := viewForUnionOrDynamic(index, val.Tags, val.ForwardTagMap(), val.Values)
30 return NewUnion(val.Typ, tags, values)
31 case *Dynamic:
32 return NewDynamic(viewForUnionOrDynamic(index, val.Tags, val.ForwardTagMap(), val.Values))
33 case *Optional:
34 return NewDynamic(viewForUnionOrDynamic(index, val.Tags, val.ForwardTagMap(), val.Values))
35 case *View:
36 index2 := make([]uint32, len(index))
37 for k, idx := range index {
38 index2[k] = uint32(val.Index[idx])
39 }
40 return NewView(val.Any, index2)
41 case *Named:
42 // Wrapped View under Named so vector.Under still works.
43 return &Named{val.Typ, Pick(val.Any, index)}
44 }
45 return &View{val, index}
46}
47
48func viewForUnionOrDynamic(index, tags, forward []uint32, values []Any) ([]uint32, []Any) {
49 indexes := make([][]uint32, len(values))

Callers 15

spreadMethod · 0.92
indexArrayOrSetFunction · 0.92
indexRecordFunction · 0.92
indexMapFunction · 0.92
TestCompareOpsAndFormsFunction · 0.92
evalMethod · 0.92
combineFunction · 0.92
evalMethod · 0.92
evalForListMethod · 0.92
evalMethod · 0.92
evalForListMethod · 0.92
dropMethod · 0.92

Calls 13

NewConstFunction · 0.85
NewDictFunction · 0.85
NewErrorFunction · 0.85
NewNoneWithErrorFunction · 0.85
OptTypeFunction · 0.85
viewForUnionOrDynamicFunction · 0.85
NewDynamicFunction · 0.85
NewViewFunction · 0.85
PickMethod · 0.80
ForwardTagMapMethod · 0.80
NewBoolFunction · 0.70
NewUnionFunction · 0.70

Tested by 2

TestCompareOpsAndFormsFunction · 0.74
TestArithOpsAndFormsFunction · 0.74