// SeekFirst returns an enumerator positioned on the first KV pair in the tree,
// if any. For an empty tree, err == io.EOF is returned and e will be nil.
433968
func (t *SecondaryTree) SeekFirst() (e *SecondaryEnumerator, err error) {
	q := t.first
	if q == nil {
		return nil, io.EOF
	}

	return btEPool2.get(nil, true, 0, q.d[0].k, q, t, atomic.LoadUint64(&t.ver)), nil
}
1189211
func (f *File) Seek(offset int64, whence int) (n int64, err error) {
	newOffset := offset
	switch whence {
	case io.SeekStart:
	case io.SeekCurrent:
		origOffset := atomic.LoadInt64(&f.offset)
		newOffset = origOffset + offset
	case io.SeekEnd:
		ei, err := f.fs.config.KBFSOps().Stat(f.fs.ctx, f.node)
		if err != nil {
			return 0, err
		}
		newOffset = int64(ei.Size) + offset
	}
	if newOffset < 0 {
		return 0, errors.Errorf("Cannot seek to offset %d", newOffset)
	}

	_ = atomic.SwapInt64(&f.offset, newOffset)
	return newOffset, nil
}
403692
func (s *SkipList) Seek(key interface{}) Iterator {
	current := s.getPath(s.header, nil, key)
	if current == nil {
		return nil
	}

	return &iter{
		current: current,
		key:     current.key,
		list:    s,
		value:   current.value,
	}
}
409216
func (c *cursor) First() (key, value []byte) {
	return (*bbolt.Cursor)(c).First()
}
164243
func (r *GormWorkItemRepository) FindFirstItem(ctx context.Context, spaceID uuid.UUID, id uuid.UUID) (*float64, error) {
	res := WorkItemStorage{}
	tx := r.db.Model(WorkItemStorage{}).Where("id=? and space_id=?", id, spaceID).First(&res)
	if tx.RecordNotFound() {
		return nil, errors.NewNotFoundError("work item", id.String())
	}
	if tx.Error != nil {
		return nil, errors.NewInternalError(ctx, tx.Error)
	}
	return &res.ExecutionOrder, nil
}
166226
func (t *PrimaryTree) Seek(k string) (e *PrimaryEnumerator, ok bool) {
	q := t.r
	if q == nil {
		e = btEPool1.get(nil, false, 0, k, nil, t, atomic.LoadUint64(&t.ver))
		return
	}

	for {
		var i int
		if i, ok = t.find(q, k); ok {
			switch x := q.(type) {
			case *x1:
				q = x.x[i+1].ch
				continue
			case *d1:
				return btEPool1.get(nil, ok, i, k, x, t, atomic.LoadUint64(&t.ver)), true
			}
		}

		switch x := q.(type) {
		case *x1:
			q = x.x[i].ch
		case *d1:
			return btEPool1.get(nil, ok, i, k, x, t, atomic.LoadUint64(&t.ver)), false
		}
	}
}
904757
func (i *Iter) Seek(offset int64, whence int) (int64, error) {
	var abs int64
	switch whence {
	case 0:
		abs = offset
	case 1:
		abs = int64(i.p) + offset
	case 2:
		abs = int64(i.rb.nsrc) + offset
	default:
		return 0, fmt.Errorf("norm: invalid whence")
	}
	if abs < 0 {
		return 0, fmt.Errorf("norm: negative position")
	}
	if int(abs) >= i.rb.nsrc {
		i.setDone()
		return int64(i.p), nil
	}
	i.p = int(abs)
	i.multiSeg = nil
	i.next = i.rb.f.nextMain
	i.info = i.rb.f.info(i.rb.src, i.p)
	return abs, nil
}
1363716
func (c *Cursor) First() ([]byte, []byte) {
	k, v := c.cursor.First()
	if len(k) == 0 && len(v) == 0 {
		return nil, nil
	}
	return k, v
}
932304
func DepthMatchFirst(p MIMEPart, matcher MIMEPartMatcher) MIMEPart {
	root := p
	for {
		if matcher(p) {
			return p
		}
		c := p.FirstChild()
		if c != nil {
			p = c
		} else {
			for p.NextSibling() == nil {
				if p == root {
					return nil
				}
				p = p.Parent()
			}
			p = p.NextSibling()
		}
	}
}
1276535
func findFirst(vs []string, predicate func(string) bool) int {
	l, h := -1, len(vs)
	// Invariant: vs[l] does not match, vs[h] does.
	// -1 and len(vs) are sentinal values, never tested but assumed to mismatch and match, respectively.
	for l+1 < h {
		m := (l + h) / 2 // Must now be a valid value
		// //debugf("%d %d %d", l, m, h)
		if predicate(vs[m]) {
			h = m
		} else {
			l = m
		}
	}
	//debugf("==> %d", h)
	return h
}
930178
func (this *IntErrs) GetFirstErr() (err error) {
	for _, v := range *this {
		if nil != v.E {
			return v.E
		}
	}
	return nil
}
1065289
func (s Selector) MatchFirst(n *html.Node) *html.Node {
	if s.Match(n) {
		return n
	}

	for c := n.FirstChild; c != nil; c = c.NextSibling {
		m := s.MatchFirst(c)
		if m != nil {
			return m
		}
	}
	return nil
}
610290
func (r *rangeIterator) seekTo(target *rangeIterator) {
	r.it.seek(target.rangeMin)
	// If the current cell does not overlap target, it is possible that the
	// previous cell is the one we are looking for. This can only happen when
	// the previous cell contains target but has a smaller CellID.
	if r.it.Done() || r.it.CellID().RangeMin() > target.rangeMax {
		if r.it.Prev() && r.it.CellID().RangeMax() < target.cellID() {
			r.it.Next()
		}
	}
	r.refresh()
}
1151718
func (s *Scanner) SeekFromStart(offset int64) (previous int64, err error) {
	// if seeking we assume that you are not interested in the header
	if s.version == 0 {
		s.version = VersionSupported
	}

	previous, err = s.r.Seek(0, io.SeekCurrent)
	if err != nil {
		return -1, err
	}

	_, err = s.r.Seek(offset, io.SeekStart)
	return previous, err
}
121537
func (s *Scroller) seekInitial() error {
	offset, err := s.source.Seek(0, os.SEEK_END)
	if err != nil {
		return err
	}
	if s.lines < 1 {
		// Simple case, no initial lines wanted.
		return nil
	}
	seekPos := int64(0)
	found := 0
	buffer := make([]byte, s.bufferSize)
SeekLoop:
	for offset > 0 {
		// bufferf partly filled, check if large enough.
		space := cap(buffer) - len(buffer)
		if space < s.bufferSize {
			// Grow buffer.
			newBuffer := make([]byte, len(buffer), cap(buffer)*2)
			copy(newBuffer, buffer)
			buffer = newBuffer
			space = cap(buffer) - len(buffer)
		}
		if int64(space) > offset {
			// Use exactly the right amount of space if there's
			// only a small amount remaining.
			space = int(offset)
		}
		// Copy remaining data to the end of the buffer.
		copy(buffer[space:cap(buffer)], buffer)
		buffer = buffer[0 : len(buffer)+space]
		offset -= int64(space)
		_, err := s.source.Seek(offset, os.SEEK_SET)
		if err != nil {
			return err
		}
		// Read into the beginning of the buffer.
		_, err = io.ReadFull(s.source, buffer[0:space])
		if err != nil {
			return err
		}
		// Find the end of the last line in the buffer.
		// This will discard any unterminated line at the end
		// of the file.
		end := bytes.LastIndex(buffer, delimiters)
		if end == -1 {
			// No end of line found - discard incomplete
			// line and continue looking. If this happens
			// at the beginning of the file, we don't care
			// because we're going to stop anyway.
			buffer = buffer[:0]
			continue
		}
		end++
		for {
			start := bytes.LastIndex(buffer[0:end-1], delimiters)
			if start == -1 && offset >= 0 {
				break
			}
			start++
			if s.isValid(buffer[start:end]) {
				found++
				if found >= s.lines {
					seekPos = offset + int64(start)
					break SeekLoop
				}
			}
			end = start
		}
		// Leave the last line in the buffer. It's not
		// clear if it is complete or not.
		buffer = buffer[0:end]
	}
	// Final positioning.
	s.source.Seek(seekPos, os.SEEK_SET)
	return nil
}
572020
func (t *Tree) Seek(k generic.T) (e *Enumerator, ok bool) {
	q := t.r
	if q == nil {
		e = &Enumerator{nil, false, 0, k, nil, t, t.ver}
		return
	}

	for {
		var i int
		if i, ok = t.find(q, k); ok {
			switch x := q.(type) {
			case *x:
				e = &Enumerator{nil, ok, 0, k, x.x[i].sep, t, t.ver}
				return
			case *d:
				e = &Enumerator{nil, ok, i, k, x, t, t.ver}
				return
			}
		}
		switch x := q.(type) {
		case *x:
			q = x.x[i].ch
		case *d:
			e = &Enumerator{nil, ok, i, k, x, t, t.ver}
			return
		}
	}
}
1215130
func (t *tree) FindFirst(f func(v interface{}) (bool, error)) Changer {
	n, err := t.container.root.findFirst(func(fn *node) (bool, error) {
		return f(fn.content.value())
	})
	return &changer{n, err}
}