// nextMulti is used for iterating over multi-segment decompositions
// for decomposing normal forms.
425169
func nextMulti(i *Iter) []byte {
	j := 0
	d := i.multiSeg
	// skip first rune
	for j = 1; j < len(d) && !utf8.RuneStart(d[j]); j++ {
	}
	for j < len(d) {
		info := i.rb.f.info(input{bytes: d}, j)
		if info.BoundaryBefore() {
			i.multiSeg = d[j:]
			return d[:j]
		}
		j += int(info.size)
	}
	// treat last segment as normal decomposition
	i.next = i.rb.f.nextMain
	return i.next(i)
}
779134
func (s *sequences) next(seq string) int {
	if s.s == nil {
		s.s = make(map[string]int, 1)
	}
	v := s.s[seq] + 1
	s.s[seq] = v
	return v
}
408470
func (iter *MultiEncodedObjectIter) Next() (plumbing.EncodedObject, error) {
	if len(iter.iters) == 0 {
		return nil, io.EOF
	}

	obj, err := iter.iters[0].Next()
	if err == io.EOF {
		iter.iters[0].Close()
		iter.iters = iter.iters[1:]
		return iter.Next()
	}

	return obj, err
}
72340
func Nextafter(x, y int) (r int) {
	return engoimath.Nextafter(x, y)
}
1298113
func (q *Query) WhereInMulti(where string, values ...interface{}) *Query {
	return q.Where(where, types.InMulti(values...))
}
900052
func (itr *tagKeyMergeIterator) Next() (_ []byte, err error) {
	// Find next lowest key amongst the buffers.
	var key []byte
	for i, buf := range itr.buf {
		// Fill buffer.
		if buf == nil {
			if buf, err = itr.itrs[i].Next(); err != nil {
				return nil, err
			} else if buf != nil {
				itr.buf[i] = buf
			} else {
				continue
			}
		}

		// Find next lowest key.
		if key == nil || bytes.Compare(buf, key) == -1 {
			key = buf
		}
	}

	// Return nil if no elements remaining.
	if key == nil {
		return nil, nil
	}

	// Merge elements and clear buffers.
	for i, buf := range itr.buf {
		if buf == nil || !bytes.Equal(buf, key) {
			continue
		}
		itr.buf[i] = nil
	}
	return key, nil
}
928846
func (c *RawBinaryClient) mutateMulti(
	code opCode, zeroVersionIdCode opCode,
	items []*Item) []MutateResponse {

	if items == nil {
		return nil
	}

	responses := make([]MutateResponse, len(items), len(items))

	// Short-circuit function to avoid locking.
	if len(items) == 0 {
		return responses
	}

	c.mutex.Lock()
	defer c.mutex.Unlock()

	var itemCode opCode
	for i, item := range items {
		itemCode = code
		if item.DataVersionId == 0 {
			itemCode = zeroVersionIdCode
		}
		responses[i] = c.sendMutateRequest(itemCode, item, true)
	}

	for i, item := range items {
		if responses[i] != nil { // error occurred while sending
			continue
		}
		itemCode = code
		if item.DataVersionId == 0 {
			itemCode = zeroVersionIdCode
		}
		responses[i] = c.receiveMutateResponse(itemCode, item.Key)
	}

	return responses
}
1208594
func (d *ManyToOneEnvelope) Next() *events.Envelope {
	data := d.d.Next()
	return (*events.Envelope)(data)
}
591974
func (d *ManyToOne) Next() []byte {
	data := d.d.Next()
	return *(*[]byte)(data)
}
522057
func (m *MemoryStore) SetMulti(metas map[string][]byte) error {
	for role, blob := range metas {
		m.Set(role, blob)
	}
	return nil
}
1369231
func (r *RDBDriver) GetMulti(cveIDs []string) (map[string]models.CveDetail, error) {
	cveDetails := map[string]models.CveDetail{}
	for _, cveID := range cveIDs {
		cve, err := r.Get(cveID)
		if err != nil {
			return nil, err
		}
		cveDetails[cveID] = *cve
	}
	return cveDetails, nil
}
1128546
func NewMultiInjector(injectors []app.Injector) app.Injector {
	return app.Injector(MultiInjector{
		injectors: injectors,
	})
}
980691
func (c *MockClient) SetMulti(items []*Item) []MutateResponse {
	c.mutex.Lock()
	defer c.mutex.Unlock()

	res := make([]MutateResponse, len(items))
	for i, item := range items {
		res[i] = c.setHelper(item)
	}
	return res
}
154926
func (g *Goon) GetMulti(dst interface{}) error {
	keys, err := g.extractKeys(dst, false) // don't allow incomplete keys on a Get request
	if err != nil {
		return err
	}

	v := reflect.Indirect(reflect.ValueOf(dst))

	multiErr, anyErr := make(appengine.MultiError, len(keys)), false

	if g.inTransaction {
		// todo: support getMultiLimit in transactions
		if err := datastore.GetMulti(g.Context, keys, v.Interface()); err != nil {
			if merr, ok := err.(appengine.MultiError); ok {
				for i := 0; i < len(keys); i++ {
					if merr[i] != nil && (!IgnoreFieldMismatch || !errFieldMismatch(merr[i])) {
						anyErr = true // this flag tells GetMulti to return multiErr later
						multiErr[i] = merr[i]
					}
				}
			} else {
				g.error(err)
				anyErr = true // this flag tells GetMulti to return multiErr later
				for i := 0; i < len(keys); i++ {
					multiErr[i] = err
				}
			}
			if anyErr {
				return realError(multiErr)
			}
		}
		return nil
	}

	var dskeys []*datastore.Key
	var dsdst []interface{}
	var dixs []int

	var memkeys []string
	var mixs []int

	g.cacheLock.RLock()
	for i, key := range keys {
		m := MemcacheKey(key)
		vi := v.Index(i)

		if vi.Kind() == reflect.Struct {
			vi = vi.Addr()
		}

		if s, present := g.cache[m]; present {
			if vi.Kind() == reflect.Interface {
				vi = vi.Elem()
			}
			vi = reflect.Indirect(vi)
			cached := reflect.Indirect(reflect.ValueOf(s))
			viType, cType := vi.Type(), cached.Type()
			if viType != cType && cType.ConvertibleTo(viType) {
				cached = cached.Convert(viType)
			}
			vi.Set(cached)
		} else {
			memkeys = append(memkeys, m)
			mixs = append(mixs, i)
			dskeys = append(dskeys, key)
			dsdst = append(dsdst, vi.Interface())
			dixs = append(dixs, i)
		}
	}
	g.cacheLock.RUnlock()

	if len(memkeys) == 0 {
		return nil
	}

	tc, cf := context.WithTimeout(g.Context, MemcacheGetTimeout)
	memvalues, err := memcache.GetMulti(tc, memkeys)
	cf()
	if appengine.IsTimeoutError(err) {
		g.timeoutError(err)
	} else if err != nil {
		g.error(err) // timing out or another error from memcache isn't something to fail over, but do log it
		// No memvalues found, prepare the datastore fetch list already prepared above
	} else if len(memvalues) > 0 {
		// since memcache fetch was successful, reset the datastore fetch list and repopulate it
		dskeys = dskeys[:0]
		dsdst = dsdst[:0]
		dixs = dixs[:0]
		// we only want to check the returned map if there weren't any errors
		// unlike the datastore, memcache will return a smaller map with no error if some of the keys were missed

		for i, m := range memkeys {
			d := v.Index(mixs[i]).Interface()
			if v.Index(mixs[i]).Kind() == reflect.Struct {
				d = v.Index(mixs[i]).Addr().Interface()
			}
			if s, present := memvalues[m]; present {
				err := deserializeStruct(d, s.Value)
				if err == nil || (IgnoreFieldMismatch && errFieldMismatch(err)) {
					g.putMemory(d)
				} else if err == datastore.ErrNoSuchEntity || errFieldMismatch(err) {
					anyErr = true // this flag tells GetMulti to return multiErr later
					multiErr[mixs[i]] = err
				} else {
					g.error(err)
					return err
				}
			} else {
				dskeys = append(dskeys, keys[mixs[i]])
				dsdst = append(dsdst, d)
				dixs = append(dixs, mixs[i])
			}
		}
		if len(dskeys) == 0 {
			if anyErr {
				return realError(multiErr)
			}
			return nil
		}
	}

	mu := new(sync.Mutex)
	goroutines := (len(dskeys)-1)/getMultiLimit + 1
	var wg sync.WaitGroup
	wg.Add(goroutines)
	for i := 0; i < goroutines; i++ {
		go func(i int) {
			defer wg.Done()
			lo := i * getMultiLimit
			hi := (i + 1) * getMultiLimit
			if hi > len(dskeys) {
				hi = len(dskeys)
			}
			toCache := make([]cacheEntry, 0, hi-lo)
			propLists := make([]datastore.PropertyList, hi-lo)
			handleProp := func(i, idx int) {
				err := deserializeProperties(dsdst[lo+i], propLists[i])
				if err == nil || (IgnoreFieldMismatch && errFieldMismatch(err)) {
					toCache = append(toCache, cacheEntry{key: dskeys[lo+i], props: propLists[i]})
					g.putMemory(dsdst[lo+i])
				} else {
					multiErr[idx] = err
				}
			}
			gmerr := datastore.GetMulti(g.Context, dskeys[lo:hi], propLists)
			if gmerr != nil {
				mu.Lock()
				anyErr = true // this flag tells GetMulti to return multiErr later
				mu.Unlock()
				merr, ok := gmerr.(appengine.MultiError)
				if !ok {
					g.error(gmerr)
					for j := lo; j < hi; j++ {
						multiErr[j] = gmerr
					}
					return
				}
				for i, idx := range dixs[lo:hi] {
					if merr[i] == nil {
						handleProp(i, idx)
					} else {
						if merr[i] == datastore.ErrNoSuchEntity {
							toCache = append(toCache, cacheEntry{key: dskeys[lo+i], props: nil})
						}
						multiErr[idx] = merr[i]
					}
				}
			} else {
				for i, idx := range dixs[lo:hi] {
					handleProp(i, idx)
				}
			}
			if len(toCache) > 0 {
				if err := g.putMemcache(toCache); err != nil {
					// since putMemcache() gives no guarantee it will actually store the data in memcache
					// we log and swallow this error
					if appengine.IsTimeoutError(err) {
						g.timeoutError(err)
					} else {
						g.error(err)
					}
				}

			}
		}(i)
	}
	wg.Wait()
	if anyErr {
		return realError(multiErr)
	}
	return nil
}
445022
func (b *Bucket) InitMulti(key string, contType string, perm ACL, options Options) (*Multi, error) {
	headers := make(http.Header)
	headers.Set("Content-Length", "0")
	headers.Set("Content-Type", contType)
	headers.Set("x-oss-acl", string(perm))

	options.addHeaders(headers)
	params := make(url.Values)
	params.Set("uploads", "")
	req := &request{
		method:  "POST",
		bucket:  b.Name,
		path:    key,
		headers: headers,
		params:  params,
	}
	var err error
	var resp struct {
		UploadId string `xml:"UploadId"`
	}
	for attempt := attempts.Start(); attempt.Next(); {
		err = b.Client.query(req, &resp)
		if !shouldRetry(err) {
			break
		}
	}
	if err != nil {
		return nil, err
	}
	return &Multi{Bucket: b, Key: key, UploadId: resp.UploadId}, nil
}
863744
func UpdateMulti(r *report.Report) {
	if r.Type == report.TypeMulti {
		for _, rep := range r.Multi {
			if rep.Id == "" {
				rep.Id = bson.NewObjectId()
			}
			rep.Scan = r.Scan
			rep.ScanSession = r.ScanSession
			now := time.Now().UTC()
			if rep.Created.IsZero() {
				rep.Created = now
			}
			rep.Updated = now
			UpdateMulti(rep)
		}
	}
	UpdateIssues(r)
}
1232227
func (s *CacheOnStorage) DeleteMulti(keys ...interface{}) error {
	if err := s.storage.DeleteMulti(keys...); err != nil {
		return err
	}

	return s.cache.DeleteMulti(keys...)
}