// calculate is called when an ack for a bdp ping is received.
// Here we calculate the current bdp and bandwidth sample and
// decide if the flow control windows should go up.
173494
func (b *bdpEstimator) calculate(d [8]byte) {
	// Check if the ping acked for was the bdp ping.
	if bdpPing.data != d {
		return
	}
	b.mu.Lock()
	rttSample := time.Since(b.sentAt).Seconds()
	if b.sampleCount < 10 {
		// Bootstrap rtt with an average of first 10 rtt samples.
		b.rtt += (rttSample - b.rtt) / float64(b.sampleCount)
	} else {
		// Heed to the recent past more.
		b.rtt += (rttSample - b.rtt) * float64(alpha)
	}
	b.isSent = false
	// The number of bytes accumulated so far in the sample is smaller
	// than or equal to 1.5 times the real BDP on a saturated connection.
	bwCurrent := float64(b.sample) / (b.rtt * float64(1.5))
	if bwCurrent > b.bwMax {
		b.bwMax = bwCurrent
	}
	// If the current sample (which is smaller than or equal to the 1.5 times the real BDP) is
	// greater than or equal to 2/3rd our perceived bdp AND this is the maximum bandwidth seen so far, we
	// should update our perception of the network BDP.
	if float64(b.sample) >= beta*float64(b.bdp) && bwCurrent == b.bwMax && b.bdp != bdpLimit {
		sampleFloat := float64(b.sample)
		b.bdp = uint32(gamma * sampleFloat)
		if b.bdp > bdpLimit {
			b.bdp = bdpLimit
		}
		bdp := b.bdp
		b.mu.Unlock()
		b.updateFlowControl(bdp)
		return
	}
	b.mu.Unlock()
}
126599
func (s *ServerRPC) Ping(c context.Context, req *types.PingRequest) (*types.PingResponse, error) {
	return &types.PingResponse{HyperdStats: "OK"}, nil
}
740721
func (bpf BPF) Rate(rate int8) Input {
	if bpf.In == nil {
		panic("BPF expects In to not be nil")
	}
	CheckRate(rate)
	(&bpf).defaults()
	return NewInput("BPF", rate, 0, 1, bpf.In, bpf.Freq, bpf.RQ)
}
1172897
func (a *IPRangeAllocator) Subtract(iprange *IPRange) {
	curBig := big.NewInt(0)
	curBig.SetBytes(iprange.Start)
	endBig := big.NewInt(0)
	endBig.SetBytes(iprange.End)

	for ; curBig.Cmp(endBig) < 1; curBig = curBig.Add(big.NewInt(1), curBig) {
		ip := a.bigIntToIP(curBig)
		if a.ipRange.Contains(ip) {
			a.Reserve(ip)
		}
	}
}
1223491
func (rs *ReferenceRiskService) Calculate(patientID string, fhirEndpointURL string, basisPieURL string) error {
	// Get and post the query to retrieve all of the data needed by the risk service plugins
	queryURL, err := rs.getRequiredDataQueryURL(patientID, fhirEndpointURL)
	if err != nil {
		return err
	}
	response, err := http.Get(queryURL)
	if err != nil {
		return err
	}
	defer response.Body.Close()
	bundle := &models.Bundle{}
	if err = json.NewDecoder(response.Body).Decode(bundle); err != nil {
		return err
	}

	// Convert the data bundle and significant birthdays into an EventStream
	es, err := BundleToEventStream(bundle)
	if err != nil {
		return err
	}

	// Now do the calculations for each plugin
	for _, p := range rs.plugins {
		if len(p.Config().Method.Coding) == 0 {
			return errors.New("Risk Assessment Plugins MUST provide a method with a coding")
		}

		// Copy the event stream since we'll add significant birthday events based on plugin config
		esClone := es.Clone()
		addSignificantBirthdayEvents(esClone, p.Config().SignificantBirthdays)

		// Calculate the results
		results, err := p.Calculate(esClone, fhirEndpointURL)
		if err != nil {
			if _, ok := err.(plugin.NotApplicableError); ok {
				UpdateRiskAssessmentsAndPies(fhirEndpointURL, patientID, results, rs.db.C("pies"), basisPieURL, p.Config(), true)
				continue
			} else {
				return err
			}
		}
		results = sortAndConsolidate(results)

		UpdateRiskAssessmentsAndPies(fhirEndpointURL, patientID, results, rs.db.C("pies"), basisPieURL, p.Config(), false)
	}

	return nil
}
413575
func (a512srv *Avx512Server) Sum(uid uint64, p []byte) [32]byte {
	sumCh := make(chan [32]byte)
	a512srv.blocksCh <- blockInput{uid: uid, msg: p, final: true, sumCh: sumCh}
	return <-sumCh
}
559151
func (f *Flow) Receive(pkts ...packet.Generic) *Flow {
	f.add(action{
		kind:    actionReceive,
		packets: pkts,
	})

	return f
}
1270275
func (acl *ACL) CalcMask() error {
	rv, _ := C.acl_calc_mask(&acl.a)
	if rv < 0 {
		return fmt.Errorf("unable to calculate mask")
	}
	return nil
}
1171083
func (pd *pingData) data() (float64, float64) {
	if pd.updated {
		pd.Lock()

		// Calculate the mean
		var accumulator float64
		for _, d := range pd.pings {
			accumulator += float64(d)
		}
		pd.lastMean = accumulator / float64(len(pd.pings))

		// Subtract the mean and square the result; calculcate the mean
		accumulator = 0.0 // Reusing accumulator.
		for _, d := range pd.pings {
			diff := pd.lastMean - float64(d)
			accumulator += math.Pow(diff, 2.0)
		}
		squareDiffMean := accumulator / float64(len(pd.pings))

		// Sqrt the square diffs mean and we have our stddev
		pd.lastStddev = math.Sqrt(squareDiffMean)

		pd.updated = false

		pd.Unlock()
	}

	return pd.lastMean, pd.lastStddev
}
1033234
func (apc Allpass) Rate(rate int8) Input {
	if apc.In == nil {
		panic("Allpass expects In to not be nil")
	}
	CheckRate(rate)

	(&apc).defaults()

	switch apc.Interpolation {
	case InterpolationNone:
		return NewInput("AllpassN", rate, 0, 1, apc.In, apc.MaxDelayTime, apc.DelayTime, apc.DecayTime)
	case InterpolationLinear:
		return NewInput("AllpassL", rate, 0, 1, apc.In, apc.MaxDelayTime, apc.DelayTime, apc.DecayTime)
	case InterpolationCubic:
		return NewInput("AllpassC", rate, 0, 1, apc.In, apc.MaxDelayTime, apc.DelayTime, apc.DecayTime)
	default:
		panic(fmt.Errorf("invalid interpolation: %d", apc.Interpolation))
	}
}
248851
func (p *Pinger) loop() error {
	for {
		select {
		case <-p.tomb.Dying():
			return errors.Trace(tomb.ErrDying)
		case <-time.After(time.Duration(float64(period+1)*0.75) * time.Second):
			if err := p.ping(); err != nil {
				return errors.Trace(err)
			}
		}
	}
}
946926
func (prof *Profiler) CalculateUsage(cur *structs.DevInfo) *structs.DevUsage {
	u := &structs.DevUsage{
		Timestamp:  cur.Timestamp,
		TimeDelta:  cur.Timestamp - prof.prior.Timestamp,
		Device: make([]structs.Device, len(cur.Device)),
	}
	for i := 0; i < len(cur.Device); i++ {
		u.Device[i].Name = cur.Device[i].Name
		u.Device[i].RBytes = cur.Device[i].RBytes - prof.prior.Device[i].RBytes
		u.Device[i].RPackets = cur.Device[i].RPackets - prof.prior.Device[i].RPackets
		u.Device[i].RErrs = cur.Device[i].RErrs - prof.prior.Device[i].RErrs
		u.Device[i].RDrop = cur.Device[i].RDrop - prof.prior.Device[i].RDrop
		u.Device[i].RFIFO = cur.Device[i].RFIFO - prof.prior.Device[i].RFIFO
		u.Device[i].RFrame = cur.Device[i].RFrame - prof.prior.Device[i].RFrame
		u.Device[i].RCompressed = cur.Device[i].RCompressed - prof.prior.Device[i].RCompressed
		u.Device[i].RMulticast = cur.Device[i].RMulticast - prof.prior.Device[i].RMulticast
		u.Device[i].TBytes = cur.Device[i].TBytes - prof.prior.Device[i].TBytes
		u.Device[i].TPackets = cur.Device[i].TPackets - prof.prior.Device[i].TPackets
		u.Device[i].TErrs = cur.Device[i].TErrs - prof.prior.Device[i].TErrs
		u.Device[i].TDrop = cur.Device[i].TDrop - prof.prior.Device[i].TDrop
		u.Device[i].TFIFO = cur.Device[i].TFIFO - prof.prior.Device[i].TFIFO
		u.Device[i].TColls = cur.Device[i].TColls - prof.prior.Device[i].TColls
		u.Device[i].TCarrier = cur.Device[i].TCarrier - prof.prior.Device[i].TCarrier
		u.Device[i].TCompressed = cur.Device[i].TCompressed - prof.prior.Device[i].TCompressed
	}
	return u
}
378838
func (self *Transcoder) Do(pkt av.Packet) (out []av.Packet, err error) {
	stream := self.streams[pkt.Idx]
	if stream.aenc != nil && stream.adec != nil {
		if out, err = stream.audioDecodeAndEncode(pkt); err != nil {
			return
		}
	} else {
		out = append(out, pkt)
	}
	return
}
703371
func calculateFeeLimit(feeLimit *lnrpc.FeeLimit,
	amount lnwire.MilliSatoshi) lnwire.MilliSatoshi {

	switch feeLimit.GetLimit().(type) {
	case *lnrpc.FeeLimit_Fixed:
		return lnwire.NewMSatFromSatoshis(
			btcutil.Amount(feeLimit.GetFixed()),
		)
	case *lnrpc.FeeLimit_Percent:
		return amount * lnwire.MilliSatoshi(feeLimit.GetPercent()) / 100
	default:
		// If a fee limit was not specified, we'll use the payment's
		// amount as an upper bound in order to avoid payment attempts
		// from incurring fees higher than the payment amount itself.
		return amount
	}
}
996805
func (playbuf PlayBuf) Rate(rate int8) Input {
	CheckRate(rate)
	if playbuf.BufNum == nil {
		panic(fmt.Errorf("BufNum can not be nil"))
	}
	(&playbuf).defaults()
	done := C(float32(playbuf.Done))
	return NewInput("PlayBuf", rate, 0, playbuf.NumChannels, playbuf.BufNum, playbuf.Speed, playbuf.Trigger, playbuf.Start, playbuf.Loop, done)
}
585816
func (blp BLowPass) Rate(rate int8) Input {
	CheckRate(rate)
	(&blp).defaults()
	return NewInput("BLowPass", rate, 0, 1, blp.In, blp.Freq, blp.RQ)
}
1183222
func (e *Store) calculateTTL(obj runtime.Object, defaultTTL int64, update bool) (ttl uint64, err error) {
	// TODO: validate this is assertion is still valid.

	// etcd may return a negative TTL for a node if the expiration has not
	// occurred due to server lag - we will ensure that the value is at least
	// set.
	if defaultTTL < 0 {
		defaultTTL = 1
	}
	ttl = uint64(defaultTTL)
	if e.TTLFunc != nil {
		ttl, err = e.TTLFunc(obj, ttl, update)
	}
	return ttl, err
}