// Segments provides access to the underlying segments stored on disk.
503733
func (c *CommitLog) Segments() []*Segment {
	c.mu.Lock()
	defer c.mu.Unlock()
	return c.segments
}
1090657
func (r *Reader) Segment() int {
	if b, ok := r.rdr.(*segmentBufReader); ok {
		return b.segs[b.cur].Index()
	}
	return -1
}
656510
func (s StreamName) Segments() []string {
	if len(s) == 0 {
		return nil
	}
	return strings.Split(string(s), string(StreamNameSep))
}
521983
func (shape *Shape) GetAsSegment() *SegmentShape {
	if seg, ok := shape.ShapeClass.(*SegmentShape); ok {
		return seg
	}

	return nil
}
140235
func WithSegment(ctx context.Context, s *Segment) context.Context {
	return context.WithValue(ctx, segKey, s)
}
729744
func (ss *segmentStack) Stats() *SegmentStackStats {
	rv := &SegmentStackStats{CurSegments: uint64(len(ss.a))}
	for _, seg := range ss.a {
		rv.CurOps += uint64(seg.Len())
		nk, nv := seg.NumKeyValBytes()
		rv.CurBytes += nk + nv
	}
	return rv
}
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
}
1332405
func (si *SegmentCommitInfo) Files() []string {
	// Start from the wrapped info's files:
	files := make(map[string]bool)
	for name, _ := range si.Info.Files() {
		files[name] = true
	}

	// Must separately add any live docs files
	for _, name := range si.Info.Codec().(Codec).LiveDocsFormat().Files(si) {
		files[name] = true
	}

	// Must separately add any per-gen updates files. This can go away
	// when we get rid of genUpdatesFiles (6.0)
	for _, names := range si.genUpdatesFiles {
		for name, _ := range names {
			files[name] = true
		}
	}

	// must separately add any field updates files
	for _, names := range si.dvUpdatesFiles {
		for name, _ := range names {
			files[name] = true
		}
	}

	// must separately add fieldInfos files
	for name, _ := range si.fieldInfosFiles {
		files[name] = true
	}

	ans := make([]string, 0, len(files))
	for s, _ := range files {
		ans = append(ans, s)
	}
	return ans
}
1096671
func (s *Store) persistSegments(ss *segmentStack, footer *Footer,
	file File, fref *FileRef) error {
	// First persist the child segments recursively.
	for cName, childSegStack := range ss.childSegStacks {
		err := s.persistSegments(childSegStack, footer.ChildFooters[cName],
			file, fref)
		if err != nil {
			return err
		}
	}

	for _, segment := range ss.a {
		if segment.Len() <= 0 {
			// With multiple child collections it is possible that some child
			// collections segments are empty. Ok to skip these empty segments.
			continue
		}

		segmentLoc, err := s.persistSegment(file, segment, s.options)
		if err != nil {
			return err
		}

		footer.SegmentLocs = append(footer.SegmentLocs, segmentLoc)
	}

	return nil
}
1078856
func newSegment(ctx context.Context, traceID, name string, req *http.Request, c net.Conn) *Segment {
	var (
		spanID   = middleware.ContextSpanID(ctx)
		parentID = middleware.ContextParentSpanID(ctx)
	)

	s := NewSegment(name, traceID, spanID, c)
	s.RecordRequest(req, "")

	if parentID != "" {
		s.ParentID = parentID
	}

	return s
}
1340277
func (pool *ReaderPool) segmentToString(info *SegmentCommitInfo) string {
	// TODO synchronized
	return info.StringOf(info.Info.Dir, pool.numDeletedDocs(info)-info.DelCount())
}
1244454
func NewSegmenterDirect(buf []byte) *Segmenter {
	return &Segmenter{
		segment:      SegmentWords,
		maxTokenSize: MaxScanTokenSize,
		buf:          buf,
		start:        0,
		end:          len(buf),
		err:          io.EOF,
	}
}
328333
func CreateSegment(dir string, k int) (*Segment, error) {
	f, err := os.OpenFile(SegmentName(dir, k), os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666)
	if err != nil {
		return nil, err
	}
	return &Segment{File: f, i: k, dir: dir}, nil
}
565027
func (slocs SegmentLocs) DecRef() {
	for _, sloc := range slocs {
		if sloc.mref != nil {
			sloc.mref.DecRef()
		}
	}
}
45775
func PersistSegmentBase(sb *SegmentBase, path string) error {
	flag := os.O_RDWR | os.O_CREATE

	f, err := os.OpenFile(path, flag, 0600)
	if err != nil {
		return err
	}

	cleanup := func() {
		_ = f.Close()
		_ = os.Remove(path)
	}

	br := bufio.NewWriter(f)

	_, err = br.Write(sb.mem)
	if err != nil {
		cleanup()
		return err
	}

	err = persistFooter(sb.numDocs, sb.storedIndexOffset, sb.fieldsIndexOffset, sb.docValueOffset,
		sb.chunkFactor, sb.memCRC, br)
	if err != nil {
		cleanup()
		return err
	}

	err = br.Flush()
	if err != nil {
		cleanup()
		return err
	}

	err = f.Sync()
	if err != nil {
		cleanup()
		return err
	}

	err = f.Close()
	if err != nil {
		cleanup()
		return err
	}

	return nil
}
1291873
func (s *HlsPackage) SetSegmentDurationSeconds(v int64) *HlsPackage {
	s.SegmentDurationSeconds = &v
	return s
}
1138145
func (ss *segmentStack) Get(key []byte, readOptions ReadOptions) ([]byte, error) {
	return ss.get(key, len(ss.a)-1, nil, readOptions)
}