// SplitRegionRanges get the split ranges from pd region.
422722
func SplitRegionRanges(bo *Backoffer, cache *RegionCache, keyRanges []kv.KeyRange) ([]kv.KeyRange, error) {
	ranges := copRanges{mid: keyRanges}

	var ret []kv.KeyRange
	appendRange := func(region RegionVerID, ranges *copRanges) {
		for i := 0; i < ranges.len(); i++ {
			ret = append(ret, ranges.at(i))
		}
	}

	err := splitRanges(bo, cache, &ranges, appendRange)
	if err != nil {
		return nil, errors.Trace(err)
	}
	return ret, nil
}
500901
func allRanges(b, pattern []byte) (ranges []matchRange) {
	i := 0
	for {
		sub := b[i:len(b)]
		idx := bytes.Index(sub, pattern)
		if idx == -1 {
			return
		}

		ranges = append(ranges, matchRange{first: idx + i, last: idx + i + len(pattern)})

		i += idx + 1
		if i > len(b)-1 {
			return
		}
	}
}
1036984
func (r *DB) subrange(start, end uint16) []*attr {
	startidx := r.idx(int(start))
	switch startidx {
	case tooSmall:
		startidx = 0
	case tooLarge:
		return []*attr{}
	}

	endidx := r.idx(int(end) + 1) // [start, end] includes its upper bound!
	switch endidx {
	case tooSmall:
		return []*attr{}
	case tooLarge:
		endidx = len(r.attrs)
	}
	return r.attrs[startidx:endidx]
}
324251
func (s *CreateStackInstancesInput) SetRegions(v []*string) *CreateStackInstancesInput {
	s.Regions = v
	return s
}
78276
func (s *TargetLocation) SetRegions(v []*string) *TargetLocation {
	s.Regions = v
	return s
}
16328
func (c *Client) GetRegions() (*RegionsResponse, error) {
	r, err := c.Get("stats/regions", nil)
	if err != nil {
		return nil, err
	}

	var rr *RegionsResponse
	if err := decodeJSON(&rr, r.Body); err != nil {
		return nil, err
	}

	return rr, nil
}
1235537
func (s *Server) Regions() []string {
	s.peerLock.RLock()
	defer s.peerLock.RUnlock()

	regions := make([]string, 0, len(s.peers))
	for region := range s.peers {
		regions = append(regions, region)
	}
	sort.Strings(regions)
	return regions
}
603688
func NewRanges(ns ...uint64) Ranges {
	xs := append(uint64s{}, ns...)
	sort.Sort(xs)
	rs := make(Ranges, len(xs))
	for i := range xs {
		rs[i].Begin, rs[i].End = xs[i], xs[i]
	}
	return rs.Squash()
}
1344310
func (r *RegionSet) Regions() (ret []Region) {
	r.lock.Lock()
	defer r.lock.Unlock()
	ret = make([]Region, len(r.regions))
	copy(ret, r.regions)
	return
}
29276
func (t *TextView) SetRegions(regions bool) *TextView {
	if t.regions != regions {
		t.index = nil
	}
	t.regions = regions
	return t
}
1359850
func split(args, fields []string) []string {
	for _, arg := range fields {
		arr := strings.Fields(arg)
		args = append(args, arr...)
	}
	return args
}
1268016
func splitPrefixes(prefixes ...[]byte) ([]byte, [][]byte) {
	switch {
	case len(prefixes) == 0 || len(prefixes[0]) == 0:
		return nil, prefixes
	case len(prefixes) == 1:
		return prefixes[0], nil
	}

	var prefix []byte
	for i := 0; ; i++ {
		var cur byte
		var matched bool
		for j, prefix := range prefixes {
			switch {
			case len(prefix) <= i:
				matched = true
				break

			case j == 0:
				cur = prefix[i]
				continue

			case cur != prefix[i]:
				matched = true
				break
			}
		}

		if matched {
			break
		}

		prefix = append(prefix, cur)
	}

	next := make([][]byte, 0, len(prefixes))
	for _, remaining := range prefixes {
		next = append(next, remaining[len(prefix):])
	}
	return prefix, next
}
780229
func (r *RegionSet) Cut(r2 Region) (ret RegionSet) {
	r.lock.Lock()
	defer r.lock.Unlock()

	for i := 0; i < len(r.regions); i++ {
		for _, xor := range r.regions[i].Cut(r2) {
			if !xor.Empty() {
				ret.Add(xor)
			}
		}
	}
	return
}
924560
func split(data []byte) [][]byte {
	chunks := [][]byte{}

	start := 0
	dirDepth := 0
	for i, b := range data {
		switch b {
		case dirStartMark:
			dirDepth++
		case dirEndMark:
			dirDepth--
		case dirElementSep:
			if dirDepth == 0 {
				chunks = append(chunks, data[start:i+1])
				start = i + 1
			}
		}
	}
	chunks = append(chunks, data[start:])

	return chunks
}
505605
func (s *DeleteStackInstancesInput) SetRegions(v []*string) *DeleteStackInstancesInput {
	s.Regions = v
	return s
}
1034785
func FindRegion(cluster *kops.Cluster) (string, error) {

	zones := []string{}
	for _, subnet := range cluster.Spec.Subnets {
		zones = append(zones, subnet.Zone)
	}
	return getRegionByZones(zones)

}
356809
func ParseCloudRegion(cloudRegion string) (string, string, error) {
	fields := strings.SplitN(cloudRegion, "/", 2)
	if len(fields) != 2 || fields[0] == "" || fields[1] == "" {
		return "", "", errors.NotValidf("cloud region %q", cloudRegion)
	}
	return fields[0], fields[1], nil
}