// Reverse returns the reverse of this Key.
//   NewKey("/Comedy/MontyPython/Actor:JohnCleese").Reverse()
//   NewKey("/Actor:JohnCleese/MontyPython/Comedy")
174849
func (k Key) Reverse() Key {
	l := k.List()
	r := make([]string, len(l), len(l))
	for i, e := range l {
		r[len(l)-i-1] = e
	}
	return KeyWithNamespaces(r)
}
199085
func (db *GoLevelDB) ReverseIterator(start, end []byte) Iterator {
	itr := db.db.NewIterator(nil, nil)
	return newGoLevelDBIterator(itr, start, end, true)
}
1007444
func ReverseBytes32(x uint32) uint32 {
	const m = 1<<32 - 1
	x = x>>8&(m3&m) | x&(m3&m)<<8
	return x>>16 | x<<16
}
787481
func Reverse(list []*rspb.Release, sortFn func([]*rspb.Release)) {
	sortFn(list)
	for i, j := 0, len(list)-1; i < j; i, j = i+1, j-1 {
		list[i], list[j] = list[j], list[i]
	}
}
847188
func (dc *Context) InvertY() {
	dc.Translate(0, float64(dc.height))
	dc.Scale(1, -1)
}
1090372
func ReverseIP(IP string) string {
	var reverseIP []string

	if net.ParseIP(IP).To4() != nil {
		reverseIP = strings.Split(IP, ".")
		l := len(reverseIP)
		for i, j := 0, l-1; i < l/2; i, j = i+1, j-1 {
			reverseIP[i], reverseIP[j] = reverseIP[j], reverseIP[i]
		}
	} else {
		reverseIP = strings.Split(IP, ":")

		// Reversed IPv6 is represented in dotted decimal instead of the typical
		// colon hex notation
		for key := range reverseIP {
			if len(reverseIP[key]) == 0 { // expand the compressed 0s
				reverseIP[key] = strings.Repeat("0000", 8-strings.Count(IP, ":"))
			} else if len(reverseIP[key]) < 4 { // 0-padding needed
				reverseIP[key] = strings.Repeat("0", 4-len(reverseIP[key])) + reverseIP[key]
			}
		}

		reverseIP = strings.Split(strings.Join(reverseIP, ""), "")

		l := len(reverseIP)
		for i, j := 0, l-1; i < l/2; i, j = i+1, j-1 {
			reverseIP[i], reverseIP[j] = reverseIP[j], reverseIP[i]
		}
	}

	return strings.Join(reverseIP, ".")
}
1036000
func (p *Polyline) Reverse() {
	for i := 0; i < len(*p)/2; i++ {
		(*p)[i], (*p)[len(*p)-i-1] = (*p)[len(*p)-i-1], (*p)[i]
	}
}
233748
func ReverseStrings(s []string) []string {
	for i, j := 0, len(s)-1; i < len(s)/2; i, j = i+1, j-1 {
		s[i], s[j] = s[j], s[i]
	}
	return s
}
1132595
func (txn *tikvTxn) IterReverse(k kv.Key) (kv.Iterator, error) {
	tikvTxnCmdCountWithSeekReverse.Inc()
	start := time.Now()
	defer func() {
		tikvTxnCmdHistogramWithSeekReverse.Observe(time.Since(start).Seconds())
	}()

	return txn.us.IterReverse(k)
}
1360953
func (s *BufferStore) IterReverse(k Key) (Iterator, error) {
	bufferIt, err := s.MemBuffer.IterReverse(k)
	if err != nil {
		return nil, err
	}
	retrieverIt, err := s.r.IterReverse(k)
	if err != nil {
		return nil, err
	}
	return NewUnionIter(bufferIt, retrieverIt, true)
}
300008
func (t *TagSet) Reverse() {
	for i, j := 0, len(t.Filters)-1; i < j; i, j = i+1, j-1 {
		t.Filters[i], t.Filters[j] = t.Filters[j], t.Filters[i]
		t.SeriesKeys[i], t.SeriesKeys[j] = t.SeriesKeys[j], t.SeriesKeys[i]
	}
}
870103
func (g *Graph) Reverse() *Graph {
	reversed := New(Directed)
	if g.Kind == Undirected {
		reversed = New(Undirected)
	}
	// O(V)
	for _ = range g.nodes {
		reversed.MakeNode()
	}
	// O(V + E)
	for _, node := range g.nodes {
		for _, edge := range node.edges {
			reversed.MakeEdge(reversed.nodes[edge.end.index].container,
				reversed.nodes[node.index].container)
		}
	}
	return reversed
}
612423
func (m Menu) Reverse() Menu {
	for i, j := 0, len(m)-1; i < j; i, j = i+1, j-1 {
		m[i], m[j] = m[j], m[i]
	}

	return m
}
539223
func (*Binary) ReverseMap(_ VCursor, ksids [][]byte) ([]sqltypes.Value, error) {
	var reverseIds = make([]sqltypes.Value, len(ksids))
	for rownum, keyspaceID := range ksids {
		if keyspaceID == nil {
			return nil, fmt.Errorf("Binary.ReverseMap: keyspaceId is nil")
		}
		reverseIds[rownum] = sqltypes.MakeTrusted(sqltypes.VarBinary, keyspaceID)
	}
	return reverseIds, nil
}
205049
func (g *MapQuestGeocoder) ReverseGeocode(p *Point) (string, error) {
	queryStr, err := mapquestReverseGeocodeQueryStr(p)
	if err != nil {
		return "", err
	}

	data, err := g.Request(queryStr)
	if err != nil {
		return "", err
	}

	res := []*mapQuestReverseGeocodeResponse{}
	err = json.Unmarshal(data, &res)
	if err != nil {
		return "", err
	}

	road := res[0].Address.Road
	city := res[0].Address.City
	state := res[0].Address.State
	postcode := res[0].Address.PostCode
	countryCode := res[0].Address.CountryCode

	resStr := fmt.Sprintf("%s %s %s %s %s", road, city, state, postcode, countryCode)
	return resStr, nil
}
1217921
func (s *BytesStore) reverse(srcPos, destPos int64) {
	assert(srcPos < destPos)
	assert(destPos < s.position())
	// fmt.Printf("reverse src=%v dest=%v\n", srcPos, destPos)

	srcBlockIndex := int(srcPos >> s.blockBits)
	src := int(srcPos & int64(s.blockMask))
	srcBlock := s.blocks[srcBlockIndex]

	destBlockIndex := int(destPos >> s.blockBits)
	dest := int(destPos & int64(s.blockMask))
	destBlock := s.blocks[destBlockIndex]

	// fmt.Printf("  srcBlock=%v destBlock=%v\n", srcBlockIndex, destBlockIndex)

	limit := int((destPos - srcPos + 1) / 2)
	for i := 0; i < limit; i++ {
		// fmt.Printf("  cycle src=%v dest=%v\n", src, dest)
		srcBlock[src], destBlock[dest] = destBlock[dest], srcBlock[src]
		if src++; src == int(s.blockSize) {
			srcBlockIndex++
			srcBlock = s.blocks[srcBlockIndex]
			fmt.Printf("  set destBlock=%v srcBlock=%v\n", destBlock, srcBlock)
			src = 0
		}

		if dest--; dest == -1 {
			destBlockIndex--
			destBlock = s.blocks[destBlockIndex]
			fmt.Printf("  set destBlock=%v srcBlock=%v\n", destBlock, srcBlock)
			dest = int(s.blockSize - 1)
		}
	}
}
946120
func (g *OpenCageGeocoder) ReverseGeocode(p *Point) (string, error) {
	queryStr, err := opencageReverseGeocodeQueryStr(p)
	if err != nil {
		return "", err
	}

	data, err := g.Request(queryStr)
	if err != nil {
		return "", err
	}

	res := &opencageReverseGeocodeResponse{}
	err = json.Unmarshal(data, res)
	if err != nil {
		return "", err
	}

	if len(res.Results) == 0 {
		return "", opencageZeroResultsError
	}

	return res.Results[0].Formatted, nil
}