diff --git a/netmap/aggregator.go b/netmap/aggregator.go index 433a3ba..6926b84 100644 --- a/netmap/aggregator.go +++ b/netmap/aggregator.go @@ -72,12 +72,6 @@ func newMinAgg() aggregator { return new(minAgg) } -// newMeanIQRAgg returns an aggregator which -// computes mean value of values from IQR interval. -func newMeanIQRAgg() aggregator { - return new(meanIQRAgg) -} - // newReverseMinNorm returns a normalizer which // normalize values in range of 0.0 to 1.0 to a minimum value. func newReverseMinNorm(min float64) normalizer { @@ -116,6 +110,11 @@ func (a *minAgg) Compute() float64 { return a.min } +func (a *meanIQRAgg) clear() { + a.k = 0 + a.arr = a.arr[:0] +} + func (a *meanIQRAgg) Add(n float64) { a.arr = append(a.arr, n) } diff --git a/netmap/selector.go b/netmap/selector.go index d57a89d..b16e774 100644 --- a/netmap/selector.go +++ b/netmap/selector.go @@ -104,8 +104,10 @@ func (c *context) getSelection(s netmap.Selector) ([]nodes, error) { if len(c.hrwSeed) != 0 { weights := make([]float64, len(res)) + a := new(meanIQRAgg) for i := range res { - weights[i] = calcBucketWeight(res[i], newMeanIQRAgg(), c.weightFunc) + a.clear() + weights[i] = calcBucketWeight(res[i], a, c.weightFunc) } hrw.SortHasherSliceByWeightValue(res, weights, c.hrwSeedHash)