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

Function getNumericIndex

runtime/sam/expr/eval.go:706–731  ·  view source on GitHub ↗
(sctx *super.Context, index super.Value, base1 bool)

Source from the content-addressed store, hash-verified

704}
705
706func getNumericIndex(sctx *super.Context, index super.Value, base1 bool) (int, bool, *super.Value) {
707 id := index.Type().ID()
708 if super.IsUnsigned(id) {
709 index = LookupPrimitiveCaster(sctx, super.TypeInt64).Eval(index)
710 id = index.Type().ID()
711 }
712 if !super.IsInteger(index.Type().ID()) {
713 if index.IsError() {
714 return 0, false, index.Ptr()
715 }
716 return 0, false, nil
717 }
718 if index.IsNull() {
719 return 0, false, sctx.Missing().Ptr()
720 }
721 idx := int(index.AsInt())
722 if base1 {
723 if idx == 0 {
724 return -1, false, sctx.Missing().Ptr()
725 }
726 if idx > 0 {
727 idx--
728 }
729 }
730 return idx, true, nil
731}
732
733func indexArrayOrSet(sctx *super.Context, inner super.Type, vector scode.Bytes, idx int) super.Value {
734 bytes, idx := getNthFromContainer(vector, idx)

Callers 1

EvalMethod · 0.85

Calls 11

IsUnsignedFunction · 0.92
IsIntegerFunction · 0.92
LookupPrimitiveCasterFunction · 0.85
IsErrorMethod · 0.80
PtrMethod · 0.80
IsNullMethod · 0.80
MissingMethod · 0.80
AsIntMethod · 0.80
IDMethod · 0.65
TypeMethod · 0.65
EvalMethod · 0.65

Tested by

no test coverage detected