Documentation ¶
Index ¶
- type HostTree
- func (ht *HostTree) All() []modules.HostDBEntry
- func (ht *HostTree) Insert(hdbe modules.HostDBEntry) error
- func (ht *HostTree) Modify(hdbe modules.HostDBEntry) error
- func (ht *HostTree) Remove(pk types.SiaPublicKey) error
- func (ht *HostTree) Select(spk types.SiaPublicKey) (modules.HostDBEntry, bool)
- func (ht *HostTree) SelectRandom(n int, ignore []types.SiaPublicKey) []modules.HostDBEntry
- type WeightFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HostTree ¶
type HostTree struct {
// contains filtered or unexported fields
}
HostTree is used to store and select host database entries. Each HostTree is initialized with a weighting func that is able to assign a weight to each entry. The entries can then be selected at random, weighted by the weight func.
func New ¶
func New(wf WeightFunc) *HostTree
New creates a new, empty, HostTree. It takes one argument, a `WeightFunc`, which is used to determine the weight of a node on Insert.
func (*HostTree) All ¶
func (ht *HostTree) All() []modules.HostDBEntry
All returns all of the hosts in the host tree, sorted by weight.
func (*HostTree) Insert ¶
func (ht *HostTree) Insert(hdbe modules.HostDBEntry) error
Insert inserts the entry provided to `entry` into the host tree. Insert will return an error if the input host already exists.
func (*HostTree) Modify ¶
func (ht *HostTree) Modify(hdbe modules.HostDBEntry) error
Modify updates a host entry at the given public key, replacing the old entry with the entry provided by `newEntry`.
func (*HostTree) Remove ¶
func (ht *HostTree) Remove(pk types.SiaPublicKey) error
Remove removes the host with the public key provided by `pk`.
func (*HostTree) Select ¶
func (ht *HostTree) Select(spk types.SiaPublicKey) (modules.HostDBEntry, bool)
Select returns the host with the provided public key, should the host exist.
func (*HostTree) SelectRandom ¶
func (ht *HostTree) SelectRandom(n int, ignore []types.SiaPublicKey) []modules.HostDBEntry
SelectRandom grabs a random n hosts from the tree. There will be no repeats, but the length of the slice returned may be less than n, and may even be zero. The hosts that are returned first have the higher priority. Hosts passed to 'ignore' will not be considered; pass `nil` if no blacklist is desired.
type WeightFunc ¶
type WeightFunc func(modules.HostDBEntry) types.Currency
WeightFunc is a function used to weight a given HostDBEntry in the tree.