// NewTSMReader returns a new TSMReader from the given file.
161454
func NewTSMReader(f *os.File, options ...tsmReaderOption) (*TSMReader, error) {
	t := &TSMReader{
		logger: zap.NewNop(),
	}
	for _, option := range options {
		option(t)
	}

	stat, err := f.Stat()
	if err != nil {
		return nil, err
	}
	t.size = stat.Size()
	t.lastModified = stat.ModTime().UnixNano()
	t.accessor = &mmapAccessor{
		logger:       t.logger,
		f:            f,
		mmapWillNeed: t.madviseWillNeed,
	}

	index, err := t.accessor.init()
	if err != nil {
		return nil, err
	}

	t.index = index
	t.tombstoner = NewTombstoner(t.Path(), index.MaybeContainsKey)

	if err := t.applyTombstones(); err != nil {
		return nil, err
	}

	return t, nil
}
982231
func NewParserReader(logFile io.Reader, parser StringParser) *Reader {
	return &Reader{
		file:   logFile,
		parser: parser,
	}
}
613844
func NewTermFacet(field string, size int) *TermFacet {
	mq := &TermFacet{}
	mq.data.Field = field
	mq.data.Size = size
	return mq
}
391535
func NewTferAction(s string) (tferAction, error) {
	var e tferAction
	err := e.FromString(s)
	if err != nil {
		return 0, err
	}
	return e, nil
}
463441
func NewTemaForStreamWithSrcLen(sourceLength uint, priceStream gotrade.DOHLCVStreamSubscriber, timePeriod int, selectData gotrade.DOHLCVDataSelectionFunc) (indicator *Tema, err error) {
	ind, err := NewTemaWithSrcLen(sourceLength, timePeriod, selectData)
	priceStream.AddTickSubscription(ind)
	return ind, err
}
584401
func NewTagStringsIterator(inputs ...string) (TagIterator, error) {
	if len(inputs)%2 != 0 {
		return nil, errInvalidNumberInputsToIteratorMatcher
	}
	tags := make([]Tag, 0, len(inputs)/2)
	for i := 0; i < len(inputs); i += 2 {
		tags = append(tags, StringTag(inputs[i], inputs[i+1]))
	}
	return NewTagsIterator(NewTags(tags...)), nil
}
352761
func NewTsfForStreamWithSrcLen(sourceLength uint, priceStream gotrade.DOHLCVStreamSubscriber, timePeriod int, selectData gotrade.DOHLCVDataSelectionFunc) (indicator *Tsf, err error) {
	ind, err := NewTsfWithSrcLen(sourceLength, timePeriod, selectData)
	priceStream.AddTickSubscription(ind)
	return ind, err
}
1317079
func NewTemplater(templatesPath, layoutsPath, ext string) (t *Templater, err error) {
	// Create templater
	t = &Templater{templates: make(map[string]*template.Template)}

	// Get layouts
	if err = filepath.Walk(layoutsPath, func(path string, info os.FileInfo, e error) (err error) {
		// Check input error
		if e != nil {
			err = errors.Wrapf(e, "astitemplate: walking layouts has an input error for path %s", path)
			return
		}

		// Only process files
		if info.IsDir() {
			return
		}

		// Check extension
		if ext != "" && filepath.Ext(path) != ext {
			return
		}

		// Append
		t.layouts = append(t.layouts, path)
		return
	}); err != nil {
		err = errors.Wrapf(err, "astitemplate: walking layouts in %s failed", layoutsPath)
		return
	}

	// Loop through templates
	if err = filepath.Walk(templatesPath, func(path string, info os.FileInfo, e error) (err error) {
		// Check input error
		if e != nil {
			err = errors.Wrapf(e, "astitemplate: walking templates has an input error for path %s", path)
			return
		}

		// Only process files
		if info.IsDir() {
			return
		}

		// Check extension
		if ext != "" && filepath.Ext(path) != ext {
			return
		}

		// Read file
		var b []byte
		if b, err = ioutil.ReadFile(path); err != nil {
			err = errors.Wrapf(err, "astitemplate: reading template content of %s failed", path)
			return
		}

		// Add template
		// We use ToSlash to homogenize Windows path
		if err = t.Add(filepath.ToSlash(strings.TrimPrefix(path, templatesPath)), string(b)); err != nil {
			err = errors.Wrap(err, "astitemplate: adding template failed")
			return
		}
		return
	}); err != nil {
		err = errors.Wrapf(err, "astitemplate: walking templates in %s failed", templatesPath)
		return
	}
	return
}
65140
func NewTokenizer(r io.Reader) *Tokenizer {
	return &Tokenizer{
		InStream: r,
		buf:      make([]byte, defaultBufSize),
	}
}
55377
func NewTSMWriterWithDiskBuffer(w io.Writer) (TSMWriter, error) {
	var index IndexWriter
	// Make sure is a File so we can write the temp index alongside it.
	if fw, ok := w.(syncer); ok {
		f, err := os.OpenFile(strings.TrimSuffix(fw.Name(), ".tsm.tmp")+".idx.tmp", os.O_CREATE|os.O_RDWR|os.O_EXCL, 0666)
		if err != nil {
			return nil, err
		}
		index = NewDiskIndexWriter(f)
	} else {
		// w is not a file, just use an inmem index
		index = NewIndexWriter()
	}

	return &tsmWriter{
		wrapped: w,
		w:       bufio.NewWriterSize(w, 1024*1024),
		index:   index,
		stats:   NewMeasurementStats(),
	}, nil
}
1183179
func newSparseFileReader(rfr numBytesReader, sp []sparseEntry, total int64) (*sparseFileReader, error) {
	if total < 0 {
		return nil, ErrHeader // Total size cannot be negative
	}

	// Validate all sparse entries. These are the same checks as performed by
	// the BSD tar utility.
	for i, s := range sp {
		switch {
		case s.offset < 0 || s.numBytes < 0:
			return nil, ErrHeader // Negative values are never okay
		case s.offset > math.MaxInt64-s.numBytes:
			return nil, ErrHeader // Integer overflow with large length
		case s.offset+s.numBytes > total:
			return nil, ErrHeader // Region extends beyond the "real" size
		case i > 0 && sp[i-1].offset+sp[i-1].numBytes > s.offset:
			return nil, ErrHeader // Regions can't overlap and must be in order
		}
	}
	return &sparseFileReader{rfr: rfr, sp: sp, total: total}, nil
}
743813
func NewTSDBTagValueIteratorAdapter(itr TagValueIterator) tsdb.TagValueIterator {
	if itr == nil {
		return nil
	}
	return &tsdbTagValueIteratorAdapter{itr: itr}
}
1236904
func SumReader(algo string, r io.Reader) ([]byte, error) {
	h, err := New(algo)
	if err != nil {
		return nil, err
	}

	_, err = io.Copy(h, r)
	if err != nil {
		return nil, err
	}

	return h.Sum(nil), nil
}
1213943
func runeReader(r io.Reader) io.RuneReader {
	if rr, ok := r.(io.RuneReader); ok {
		return rr
	}
	return bufio.NewReader(r)
}
744492
func (f *FileStorage) GetReader() (io.ReadCloser, error) {
	newFile, err := os.Open(f.file.Name())
	if err != nil {
		return nil, err
	}
	return &FileReader{
		content:      newFile,
		subscription: f.subscription.NewSubscriber(),
		unsubscribe:  f.subscription.RemoveSubscriber,
	}, nil
}
1141639
func newTS() *Set {
	s := &Set{}
	s.m = make(map[interface{}]struct{})

	// Ensure interface compliance
	var _ Interface = s

	return s
}
663399
func NewTSDBTagKeyIteratorAdapter(itr TagKeyIterator) tsdb.TagKeyIterator {
	if itr == nil {
		return nil
	}
	return &tsdbTagKeyIteratorAdapter{itr: itr}
}