Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrInsufficientElements = errors.New("insufficient elements") ErrTooManyElements = errors.New("too many elements requested") )
Functions ¶
This section is empty.
Types ¶
type BestSampler ¶
type BestSampler interface {
// Sample returns the K elements with the best scores.
Sample() []ids.NodeID
// SetScore sets the score of the given element.
SetScore(nodeID ids.NodeID, score uint64)
// Clear removes all elements.
Clear()
}
BestSampler samples the K elements with the best scores.
func NewBest ¶
func NewBest(k int) BestSampler
NewBest returns a new sampler that samples the K nodes with the best scores.
type Parameters ¶
type Parameters struct {
// K is the number of nodes to poll
K int `json:"k" yaml:"k"`
// AlphaPreference is the vote threshold to change preference
AlphaPreference int `json:"alphaPreference" yaml:"alphaPreference"`
// AlphaConfidence is the vote threshold for confidence
AlphaConfidence int `json:"alphaConfidence" yaml:"alphaConfidence"`
// Beta is the number of consecutive successful polls required for finalization
Beta int `json:"beta" yaml:"beta"`
// ConcurrentRepolls is the number of concurrent polls
ConcurrentRepolls int `json:"concurrentRepolls" yaml:"concurrentRepolls"`
// OptimalProcessing is the number of items to process optimally
OptimalProcessing int `json:"optimalProcessing" yaml:"optimalProcessing"`
// MaxOutstandingItems is the maximum number of outstanding items
MaxOutstandingItems int `json:"maxOutstandingItems" yaml:"maxOutstandingItems"`
// MaxItemProcessingTime is the maximum time to process an item
MaxItemProcessingTime time.Duration `json:"maxItemProcessingTime" yaml:"maxItemProcessingTime"`
}
Parameters defines the consensus parameters for binary voting
func (Parameters) Valid ¶
func (p Parameters) Valid() error
Valid returns nil if the parameters are valid
type Sampler ¶
type Sampler interface {
// Sample returns a sample of the given size from the set.
// If there are less than [size] elements in the set, an error is returned.
Sample(size int) ([]ids.NodeID, error)
// CanSample returns whether a sample of the given size can be taken from the set.
CanSample(size int) bool
// Clear removes all elements from the sampler.
Clear()
// Add adds an element to the set.
Add(ids.NodeID)
// Len returns the number of elements in the set.
Len() int
// Weighted returns whether the sampler samples by weight.
Weighted() bool
}
Sampler samples elements from a set.
func NewDeterministicUniform ¶
NewDeterministicUniform returns a new sampler that samples uniformly with a deterministic seed.
func NewUniform ¶
func NewUniform() Sampler
NewUniform returns a new sampler that samples uniformly from the set.
type Type ¶
type Type byte
Type enumerates the different samplers that can be used.
const ( // UniformSamplerType samples uniformly from the set. UniformSamplerType Type = iota // WeightedSamplerType samples from the set with weights. WeightedSamplerType // BestSamplerType samples the K elements with the best scores. BestSamplerType // MaxSamplerType is the largest valid sampler type. MaxSamplerType = math.MaxUint8 )
type Uniform ¶
type Uniform struct {
// contains filtered or unexported fields
}
Uniform samples uniformly from a set.
func (*Uniform) CanSample ¶
CanSample returns whether a sample of the given size can be taken from the set.
type Weighted ¶
type Weighted struct {
// contains filtered or unexported fields
}
Weighted samples from a set with weights.
func (*Weighted) AddWeighted ¶
AddWeighted adds an element with the given weight to the set.
func (*Weighted) CanSample ¶
CanSample returns whether a sample of the given size can be taken from the set.
type WeightedSampler ¶
type WeightedSampler interface {
Sampler
// AddWeighted adds an element with the given weight to the set.
AddWeighted(nodeID ids.NodeID, weight uint64)
}
WeightedSampler samples elements from a set with weights.
func NewWeighted ¶
func NewWeighted() WeightedSampler
NewWeighted returns a new sampler that samples by weight.