MCPcopy Create free account
hub / github.com/cogentcore/core / UpdateSliceTable

Function UpdateSliceTable

tensor/table/slicetable.go:59–78  ·  view source on GitHub ↗

UpdateSliceTable updates given Table with data from the given slice of structs, which must be the same type as used to configure the table

(st any, dt *Table)

Source from the content-addressed store, hash-verified

57// UpdateSliceTable updates given Table with data from the given slice
58// of structs, which must be the same type as used to configure the table
59func UpdateSliceTable(st any, dt *Table) {
60 npv := reflectx.NonPointerValue(reflect.ValueOf(st))
61 eltyp := reflectx.NonPointerType(npv.Type().Elem())
62
63 nr := npv.Len()
64 dt.SetNumRows(nr)
65 for ri := 0; ri < nr; ri++ {
66 for i := 0; i < eltyp.NumField(); i++ {
67 f := eltyp.Field(i)
68 switch f.Type.Kind() {
69 case reflect.Float32:
70 dt.SetFloat(f.Name, ri, float64(npv.Index(ri).Field(i).Interface().(float32)))
71 case reflect.Float64:
72 dt.SetFloat(f.Name, ri, float64(npv.Index(ri).Field(i).Interface().(float64)))
73 case reflect.String:
74 dt.SetString(f.Name, ri, npv.Index(ri).Field(i).Interface().(string))
75 }
76 }
77 }
78}

Callers

nothing calls this directly

Calls 12

NonPointerValueFunction · 0.92
NonPointerTypeFunction · 0.92
ElemMethod · 0.80
NumFieldMethod · 0.80
FieldMethod · 0.80
KindMethod · 0.80
TypeMethod · 0.65
LenMethod · 0.65
SetNumRowsMethod · 0.65
SetFloatMethod · 0.65
SetStringMethod · 0.65
IndexMethod · 0.45

Tested by

no test coverage detected