github.com/avahowell/sia@v0.5.1-beta.0.20160524050156-83dcc3d37c94/modules/renter/hostdb/hostweight.go (about)

     1  package hostdb
     2  
     3  import (
     4  	"math/big"
     5  
     6  	"github.com/NebulousLabs/Sia/types"
     7  )
     8  
     9  var (
    10  	// Because most weights would otherwise be fractional, we set the base
    11  	// weight to 10^80 to give ourselves lots of precision when determing the
    12  	// weight of a host
    13  	baseWeight = types.NewCurrency(new(big.Int).Exp(big.NewInt(10), big.NewInt(150), nil))
    14  )
    15  
    16  // calculateHostWeight returns the weight of a host according to the settings of
    17  // the host database entry. Currently, only the price is considered.
    18  func calculateHostWeight(entry hostEntry) (weight types.Currency) {
    19  	// If the price is 0, just return the base weight to avoid divide by zero.
    20  	price := entry.ContractPrice
    21  	if price.IsZero() {
    22  		return baseWeight
    23  	}
    24  
    25  	// Divide the base weight by the price to the fifth power.
    26  	return baseWeight.Div(price).Div(price).Div(price).Div(price).Div(price)
    27  }