MCPcopy
hub / github.com/google/mangle / Map

Function Map

ast/ast.go:384–404  ·  view source on GitHub ↗

Map constructs a map constant. Parts can only be accessed in transforms.

(kvMap map[*Constant]*Constant)

Source from the content-addressed store, hash-verified

382
383// Map constructs a map constant. Parts can only be accessed in transforms.
384func Map(kvMap map[*Constant]*Constant) *Constant {
385 m := &MapNil
386 if len(kvMap) == 0 {
387 return m
388 }
389 keys := make([]*Constant, len(kvMap))
390 vals := make([]*Constant, len(kvMap))
391 i := 0
392 for k, v := range kvMap {
393 keys[i] = k
394 vals[i] = v
395 i++
396 }
397 index := make([]int, len(kvMap))
398 SortIndexInto(keys, index)
399 for _, i := range index {
400 next := MapCons(keys[i], vals[i], m)
401 m = &next
402 }
403 return m
404}
405
406// Struct constructs a struct constant. Parts can only be accessed in transforms.
407// labels must be sorted .

Callers 6

makeMapFunction · 0.92
ProtoToStructFunction · 0.92
TestEvalApplyFnFunction · 0.92
EvalApplyFnFunction · 0.92
EvalReduceFnFunction · 0.92
ast_test.goFile · 0.85

Calls 2

SortIndexIntoFunction · 0.85
MapConsFunction · 0.85

Tested by 2

makeMapFunction · 0.74
TestEvalApplyFnFunction · 0.74