MCPcopy Create free account
hub / github.com/cel-expr/cel-go / costCreateMap

Method costCreateMap

checker/cost.go:623–645  ·  view source on GitHub ↗
(e ast.Expr)

Source from the content-addressed store, hash-verified

621}
622
623func (c *coster) costCreateMap(e ast.Expr) CostEstimate {
624 mapVal := e.AsMap()
625 var sum CostEstimate
626 keySize := SizeEstimate{Min: math.MaxUint64, Max: 0}
627 valSize := SizeEstimate{Min: math.MaxUint64, Max: 0}
628 if mapVal.Size() == 0 {
629 valSize.Min = 0
630 keySize.Min = 0
631 }
632 for _, ent := range mapVal.Entries() {
633 entry := ent.AsMapEntry()
634 sum = sum.Add(c.cost(entry.Key()))
635 sum = sum.Add(c.cost(entry.Value()))
636 // Compute the key size range
637 ks := c.sizeOrUnknown(entry.Key())
638 keySize = keySize.Union(ks)
639 // Compute the value size range
640 vs := c.sizeOrUnknown(entry.Value())
641 valSize = valSize.Union(vs)
642 }
643 c.setEntrySize(e, &entrySizeEstimate{containerKind: types.MapKind, key: keySize, val: valSize})
644 return sum.Add(createMapBaseCost)
645}
646
647func (c *coster) costCreateStruct(e ast.Expr) CostEstimate {
648 msgVal := e.AsStruct()

Callers 1

costMethod · 0.95

Calls 11

AddMethod · 0.95
costMethod · 0.95
sizeOrUnknownMethod · 0.95
UnionMethod · 0.95
setEntrySizeMethod · 0.95
AsMapMethod · 0.65
SizeMethod · 0.65
EntriesMethod · 0.65
AsMapEntryMethod · 0.65
KeyMethod · 0.65
ValueMethod · 0.65

Tested by

no test coverage detected