// Prev moves the iterator one key/value pair backward and returns whether or
// not the pair exists.
//
// This is part of the leveldb iterator.Iterator interface implementation.
345956
func (iter *dbCacheIterator) Prev() bool {
	// Nothing to return if cursor is exhausted.
	if iter.currentIter == nil {
		return false
	}

	// Move the current iterator to the previous entry and choose the
	// iterator that is both valid and has the larger key.
	iter.currentIter.Prev()
	return iter.chooseIterator(false)
}
1027547
func (yfast *YFastTrie) Predecessor(key uint64) Entry {
	entry := yfast.predecessor(key)
	if entry == nil {
		return nil
	}

	return entry
}
1060632
func (c *cursor) Prev() (key, value []byte) {
	return (*bbolt.Cursor)(c).Prev()
}
451869
func (iter *WriteBatchIterator) Next() bool {
	if iter.err != nil || len(iter.data) == 0 {
		return false
	}
	// reset the current record
	iter.record.CF = 0
	iter.record.Key = nil
	iter.record.Value = nil

	// parse the record type
	iter.record.Type = iter.decodeRecType()

	switch iter.record.Type {
	case
		WriteBatchDeletionRecord,
		WriteBatchSingleDeletionRecord:
		iter.record.Key = iter.decodeSlice()
	case
		WriteBatchCFDeletionRecord,
		WriteBatchCFSingleDeletionRecord:
		iter.record.CF = int(iter.decodeVarint())
		if iter.err == nil {
			iter.record.Key = iter.decodeSlice()
		}
	case
		WriteBatchValueRecord,
		WriteBatchMergeRecord,
		WriteBatchRangeDeletion,
		WriteBatchBlobIndex:
		iter.record.Key = iter.decodeSlice()
		if iter.err == nil {
			iter.record.Value = iter.decodeSlice()
		}
	case
		WriteBatchCFValueRecord,
		WriteBatchCFRangeDeletion,
		WriteBatchCFMergeRecord,
		WriteBatchCFBlobIndex:
		iter.record.CF = int(iter.decodeVarint())
		if iter.err == nil {
			iter.record.Key = iter.decodeSlice()
		}
		if iter.err == nil {
			iter.record.Value = iter.decodeSlice()
		}
	case WriteBatchLogDataRecord:
		iter.record.Value = iter.decodeSlice()
	case
		WriteBatchNoopRecord,
		WriteBatchBeginPrepareXIDRecord,
		WriteBatchBeginPersistedPrepareXIDRecord:
	case
		WriteBatchEndPrepareXIDRecord,
		WriteBatchCommitXIDRecord,
		WriteBatchRollbackXIDRecord:
		iter.record.Value = iter.decodeSlice()
	default:
		iter.err = errors.New("unsupported wal record type")
	}

	return iter.err == nil

}
616896
func (e *ItemElement) Prev() *ItemElement {
	if p := e.prev; e.list != nil && p != &e.list.root {
		return p
	}
	return nil
}
1033422
func (c *Carbon) Previous(wd time.Weekday) *Carbon {
	c = c.SubDay()
	for c.Weekday() != wd {
		c = c.SubDay()
	}

	return c.StartOfDay()
}
667840
func (entries Entries) predecessor(key uint64) (Entry, int) {
	if len(entries) == 0 {
		return nil, -1
	}

	i := entries.search(key)
	if i == len(entries) {
		return entries[i-1], i - 1
	}

	if entries[i].Key() == key {
		return entries[i], i
	}

	i--

	if i < 0 {
		return nil, -1
	}

	return entries[i], i
}
251122
func (c *CompletionManager) Previous() {
	if c.verticalScroll == c.selected && c.selected > 0 {
		c.verticalScroll--
	}
	c.selected--
	c.update()
	return
}
896762
func getPrevRev(c context.Context, b *buildbot.Build, maxRecursionDepth int) (string, error) {
	// note: we cannot use exponential scan here because there may be build
	// number gaps anywhere, for example given build numbers 10 20 30 40,
	// if we check 25 while scanning [20, 40), we don't know if we should continue
	// scanning in [20, 25) or (25, 40).

	switch {
	case b.Number == 0:
		return "", nil
	case maxRecursionDepth <= 0:
		logging.Warningf(c, "reached maximum recursion depth; giving up")
		return "", nil
	}

	prev := &buildbot.Build{
		Master:      b.Master,
		Buildername: b.Buildername,
		Number:      b.Number - 1,
	}

	cache := buildRevCache(c, prev)
	err := memcache.Get(c, cache)
	if err == nil {
		// fast path
		return string(cache.Value()), nil
	}

	// slow path
	if err != memcache.ErrCacheMiss {
		logging.WithError(err).Warningf(c, "memcache.get failed for key %q", cache.Key())
	}
	fetched, err := getBuild(c, prev.ID(), false, false)
	if err != nil {
		return "", err
	}

	var prevRev string
	if fetched != nil && commitHashRe.MatchString(fetched.Sourcestamp.Revision) {
		prevRev = fetched.Sourcestamp.Revision
	} else {
		// slowest path
		// May happen if there is a gap in build numbers or
		// if someone scheduled a build manually with no or HEAD revision.
		// Rare case.

		// This is a recursive call of itself.
		// The results are memcached along the stack though.
		if prevRev, err = getPrevRev(c, b, maxRecursionDepth-1); err != nil {
			return "", err
		}
	}
	cache.SetValue([]byte(prevRev))
	memcache.Set(c, cache)
	return prevRev, nil
}
834173
func (s *PerUserKeySeed) derivePrevKey() (res NaclSecretBoxKey, err error) {
	return s.DeriveSymmetricKey(DeriveReasonPUKPrev)
}
195609
func (ci CellID) PrevWrap() CellID {
	p := ci.Prev()
	if uint64(p) < wrapOffset {
		return p
	}
	return CellID(uint64(p) + wrapOffset)
}
1183001
func (alle *assetLruListElement) Prev() *assetLruListElement {
	if p := alle.prev; alle.list != nil && p != &alle.list.root {
		return p
	}
	return nil
}
940550
func (id KSUID) Prev() KSUID {
	max := makeUint128(math.MaxUint64, math.MaxUint64)

	t := id.Timestamp()
	u := uint128Payload(id)
	v := sub128(u, makeUint128(0, 1))

	if v == max { // overflow
		t--
	}

	return v.ksuid(t)
}
1228068
func (ev *ChangeWatchResp) GetPrevValue(prevVal proto.Message) (prevExists bool, err error) {
	if ev.message.OperationType == PutDel_DEL {
		return false, err
	}

	return false, err //TODO prev value
}
311638
func (i *iterator) Next() (key []byte, value []byte) {
	if i.err != nil {
		return nil, nil
	}

	if i.dataBucket == nil {
		return nil, nil
	}

	if i.nextKeys == nil {
		return nil, nil
	}

	if len(i.keyCache) == 0 {
		newKeys, err := i.nextKeys(i.prepCursor, i.indexCursor)
		i.prepCursor = false
		if err != nil {
			i.err = err
			return nil, nil
		}

		if len(newKeys) == 0 {
			return nil, nil
		}

		i.keyCache = append(i.keyCache, newKeys...)
	}

	nextKey := i.keyCache[0]
	i.keyCache = i.keyCache[1:]

	val := i.dataBucket.Get(nextKey)

	return nextKey, val
}
12141
func (t byTime) Less(i, j int) bool {
	return t[i].Time.Before(t[j].Time)
}
575634
func (iter *ExprIter) Next() (found bool) {
	defer func() {
		iter.matched = found
	}()

	// Iterate child firstly.
	for i := len(iter.Children) - 1; i >= 0; i-- {
		if !iter.Children[i].Next() {
			continue
		}

		for j := i + 1; j < len(iter.Children); j++ {
			iter.Children[j].Reset()
		}
		return true
	}

	// It's root node.
	if iter.Group == nil {
		return false
	}

	// Otherwise, iterate itself to find more matched equivalent expressions.
	for elem := iter.Element.Next(); elem != nil; elem = elem.Next() {
		expr := elem.Value.(*GroupExpr)
		exprOperand := GetOperand(expr.ExprNode)

		if !iter.Operand.Match(exprOperand) {
			// All the Equivalents which have the same Operand are continuously
			// stored in the list. Once the current equivalent can not Match
			// the Operand, the rest can not, either.
			return false
		}

		if len(iter.Children) != len(expr.Children) {
			continue
		}

		allMatched := true
		for i := range iter.Children {
			iter.Children[i].Group = expr.Children[i]
			if !iter.Children[i].Reset() {
				allMatched = false
				break
			}
		}

		if allMatched {
			iter.Element = elem
			return true
		}
	}
	return false
}