From d71a0e0755f8f36941328ba3f3b76ff91fcba25f Mon Sep 17 00:00:00 2001 From: "andnilin@gmail.com" Date: Sat, 16 Sep 2023 17:03:38 +0300 Subject: [PATCH] [#88] netmap: use bool, fix hrw_sort tests Signed-off-by: Andrew Danilin --- netmap/aggregator.go | 19 +++++++++++-------- netmap/json_tests/hrw_sort.json | 8 ++++---- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/netmap/aggregator.go b/netmap/aggregator.go index 3365fe3..b2a9366 100644 --- a/netmap/aggregator.go +++ b/netmap/aggregator.go @@ -23,7 +23,8 @@ type ( } minAgg struct { - min *float64 + min float64 + minFound bool } meanIQRAgg struct { @@ -102,17 +103,19 @@ func (a *meanAgg) Compute() float64 { } func (a *minAgg) Add(n float64) { - if a.min == nil || n < *a.min { - a.min = &n + if !a.minFound { + a.min = n + a.minFound = true + return + } + + if n < a.min { + a.min = n } } func (a *minAgg) Compute() float64 { - if a.min == nil { - return 0 - } - - return *a.min + return a.min } func (a *meanIQRAgg) Add(n float64) { diff --git a/netmap/json_tests/hrw_sort.json b/netmap/json_tests/hrw_sort.json index 6ebeffc..8110ac7 100644 --- a/netmap/json_tests/hrw_sort.json +++ b/netmap/json_tests/hrw_sort.json @@ -146,19 +146,19 @@ "select 3 nodes in 3 distinct countries, same placement": { "policy": {"replicas":[{"count":1,"selector":"Main"}],"containerBackupFactor":1,"selectors":[{"name":"Main","count":3,"clause":"DISTINCT","attribute":"Country","filter":"*"}],"filters":[]}, "pivot": "Y29udGFpbmVySUQ=", - "result": [[4, 0, 7]], + "result": [[0, 2, 3]], "placement": { "pivot": "b2JqZWN0SUQ=", - "result": [[4, 0, 7]] + "result": [[0, 2, 3]] } }, "select 6 nodes in 3 distinct countries, different placement": { "policy": {"replicas":[{"count":1,"selector":"Main"}],"containerBackupFactor":2,"selectors":[{"name":"Main","count":3,"clause":"DISTINCT","attribute":"Country","filter":"*"}],"filters":[]}, "pivot": "Y29udGFpbmVySUQ=", - "result": [[4, 3, 0, 1, 7, 2]], + "result": [[0, 1, 2, 6, 3, 4]], "placement": { "pivot": "b2JqZWN0SUQ=", - "result": [[4, 3, 0, 7, 2, 1]] + "result": [[0, 1, 2, 6, 3, 4]] } } }