MCPcopy
hub / github.com/lindb/lindb / AvgCall

Function AvgCall

aggregation/function/avg.go:22–39  ·  view source on GitHub ↗
(arrays ...*collections.FloatArray)

Source from the content-addressed store, hash-verified

20import "github.com/lindb/lindb/pkg/collections"
21
22func AvgCall(arrays ...*collections.FloatArray) *collections.FloatArray {
23 // params: 0=>sum, 1=>count
24 if len(arrays) < 2 {
25 return nil
26 }
27 result := collections.NewFloatArray(arrays[0].Capacity())
28 itr := arrays[0].NewIterator()
29 for itr.HasNext() {
30 idx, sum := itr.Next()
31 if arrays[1].HasValue(idx) {
32 count := arrays[1].GetValue(idx)
33 if count != 0 {
34 result.SetValue(idx, sum/count)
35 }
36 }
37 }
38 return result
39}

Callers 2

funcCallMethod · 0.92
Test_AvgCallFunction · 0.85

Calls 8

HasNextMethod · 0.95
NextMethod · 0.95
SetValueMethod · 0.95
NewFloatArrayFunction · 0.92
CapacityMethod · 0.80
NewIteratorMethod · 0.65
GetValueMethod · 0.65
HasValueMethod · 0.45

Tested by 1

Test_AvgCallFunction · 0.68