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

Function NormalizeSet

complex.go:279–299  ·  view source on GitHub ↗

NormalizeSet interprets zv as a set body and returns an equivalent set body that is normalized according to the BSUP specification (i.e., each element's tag-counted value is lexicographically greater than that of the preceding element).

(zv scode.Bytes)

Source from the content-addressed store, hash-verified

277// tag-counted value is lexicographically greater than that of the preceding
278// element).
279func NormalizeSet(zv scode.Bytes) scode.Bytes {
280 elements := make([]scode.Bytes, 0, 8)
281 for it := zv.Iter(); !it.Done(); {
282 elements = append(elements, it.NextTagAndBody())
283 }
284 if len(elements) < 2 {
285 return zv
286 }
287 sort.Slice(elements, func(i, j int) bool {
288 return bytes.Compare(elements[i], elements[j]) == -1
289 })
290 norm := make(scode.Bytes, 0, len(zv))
291 norm = append(norm, elements[0]...)
292 for i := 1; i < len(elements); i++ {
293 // Skip duplicates.
294 if !bytes.Equal(elements[i], elements[i-1]) {
295 norm = append(norm, elements[i]...)
296 }
297 }
298 return norm
299}
300
301type TypeFusion struct {
302 id int

Callers 5

evalMethod · 0.92
EvalMethod · 0.92
EvalMethod · 0.92
toArrayOrSetMethod · 0.92
ResultMethod · 0.92

Calls 5

IterMethod · 0.80
NextTagAndBodyMethod · 0.80
DoneMethod · 0.45
CompareMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected