netmap: sort buckets by HRW value

If weights for some buckets are equal, result depends on the
initial positions of buckets in slice. Thus we sort buckets by value
using hash of the first node as a have for the whole bucket.
This is ok, because buckets are already sorted by HRW.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2021-12-24 14:31:34 +03:00 committed by Alex Vanin
parent f7582399ed
commit 3edaf9ecb6
3 changed files with 192 additions and 2 deletions

View file

@ -96,6 +96,16 @@ func (n Node) Hash() uint64 {
return n.ID
}
// Hash is a function from hrw.Hasher interface. It is implemented
// to support weighted hrw sorting of buckets. Each bucket is already sorted by hrw,
// thus giving us needed "randomness".
func (n Nodes) Hash() uint64 {
if len(n) > 0 {
return n[0].Hash()
}
return 0
}
// NodesFromInfo converts slice of NodeInfo to a generic node slice.
func NodesFromInfo(infos []NodeInfo) Nodes {
nodes := make(Nodes, len(infos))