code: func (iter *dbCacheIterator) chooseIterator(forwards bool) bool {
  	// Skip any keys at the current database iterator position that are
  	// being updated by the cache.
  	iter.skipPendingUpdates(forwards)
  
  	// When both iterators are exhausted, the iterator is exhausted too.
  	if !iter.dbIter.Valid() && !iter.cacheIter.Valid() {
  		iter.currentIter = nil
  		return false
  	}
  
  	// Choose the database iterator when the cache iterator is exhausted.
  	if !iter.cacheIter.Valid() {
  		iter.currentIter = iter.dbIter
  		return true
  	}
  
  	// Choose the cache iterator when the database iterator is exhausted.
  	if !iter.dbIter.Valid() {
  		iter.currentIter = iter.cacheIter
  		return true
  	}
  
  	// Both iterators are valid, so choose the iterator with either the
  	// smaller or larger key depending on the forwards flag.
  	compare := bytes.Compare(iter.dbIter.Key(), iter.cacheIter.Key())
  	if (forwards && compare > 0) || (!forwards && compare < 0) {
  		iter.currentIter = iter.cacheIter
  	} else {
  		iter.currentIter = iter.dbIter
  	}
  	return true
  }
docs: // chooseIterator first skips any entries in the database iterator that are
  // being updated by the cache and sets the current iterator to the appropriate
  // iterator depending on their validity and the order they compare in while taking
  // into account the direction flag.  When the iterator is being moved forwards
  // and both iterators are valid, the iterator with the smaller key is chosen and
  // vice versa when the iterator is being moved backwards.