code: func indexEntryFor(entries []*logpb.LogIndex_Entry, i types.MessageIndex) int {
  	ui := uint64(i)
  	s := sort.Search(len(entries), func(i int) bool {
  		return entries[i].StreamIndex > ui
  	})
  
  	// The returned index is the one immediately after the index that we want. If
  	// our search returned 0, the first index entry is > our search entry, and we
  	// will return nil.
  	return s - 1
  }
docs: // indexEntryFor identifies the log index entry closest (<=) to the specified
  // index.
  //
  // If the first index entry is greater than our search index, -1 will be
  // returned. This should never happen in practice, though, since our index
  // construction always indexes log entry #0.
  //
  // It does this by performing a binary search over the index entries.