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

Method unify

runtime/sam/expr/function/defuse.go:115–138  ·  view source on GitHub ↗
(elems []super.Value)

Source from the content-addressed store, hash-verified

113}
114
115func (d *defuse) unify(elems []super.Value) (super.Type, scode.Bytes) {
116 seen := make(map[super.Type]struct{})
117 var types []super.Type
118 for _, e := range elems {
119 typ := e.Type()
120 if _, ok := seen[typ]; !ok {
121 seen[typ] = struct{}{}
122 types = append(types, typ)
123 }
124 }
125 if len(types) == 1 {
126 var b scode.Builder
127 for _, e := range elems {
128 b.Append(e.Bytes())
129 }
130 return types[0], b.Bytes()
131 }
132 var b scode.Builder
133 union := d.sctx.LookupTypeUnion(types)
134 for _, e := range elems {
135 super.BuildUnion(&b, union.TagOf(e.Type()), e.Bytes())
136 }
137 return union, b.Bytes()
138}
139
140func (d *defuse) unifyType(vals []super.Value) super.Type {
141 seen := make(map[super.Type]struct{})

Callers 1

evalMethod · 0.95

Calls 7

AppendMethod · 0.95
BytesMethod · 0.95
BuildUnionFunction · 0.92
LookupTypeUnionMethod · 0.80
TagOfMethod · 0.80
TypeMethod · 0.65
BytesMethod · 0.45

Tested by

no test coverage detected