// SubGas deducts the given amount from the pool if enough gas is
// available and returns an error otherwise.
173050
func (gp *GasPool) SubGas(amount uint64) error {
	if uint64(*gp) < amount {
		return ErrGasLimitReached
	}
	*(*uint64)(gp) -= amount
	return nil
}
384114
func Sub(a, b []float64) {
	b = b[:len(a)]
	for i, v := range a {
		a[i] = v - b[i]
	}
}
1052581
func (c RGBA) Sub(d RGBA) RGBA {
	return RGBA{
		R: c.R - d.R,
		G: c.G - d.G,
		B: c.B - d.B,
		A: c.A - d.A,
	}
}
1333766
func (p *pool) Subscribe(taskID string) {
	p.Lock()
	defer p.Unlock()

	if _, exists := p.subs[taskID]; !exists {
		// Version is the last item in the key, so we split here
		// to retrieve it for the subscription.
		p.subs[taskID] = &subscription{
			TaskID:  taskID,
			Version: p.version,
		}
	}
}
645485
func (c *Websocket) Subprotocol() *String {
	s := &String{chain: c.chain}
	if c.conn != nil {
		s.value = c.conn.Subprotocol()
	}
	return s
}
353038
func (s *Server) Subsz(opts *SubszOptions) (*Subsz, error) {
	var (
		subdetail bool
		test      bool
		offset    int
		limit     = DefaultSubListSize
		testSub   = ""
	)

	if opts != nil {
		subdetail = opts.Subscriptions
		offset = opts.Offset
		if offset < 0 {
			offset = 0
		}
		limit = opts.Limit
		if limit <= 0 {
			limit = DefaultSubListSize
		}
		if opts.Test != "" {
			testSub = opts.Test
			test = true
			if !IsValidLiteralSubject(testSub) {
				return nil, fmt.Errorf("invalid test subject, must be valid publish subject: %s", testSub)
			}
		}
	}

	// FIXME(dlc) - Make account aware.
	sz := &Subsz{s.gacc.sl.Stats(), 0, offset, limit, nil}

	if subdetail {
		// Now add in subscription's details
		var raw [4096]*subscription
		subs := raw[:0]

		s.gacc.sl.localSubs(&subs)
		details := make([]SubDetail, len(subs))
		i := 0
		// TODO(dlc) - may be inefficient and could just do normal match when total subs is large and filtering.
		for _, sub := range subs {
			// Check for filter
			if test && !matchLiteral(testSub, string(sub.subject)) {
				continue
			}
			if sub.client == nil {
				continue
			}
			sub.client.mu.Lock()
			details[i] = SubDetail{
				Subject: string(sub.subject),
				Queue:   string(sub.queue),
				Sid:     string(sub.sid),
				Msgs:    sub.nm,
				Max:     sub.max,
				Cid:     sub.client.cid,
			}
			sub.client.mu.Unlock()
			i++
		}
		minoff := sz.Offset
		maxoff := sz.Offset + sz.Limit

		maxIndex := i

		// Make sure these are sane.
		if minoff > maxIndex {
			minoff = maxIndex
		}
		if maxoff > maxIndex {
			maxoff = maxIndex
		}
		sz.Subs = details[minoff:maxoff]
		sz.Total = len(sz.Subs)
	}

	return sz, nil
}
217307
func (s *storage) SubFetch(ctx context.Context, ref blob.Ref, offset, length int64) (io.ReadCloser, error) {
	// TODO: pass ctx to more calls within this method.
	m, err := s.getMetaRow(ref)
	if err != nil {
		return nil, err
	}
	if m.isPacked() {
		length, err = capOffsetLength(m.size, offset, length)
		if err != nil {
			return nil, err
		}
		// get the blob from the large subfetcher
		return s.large.SubFetch(ctx, m.largeRef, int64(m.largeOff)+offset, length)
	}
	if sf, ok := s.small.(blob.SubFetcher); ok {
		rc, err := sf.SubFetch(ctx, ref, offset, length)
		if err != blob.ErrUnimplemented {
			return rc, err
		}
	}
	rc, size, err := s.small.Fetch(ctx, ref)
	if err != nil {
		return rc, err
	}
	length, err = capOffsetLength(size, offset, length)
	if err != nil {
		rc.Close()
		return nil, err
	}
	if offset != 0 {
		if _, err = io.CopyN(ioutil.Discard, rc, offset); err != nil {
			rc.Close()
			return nil, err
		}
	}
	return struct {
		io.Reader
		io.Closer
	}{io.LimitReader(rc, length), rc}, nil
}
366958
func flattenSubnetsFromAvailabilityZones(availabilityZones []*elbv2.AvailabilityZone) []string {
	var result []string
	for _, az := range availabilityZones {
		result = append(result, aws.StringValue(az.SubnetId))
	}
	return result
}
1045308
func (p *Pool) Add(amount int) int {
	p.mutex.Lock()
	defer p.mutex.Unlock()
	max := p.max - p.counter
	if max < amount {
		amount = max
	}
	p.wg.Add(amount)
	p.counter += amount
	return amount
}
725329
func (o Timestamp) Sub(duration time.Duration) Timestamp {
	return o - Timestamp(duration/100)
}
770583
func (u Vec) Sub(v Vec) Vec {
	return Vec{
		u.X - v.X,
		u.Y - v.Y,
	}
}
508527
func (a *Allocator) ReleasePool(poolID string) error {
	logrus.Debugf("ReleasePool(%s)", poolID)
	k := SubnetKey{}
	if err := k.FromString(poolID); err != nil {
		return types.BadRequestErrorf("invalid pool id: %s", poolID)
	}

retry:
	if err := a.refresh(k.AddressSpace); err != nil {
		return err
	}

	aSpace, err := a.getAddrSpace(k.AddressSpace)
	if err != nil {
		return err
	}

	remove, err := aSpace.updatePoolDBOnRemoval(k)
	if err != nil {
		return err
	}

	if err = a.writeToStore(aSpace); err != nil {
		if _, ok := err.(types.RetryError); !ok {
			return types.InternalErrorf("pool (%s) removal failed because of %v", poolID, err)
		}
		goto retry
	}

	return remove()
}
1251565
func (c *Contract) UseGas(gas uint64) (ok bool) {
	if c.Gas < gas {
		return false
	}
	c.Gas -= gas
	return true
}
668312
func (t Time) Sub(o Time) time.Duration {
	return time.Duration(t-o) * minimumTick
}
1033366
func (nc *Conn) NumSubscriptions() int {
	nc.mu.RLock()
	defer nc.mu.RUnlock()
	return len(nc.subs)
}
601269
func (vec *T) Sub(v *T) *T {
	vec[0] -= v[0]
	vec[1] -= v[1]
	return vec
}
203456
func Sub(a, b []float64) {
	if len(a) != len(b) {
		panic("vectors must be the same length")
	}
	subAsm(a, b)
}