// returns either the first (if first is true) or the last
// index of the logs bucket.
961080
func (r *raftLog) getIndex(first bool) (uint64, error) {
	tx, err := r.conn.Begin(false)
	if err != nil {
		return 0, err
	}
	var (
		key []byte
		idx uint64
	)
	curs := tx.Bucket(logsBucket).Cursor()
	if first {
		key, _ = curs.First()
	} else {
		key, _ = curs.Last()
	}
	if key != nil {
		idx = binary.BigEndian.Uint64(key)
	}
	tx.Rollback()
	return idx, nil
}
711675
func SortLogger(outputLogger log.Logger, keys ...string) log.Logger {
	indices := make(map[string]int, len(keys))
	for i, k := range keys {
		indices[k] = i
	}
	return log.LoggerFunc(func(keyvals ...interface{}) error {
		sortKeyvals(indices, keyvals)
		return outputLogger.Log(keyvals...)
	})
}
920504
func GetFirstChar(s string) string {
	firstChar := ""
	for _, r := range s {
		firstChar = fmt.Sprintf("%c", r)
		break
	}
	return firstChar
}
472668
func (b *Bucketer) Bucket(sample float64) int {
	return sort.Search(b.NumBuckets(), func(i int) bool { return sample < b.lowerBounds[i] }) - 1
}
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}
}
267266
func (c *chunkedSeq) ChunkedFirst() iseq.Chunk {
	return newArrayChunk2(c.node, c.offset)
}
1181736
func (c *index) SeekFirst(r kv.Retriever) (iter table.IndexIterator, err error) {
	upperBound := c.prefix.PrefixNext()
	it, err := r.Iter(c.prefix, upperBound)
	if err != nil {
		return nil, err
	}
	return &indexIter{it: it, idx: c, prefix: c.prefix}, nil
}
419707
func findFirstNewline(b []byte) []byte {
	index := bytes.IndexByte(b, '\n')
	if index < 0 || index == len(b)-1 {
		return nil
	}
	return b[(index + 1):]
}
797723
func (prod *AwsCloudwatchLogs) timeIndex(messages []*core.Message) (index int) {
	if len(messages) == 0 {
		return 0
	}
	firstTimestamp := messages[0].GetCreationTime().Unix()
	for i, message := range messages {
		if (message.GetCreationTime().Unix() - firstTimestamp) > int64(maxBatchTimeSpan) {
			break
		}
		index = i + 1
	}
	return index
}
1320178
func (w *ConditionalWrite) Last() string {
	if len(w.Queued) == 0 {
		return ""
	}
	return w.Queued[len(w.Queued)-1]
}
1172312
func (b *BoltStore) LastIndex() (uint64, error) {
	tx, err := b.conn.Begin(false)
	if err != nil {
		return 0, err
	}
	defer tx.Rollback()

	curs := tx.Bucket(dbLogs).Cursor()
	if last, _ := curs.Last(); last == nil {
		return 0, nil
	} else {
		return bytesToUint64(last), nil
	}
}
740693
func (iter *Iterator) Last() bool {
	// Seek the limit key if the iterator was created with one.  This will
	// result in the first key smaller than the limit key, or an exhausted
	// iterator if no such key exists.
	iter.isNew = false
	if iter.limitKey != nil {
		return iter.seek(iter.limitKey, false, false)
	}

	// The highest key is in the right-most node.
	iter.parents = parentStack{}
	for node := iter.root; node != nil; node = node.right {
		if node.right == nil {
			iter.node = node
			return true
		}
		iter.parents.Push(node)
	}
	return false
}
630112
func (rs Recoverings) Last() *Recovering {
	if len(rs) > 0 {
		return rs[len(rs)-1]
	}
	return nil
}
845828
func (d *Document) FindStartOfPreviousWord() int {
	x := d.TextBeforeCursor()
	i := strings.LastIndexByte(x, ' ')
	if i != -1 {
		return i + 1
	}
	return 0
}
8908
func (mvl *MetricsList) Last() *MetricValue {
	if len(mvl.data) > 0 {
		mvl.Sort()
		return mvl.data[len(mvl.data)-1]
	}
	return nil
}
23784
func (p PgXLog) Compare(xlog1, xlog2 xlog.Position) (int, error) {
	p1, err := parse(xlog1)
	if err != nil {
		return 0, err
	}
	p2, err := parse(xlog2)
	if err != nil {
		return 0, err
	}

	if p1[0] == p2[0] && p1[1] == p2[1] {
		return 0, nil
	}
	if p1[0] > p2[0] || p1[0] == p2[0] && p1[1] > p2[1] {
		return 1, nil
	}
	return -1, nil
}
629190
func lastSequenceIndex(str string) int {
	if len(str) == 0 {
		return -1
	}

	if len(str) == 1 {
		return 0
	}

	sequenceChar := str[0:1]
	lastPos := 0
	for i := 1; i < len(str); i++ {
		if str[i:i+1] != sequenceChar {
			break
		}

		lastPos = i
	}

	return lastPos
}