(arrays ...*collections.FloatArray)
| 20 | import "github.com/lindb/lindb/pkg/collections" |
| 21 | |
| 22 | func 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 | } |