// pyindex converts an index into a real index like python.
// Returns an index to use and whether the index is safe to use.
768054
func pyindex(index, len int) (int, bool) {
	if len <= 0 {
		return 0, false
	}
	// wrap from the end
	if index < 0 {
		index = len + index
	}
	if index < 0 || index >= len {
		return 0, false
	}
	return index, true
}
385299
func GetWordIndex(word string) (int, bool) {
	idx, ok := wordMap[word]
	return idx, ok
}
285024
func (r *Reader) toHex(input string) []byte {
	result, err := hex.DecodeString(prune(input))
	if err != nil {
		return []byte{}
	}
	return result
}
1206677
func (s *IndicesExistsTypeService) Index(index ...string) *IndicesExistsTypeService {
	s.index = append(s.index, index...)
	return s
}
199707
func minIndex(indices ...int) int {
	min := -1

	for _, j := range indices {
		if j < 0 {
			continue
		}
		if min == -1 {
			min = j
		} else if j < min {
			min = j
		}
	}
	return min
}
266812
func shIndex(L *lua.LState) int {
	index := L.CheckString(2)

	switch index {
	case "cmd":
		L.Push(L.NewFunction(shPathCmd(L)))
		return 1
	case "print":
		L.Push(L.NewFunction(shPrint))
		return 1
	case "ok":
		L.Push(L.NewFunction(shOk))
		return 1
	case "lines":
		L.Push(L.NewFunction(shLines))
		return 1
	case "success":
		L.Push(L.NewFunction(shSuccess))
		return 1
	case "exitcode":
		L.Push(L.NewFunction(shExitCode))
		return 1
	case "stdout", "stderr", "combinedOutput":
		L.Push(L.NewFunction(shOutput(index)))
		return 1
	default:
		return shCmd(L)
	}

}
325479
func (r *attrRange) idx(h int) int {
	if h < int(r.base) {
		return tooSmall
	}
	if int(h) >= int(r.base)+len(r.aa) {
		return tooLarge
	}
	return h - int(r.base)
}
779313
func (table *Table) AddIndex(index *Index) {
	table.Indexes[index.Name] = index
}
861987
func (s *IndicesSegmentsService) Index(indices ...string) *IndicesSegmentsService {
	s.index = append(s.index, indices...)
	return s
}
905106
func (c *CacheMemDB) GetByPrefix(indexName string, indexValues ...interface{}) ([]*Index, error) {
	if !validIndexName(indexName) {
		return nil, fmt.Errorf("invalid index name %q", indexName)
	}

	indexName = indexName + "_prefix"

	// Get all the objects
	iter, err := c.db.Txn(false).Get(tableNameIndexer, indexName, indexValues...)
	if err != nil {
		return nil, err
	}

	var indexes []*Index
	for {
		obj := iter.Next()
		if obj == nil {
			break
		}
		index, ok := obj.(*Index)
		if !ok {
			return nil, fmt.Errorf("failed to cast cached index")
		}

		indexes = append(indexes, index)
	}

	return indexes, nil
}
420280
func (p *parser) scanHex(c int) (rune, error) {

	i := 0

	if p.charsRight() >= c {
		for c > 0 {
			d := hexDigit(p.moveRightGetChar())
			if d < 0 {
				break
			}
			i *= 0x10
			i += d
			c--
		}
	}

	if c > 0 {
		return 0, p.getErr(ErrTooFewHex)
	}

	return rune(i), nil
}
328507
func DropTxIndex(db database.DB, interrupt <-chan struct{}) error {
	err := dropIndex(db, addrIndexKey, addrIndexName, interrupt)
	if err != nil {
		return err
	}

	return dropIndex(db, txIndexKey, txIndexName, interrupt)
}
1261773
func (db *DB) LIndex(key []byte, index int32) ([]byte, error) {
	if err := checkKeySize(key); err != nil {
		return nil, err
	}

	var seq int32
	var headSeq int32
	var tailSeq int32
	var err error

	metaKey := db.lEncodeMetaKey(key)

	it := db.bucket.NewIterator()
	defer it.Close()

	headSeq, tailSeq, _, err = db.lGetMeta(it, metaKey)
	if err != nil {
		return nil, err
	}

	if index >= 0 {
		seq = headSeq + index
	} else {
		seq = tailSeq + index + 1
	}

	sk := db.lEncodeListKey(key, seq)
	v := it.Find(sk)

	return v, nil
}
642449
func (sim *simra) GetZIndex(s Spriter) (int, error) {
	sp := s.(*sprite)
	return sim.spritecontainer.GetZIndex(&sp.Sprite)
}
612082
func (d *Context) GetPropIndex(objIndex int, arrIndex uint) bool {
	return int(C.duk_get_prop_index(d.duk_context, C.duk_idx_t(objIndex), C.duk_uarridx_t(arrIndex))) == 1
}
304337
func (v List) Index(i int) Value {
	if !(0 <= i && i < len(v)) {
		return Undefined{}
	}
	return v[i]
}
48856
func (c *Client) Index(bucket, index, key, start, end string) (*RpbIndexResp, error) {
	return c.index(nil, bucket, index, key, start, end)
}