// Weight is an optional functional argument that sets weight of the server
17636
func Weight(w int) ServerOption {
	return func(s *server) error {
		if w < 0 {
			return fmt.Errorf("Weight should be >= 0")
		}
		s.weight = w
		return nil
	}
}
828559
func AddWeight(e Expr, weights []float32, words []string) {
	if len(weights) != len(words) {
		panic("weight and words must be the same length")
	}

	for i, w := range weights {
		e.Add(w, words[i])
	}
}
910619
func weightExp(x, base float64) float64 {
	return (math.Pow(base, x) - 1) / (math.Pow(base, 1) - 1)
}
204686
func NewWeightdeviceOpt(validator ValidatorWeightFctType) WeightdeviceOpt {
	values := []*blkiodev.WeightDevice{}
	return WeightdeviceOpt{
		values:    values,
		validator: validator,
	}
}
525410
func (s *EndpointConfiguration) SetWeight(v int64) *EndpointConfiguration {
	s.Weight = &v
	return s
}
381236
func sortByHookWeight(hooks []*release.Hook) []*release.Hook {
	hs := newHookWeightSorter(hooks)
	sort.Sort(hs)
	return hs.hooks
}
1136263
func (s *ResourceRecordSet) SetWeight(v int64) *ResourceRecordSet {
	s.Weight = &v
	return s
}
10181
func (e *Edge) WeightValue() int64 {
	if e.WeightDiv == 0 {
		return e.Weight
	}
	return e.Weight / e.WeightDiv
}
551221
func GetWeights(query map[string]string, lastModifiedSince string) (*Weights, string, error) {
	weights := new(Weights)

	if lastModified, err := executeRequest("weights", query, lastModifiedSince, &weights); err != nil {
		return nil, "", err
	} else {
		return weights, lastModified, nil
	}
}
137050
func (ctx *Context) updateBackend(vsID, rsID string, weight int32) (int32, error) {
	rs, exists := ctx.backends[rsID]

	if !exists {
		return 0, ErrObjectNotFound
	}

	log.Infof("updating backend [%s/%s] with weight: %d", vsID, rsID,
		weight)

	if err := ctx.ipvs.UpdateDestPort(
		rs.service.options.host.String(),
		rs.service.options.Port,
		rs.options.host.String(),
		rs.options.Port,
		rs.service.options.protocol,
		weight,
		rs.options.methodID,
	); err != nil {
		log.Errorf("error while updating backend [%s/%s]", vsID, rsID)
		return 0, ErrIpvsSyscallFailed
	}

	var result int32

	// Save the old backend weight and update the current backend weight.
	result, rs.options.Weight = rs.options.Weight, weight

	// Currently the backend options are changing only the weight.
	// The weight value is set to the value requested at the first setting,
	// and the weight value is updated when the pulse fails in the gorb.
	// In kvstore, it seems correct to record the request at the first setting and
	// not reflect the updated weight value.
	//if ctx.store != nil {
	//	ctx.store.UpdateBackend(vsID, rsID, rs.options)
	//}

	return result, nil
}
793682
func (mat *T) Scaled(f float32) T {
	r := *mat
	return *r.Scale(f)
}
639760
func (fn *FieldValueFactorFunction) Weight(weight float64) *FieldValueFactorFunction {
	fn.weight = &weight
	return fn
}
682634
func (a *AlgorithmDefault) WeightingRelation(
	word1ID int,
	word2ID int,
	rank *Rank,
) float32 {
	relationQty := rank.Relation.Node[word1ID][word2ID].Qty

	return float32(relationQty)
}
1213513
func (s *SampledHTTPRequest) SetWeight(v int64) *SampledHTTPRequest {
	s.Weight = &v
	return s
}
680576
func (s *Server) Stats() map[string]map[string]string {
	toString := func(v uint64) string {
		return strconv.FormatUint(v, 10)
	}
	stats := map[string]map[string]string{
		"nomad": {
			"server":        "true",
			"leader":        fmt.Sprintf("%v", s.IsLeader()),
			"leader_addr":   string(s.raft.Leader()),
			"bootstrap":     fmt.Sprintf("%v", s.config.Bootstrap),
			"known_regions": toString(uint64(len(s.peers))),
		},
		"raft":    s.raft.Stats(),
		"serf":    s.serf.Stats(),
		"runtime": stats.RuntimeStats(),
		"vault":   s.vault.Stats(),
	}

	return stats
}
1134559
func (s *ECSTaskSet) SetTrafficWeight(v float64) *ECSTaskSet {
	s.TrafficWeight = &v
	return s
}
473836
func (g *GSLB) AddGSLBServer(server *GSLBServer) {
	var isExist = false
	for i := range g.Settings.GSLB.Servers {
		if g.Settings.GSLB.Servers[i].IPAddress == server.IPAddress {
			g.Settings.GSLB.Servers[i].Enabled = server.Enabled
			g.Settings.GSLB.Servers[i].Weight = server.Weight
			isExist = true
		}
	}

	if !isExist {
		g.Settings.GSLB.Servers = append(g.Settings.GSLB.Servers, *server)
	}
}