/*
Finds the largest entry whose value is less than or equal to c, or
0 if there is no such entry.
*/
346866
func findIndex(c int, points []int) int {
	a, b := 0, len(points)
	for b-a > 1 {
		d := int(uint(a+b) >> 1)
		if points[d] > c {
			b = d
		} else if points[d] < c {
			a = d
		} else {
			return d
		}
	}
	return a
}
1298420
func (l *Log) containsEntry(index uint64, term uint64) bool {
	entry := l.getEntry(index)
	return (entry != nil && entry.Term() == term)
}
734095
func findMSBSetNonZero64(x uint64) int {
	val := []uint64{0x2, 0xC, 0xF0, 0xFF00, 0xFFFF0000, 0xFFFFFFFF00000000}
	shift := []uint64{1, 2, 4, 8, 16, 32}
	var msbPos uint64
	for i := 5; i >= 0; i-- {
		if x&val[i] != 0 {
			x >>= shift[i]
			msbPos |= shift[i]
		}
	}
	return int(msbPos)
}
346641
func MaxOf(a []float64) (retVal float64) {
	if len(a) < 1 {
		panic("Cannot find the max of an empty slice")
	}
	return Reduce(max, a[0], a[1:]...)
}
771645
func (s SeqSet) search(q uint32) (i int, ok bool) {
	min, max := 0, len(s.Set)-1
	for min < max {
		if mid := (min + max) >> 1; s.Set[mid].Less(q) {
			min = mid + 1
		} else {
			max = mid
		}
	}
	if max < 0 || s.Set[min].Less(q) {
		return len(s.Set), false // q is the new largest value
	}
	return min, s.Set[min].Contains(q)
}
859412
func (b *Sortable) Less(i, j int) bool {
	for _, c := range b.Comparators {
		if c(i, j) {
			return true
		} else if c(j, i) {
			return false
		}
	}
	return false
}
1142943
func ContainsInt(s []int, v int) bool {
	for _, vv := range s {
		if vv == v {
			return true
		}
	}
	return false
}
23169
func compareByDigits(n1, n2 []rune) (less, greater, equal bool) {
	offset := len(n2) - len(n1)
	n1n2 := offset < 0 // len(n1) > len(n2)
	if n1n2 {
		// if n1 longer, swap with n2
		offset = -offset
		n1, n2 = n2, n1
	}

	var j int
	// len(n1) always be <= len(n2)
	for i := range n2 {
		var r1 rune
		if offset == 0 {
			// begin actual read
			r1 = n1[j]
			j++
		} else {
			// emulate zero-padding
			r1 = '0'
			offset--
		}

		r2 := n2[i]
		if r1 != r2 {
			if n1n2 {
				return r2 < r1, r2 > r1, false // actually r1 < r2
			}
			return r1 < r2, r1 > r2, false
		}
	}

	// numeric value equals, compare by length
	if n1n2 {
		// n1 was > n2
		return false, true, true
	}
	// eval a comparison only if n1 known to be <= n2
	return len(n1) < len(n2), len(n1) > len(n2), true
}
438203
func (s int64Sorter) Less(i, j int) bool {
	return s[i] < s[j]
}
378439
func (impl *Standard) Isamax(n int, x []float32, incX int) (retVal int) {
	// declared at cublasgen.h:384:17 enum CUBLAS_STATUS { ... } cublasIsamax ...
	if impl.e != nil {
		return
	}

	if n < 0 {
		panic("blas: n < 0")
	}
	if incX == 0 {
		panic("blas: zero x index increment")
	}
	if n == 0 || incX < 0 {
		return -1
	}
	if incX > 0 && (n-1)*incX >= len(x) {
		panic("blas: x index out of range")
	}
	if n == 0 {
		return
	}
	var ret C.int
	impl.e = status(C.cublasIsamax(C.cublasHandle_t(impl.h), C.int(n), (*C.float)(&x[0]), C.int(incX), &ret))
	return int(ret)
}
423515
func (sb *shardBuffer) oldestEntry() *entry {
	sb.mu.Lock()
	defer sb.mu.Unlock()

	if len(sb.queue) > 0 {
		return sb.queue[0]
	}
	return nil
}
247549
func cmp(x, y *Big, abs bool) int {
	if debug {
		x.validate()
		y.validate()
	}

	if x == y {
		return 0
	}

	// NaN cmp x
	// z cmp NaN
	// NaN cmp NaN
	if (x.form|y.form)&nan != 0 {
		return 0
	}

	// Fast path: Catches non-finite forms like zero and ±Inf, possibly signed.
	xs := x.ord(abs)
	ys := y.ord(abs)
	if xs != ys {
		if xs > ys {
			return +1
		}
		return -1
	}
	switch xs {
	case 0, +2, -2:
		return 0
	default:
		r := cmpabs(x, y)
		if xs < 0 && !abs {
			r = -r
		}
		return r
	}
}
1257065
func (d *MyDecimal) Compare(to *MyDecimal) int {
	if d.negative == to.negative {
		cmp, _ := doSub(d, to, nil)
		return cmp
	}
	if d.negative {
		return -1
	}
	return 1
}
953845
func maxfor(z *big.Int, n, sign int) {
	arith.Sub(z, arith.BigPow10(uint64(n)), 1)
	if sign < 0 {
		z.Neg(z)
	}
}
934617
func (ms *multiSorter) Less(i, j int) bool {
	p, q := &ms.stats[i], &ms.stats[j]
	// Try all but the last comparison.
	var k int
	for k = 0; k < len(ms.less)-1; k++ {
		less := ms.less[k]
		switch {
		case less(p, q):
			return true
		case less(q, p):
			return false
		}
		// p == q; try the next comparison.
	}
	return ms.less[k](p, q)
}
292406
func less(a, b uint32) bool {
	if a < b {
		return (b - a) <= MaxSerialIncrement
	}
	return (a - b) > MaxSerialIncrement
}
362010
func Max(v T) interface{} {
	x, _ := minmax(v, 1, true)
	return x.Interface()
}