func Swap(d []int64, x, y int) {
	if x == y || len(d) <= 1 || x > len(d) || y > len(d) {
		return
	}
	tmp := d[x]
	d[x] = d[y]
	d[y] = tmp
}
Swap two indices value of slice.
package ints64
import (
	"github.com/shuLhan/share/lib/ints"
)
func Count(d []int64, class int64) (count int) {
	if len(d) == 0 {
		return
	}
	for x := 0; x < len(d); x++ {
		if d[x] == class {
			count++
		}
	}
	return
}
func Counts(d, classes []int64) (counts []int) {
	if len(classes) == 0 {
		return
	}
	counts = make([]int, len(classes))
	for x, c := range classes {
		counts[x] = Count(d, c)
	}
	return
}
func IndirectSort(d []int64, asc bool) (sortedIdx []int) {
	if len(d) == 0 {
		return
	}
	sortedIdx = make([]int, len(d))
	for x := 0; x < len(d); x++ {
		sortedIdx[x] = x
	}
	InplaceMergesort(d, sortedIdx, 0, len(d), asc)
	return
}
func InplaceMergesort(d []int64, idx []int, l, r int, asc bool) {
	if l+7 >= r {
		InsertionSortWithIndices(d, idx, l, r, asc)
		return
	}
	res := (r + l) % 2
	c := (r + l) / 2
	if res == 1 {
		c++
	}
	InplaceMergesort(d, idx, l, c, asc)
	InplaceMergesort(d, idx, c, r, asc)
	if asc {
		if d[c-1] <= d[c] {
			return
		}
	} else {
		if d[c-1] >= d[c] {
			return
		}
	}
	inplaceMerge(d, idx, l, c, r, asc)
}
func InsertionSortWithIndices(d []int64, ids []int, l, r int, asc bool) {
	for x := l; x < r; x++ {
		for y := x + 1; y < r; y++ {
			if asc {
				if d[x] > d[y] {
					ints.Swap(ids, x, y)
					Swap(d, x, y)
				}
			} else {
				if d[x] < d[y] {
					ints.Swap(ids, x, y)
					Swap(d, x, y)
				}
			}
		}
	}
}
func Max(d []int64) (v int64, i int, ok bool) {
	if len(d) == 0 {
		return 0, 0, false
	}
	v = d[0]
	i = 0
	for x := 1; x < len(d); x++ {
		if d[x] > v {
			v = d[x]
			i = x
		}
	}
	return v, i, true
}
func IsExist(d []int64, v int64) bool {
	for x := 0; x < len(d); x++ {
		if d[x] == v {
			return true
		}
	}
	return false
}
func MaxCountOf(d, classes []int64) (int64, bool) {
	if len(classes) == 0 {
		return -1, false
	}
	if len(d) == 0 {
		return -2, false
	}
	counts := Counts(d, classes)
	_, i, _ := ints.Max(counts)
	return classes[i], true
}
func MaxRange(d []int64, l, r int) (v int64, i int) {
	v = d[l]
	i = l
	for l++; l < r; l++ {
		if d[l] >= v {
			v = d[l]
			i = l
		}
	}
	return
}
func Min(d []int64) (v int64, i int, ok bool) {
	if len(d) == 0 {
		return 0, 0, false
	}
	v = d[0]
	i = 0
	for x := 1; x < len(d); x++ {
		if d[x] < v {
			v = d[x]
			i = x
		}
	}
	return v, i, true
}
func MinRange(d []int64, l, r int) (v int64, i int) {
	v = d[l]
	i = l
	for l++; l < r; l++ {
		if d[l] <= v {
			v = d[l]
			i = l
		}
	}
	return
}
func SortByIndex(d *[]int64, sortedIds []int) {
	newd := make([]int64, len(*d))
	for x := range sortedIds {
		newd[x] = (*d)[sortedIds[x]]
	}
	(*d) = newd
}
func Sum(d []int64) (sum int64) {
	for x := 0; x < len(d); x++ {
		sum += d[x]
	}
	return
}