github.com/MetalBlockchain/metalgo@v1.11.9/utils/sampler/weighted.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package sampler 5 6 // Weighted defines how to sample a specified valued based on a provided 7 // weighted distribution 8 type Weighted interface { 9 Initialize(weights []uint64) error 10 Sample(sampleValue uint64) (int, bool) 11 } 12 13 // NewWeighted returns a new sampler 14 func NewWeighted() Weighted { 15 return &weightedBest{ 16 samplers: []Weighted{ 17 &weightedArray{}, 18 &weightedHeap{}, 19 &weightedUniform{ 20 maxWeight: 1024, 21 }, 22 }, 23 benchmarkIterations: 100, 24 } 25 } 26 27 func NewDeterministicWeighted() Weighted { 28 return &weightedHeap{} 29 }