// IndexRank gets rank of table key in index, InvalidRank returned if key not found
962233
func (eng *engine) IndexRank(index Index, key interface{}) (int64, error) {
	s := eng.newSession()
	defer s.Close()
	action, rank, err := s.indexRank(index, key)
	if err != nil {
		return rank, s.catch("IndexRank: "+action, err)
	}
	return rank, nil
}
1289605
func closestIndex(s []rune, r rune, pos int) int {

	desc := naiveSearchDescending(s, r, pos)
	asc := naiveSearchAscending(s, r, pos)

	da := math.Abs(float64(desc - pos))
	aa := math.Abs(float64(asc - pos))

	if da < aa {
		return desc
	}
	return asc
}
909133
func (a *KVData) Index(k string) []int {
	v, _ := a.index[k]
	return v
}
205816
func (s *NodesStatsService) IndexMetric(indexMetric ...string) *NodesStatsService {
	s.indexMetric = append(s.indexMetric, indexMetric...)
	return s
}
124976
func (c *Connection) IndexStatus(indexList []string) (*Response, error) {
	r := Request{
		Conn:      c,
		IndexList: indexList,
		method:    "GET",
		api:       "_status",
	}

	return r.Run()
}
423253
func (s *Selection) Index() int {
	if len(s.Nodes) > 0 {
		return newSingleSelection(s.Nodes[0], s.document).PrevAll().Length()
	}
	return -1
}
753804
func (skv *sortableKeyvals) Less(i, j int) bool {
	return skv.keyRank(i) < skv.keyRank(j)
}
1183970
func (s *UpdateByQueryService) Index(index ...string) *UpdateByQueryService {
	s.index = append(s.index, index...)
	return s
}
928456
func (s *nodeStack) index(n *Node) int {
	for i := len(*s) - 1; i >= 0; i-- {
		if (*s)[i] == n {
			return i
		}
	}
	return -1
}
1324718
func (s *GetFilterOutput) SetRank(v int64) *GetFilterOutput {
	s.Rank = &v
	return s
}
1115433
func (s *GlobalStore) keyNodeIndex(key []byte, addr common.Address) (index int, found bool) {
	k := string(key)
	l := len(s.keyNodes[k])
	index = sort.Search(l, func(i int) bool {
		return bytes.Compare(s.keyNodes[k][i][:], addr[:]) >= 0
	})
	found = index < l && s.keyNodes[k][index] == addr
	return index, found
}
143030
func (s *GlobalStore) keyIndex(key []byte) (index int, found bool) {
	l := len(s.keys)
	index = sort.Search(l, func(i int) bool {
		return bytes.Compare(s.keys[i], key) >= 0
	})
	found = index < l && bytes.Equal(s.keys[index], key)
	return index, found
}
509592
func (s *UpdateFilterInput) SetRank(v int64) *UpdateFilterInput {
	s.Rank = &v
	return s
}
1281849
func (s *IndicesOpenService) Index(index string) *IndicesOpenService {
	s.index = index
	return s
}
380693
func indexTableSchema() *memdb.TableSchema {
	return &memdb.TableSchema{
		Name: "index",
		Indexes: map[string]*memdb.IndexSchema{
			"id": &memdb.IndexSchema{
				Name:         "id",
				AllowMissing: false,
				Unique:       true,
				Indexer: &memdb.StringFieldIndex{
					Field:     "Key",
					Lowercase: true,
				},
			},
		},
	}
}
272453
func (db *DB) UpdateCertificateRank(id, rank int64) error {
	_, err := db.Exec("UPDATE certificates SET cisco_umbrella_rank=$1 WHERE id=$2", rank, id)
	return err
}
1286862
func (s VertexSet) rank(n int) int {
	if len(s.set) == 0 || n < s.set[0].a {
		return -1
	}
	// The smallest index i such that n < set[i].a
	i := sort.Search(len(s.set), func(i int) bool {
		return n < s.set[i].a
	})
	in := s.set[i-1]
	if n >= in.b {
		return -1
	}
	return in.index + n - in.a
}