// Segments returns the numeric segments of the version as a slice of ints.
//
// This excludes any metadata or pre-release information. For example,
// for a version "1.2.3-beta", segments will return a slice of
// 1, 2, 3.
545626
func (v *Version) Segments() []int {
	segmentSlice := make([]int, len(v.segments))
	for i, v := range v.segments {
		segmentSlice[i] = int(v)
	}
	return segmentSlice
}
1151966
func (r *Row) segment(shard uint64) *rowSegment {
	if i := sort.Search(len(r.segments), func(i int) bool {
		return r.segments[i].shard >= shard
	}); i < len(r.segments) && r.segments[i].shard == shard {
		return &r.segments[i]
	}
	return nil
}
989053
func (v *Version) Segments64() []int64 {
	result := make([]int64, len(v.segments))
	copy(result, v.segments)
	return result
}
1232637
func (p *Parth) Segment(i int, v interface{}) {
	if p.err != nil {
		return
	}

	p.err = Segment(p.path, i, v)
}
1099051
func (v qrCodeVersion) numDataBits() int {
	numDataBits := 0
	for _, b := range v.block {
		numDataBits += 8 * b.numBlocks * b.numDataCodewords // 8 bits in a byte
	}

	return numDataBits
}
996869
func (l *Client) GetSegmentMLModels() ([]SegmentML, error) {
	res := ApiResp{}
	data := []SegmentML{}

	// make the request
	err := l.Get(segmentMLListEndpoint, nil, nil, &res, &data)
	if err != nil {
		return data, err
	}

	return data, nil
}
290971
func (kf *KeyFormat) ScanBytes(key []byte) [][]byte {
	segments := make([][]byte, len(kf.layout))
	n := kf.prefix.Length()
	for i, l := range kf.layout {
		if l == 0 {
			// Must be final variadic segment
			segments[i] = key[n:]
			return segments
		}
		n += l
		if n > len(key) {
			return segments[:i]
		}
		segments[i] = key[n-l : n]
	}
	return segments
}
1090657
func (r *Reader) Segment() int {
	if b, ok := r.rdr.(*segmentBufReader); ok {
		return b.segs[b.cur].Index()
	}
	return -1
}
835849
func (mtt *mttNode) GetVersions(ns []string) ([]*metricType, error) {
	var nodes []*mttNode
	var mts []*metricType

	if len(ns) == 0 {
		return nil, errorEmptyNamespace()
	}

	nodes = mtt.search(nodes, ns)

	for _, node := range nodes {
		// concatenates metric types in ALL versions into a single slice
		for _, mt := range node.mts {
			mts = append(mts, mt)
		}
	}
	if len(mts) == 0 {
		return nil, errorMetricNotFound("/" + strings.Join(ns, "/"))
	}
	return mts, nil
}
437077
func decodePathSegment(pathData unsafe.Pointer) (*PathSegment, int) {
	header := (*pathDataHeader)(pathData)
	seg := PathSegment{
		Type:   PathDataType(header.dataType),
		Points: make([]PathPoint, header.length-1),
	}
	parts := (*[1 << 30]PathPoint)(pathData)
	copy(seg.Points, parts[1:])
	return &seg, int(header.length)
}
363717
func (c *Client) IndexSegments(indices ...string) *IndicesSegmentsService {
	return NewIndicesSegmentsService(c).Index(indices...)
}
290291
func Segment(x []float64, size, noverlap int) [][]float64 {
	stride := size - noverlap
	lx := len(x)

	var segments int
	if lx == size {
		segments = 1
	} else if lx > size {
		segments = (len(x)-size)/stride + 1
	} else {
		segments = 0
	}

	r := make([][]float64, segments)
	for i, offset := 0, 0; i < segments; i++ {
		r[i] = make([]float64, size)

		for j := 0; j < size; j++ {
			r[i][j] = x[offset+j]
		}

		offset += stride
	}

	return r
}
349707
func ReadSeriesKeyFromSegments(a []*SeriesSegment, offset int64) []byte {
	segmentID, pos := SplitSeriesOffset(offset)
	segment := FindSegment(a, segmentID)
	if segment == nil {
		return nil
	}
	buf := segment.Slice(pos)
	key, _ := ReadSeriesKey(buf)
	return key
}
1166935
func slice(path string, start int) (segment string, next int) {
	if len(path) == 0 || start < 0 || start >= len(path) {
		return "", -1
	}
	end := strings.IndexRune(path[start:], '/')
	if end == -1 {
		return path[start:], -1
	}
	if path[start:start+end] == "/" {
		return "", start + end + 1
	}
	return path[start : start+end], start + end + 1
}
780545
func versionParts(v string) ([]int, string) {
	parts := strings.SplitN(v[1:], " ", 2) // " (+dev)" versions
	if len(parts) == 1 {
		parts = strings.SplitN(parts[0], "-", 2) // "-rc.1" type versions
	}
	fields := strings.Split(parts[0], ".")

	release := make([]int, len(fields))
	for i, s := range fields {
		v, _ := strconv.Atoi(s)
		release[i] = v
	}

	var prerelease string
	if len(parts) > 1 {
		prerelease = parts[1]
	}

	return release, prerelease
}
863573
func (sm *SegmentMap) GetSegment(index int64) (map[string]interface{}, error) {
	if index >= sm.size || index < 0 {
		return nil, errors.Errorf("index out of bound: %d", index)
	}

	return sm.maps[index], nil
}
1219922
func (l *Client) GetSegmentCollection(id string) (SegmentCollection, error) {
	res := ApiResp{}
	data := SegmentCollection{}

	err := l.Get(parseLyticsURL(segmentCollectionEndpoint, map[string]string{"id": id}), nil, nil, &res, &data)
	if err != nil {
		return data, err
	}

	return data, nil
}