// helper functions
// returns the min index >= 0
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
}
1043000
func (l chunkByIndex) Less(i, j int) bool {
	ii := l[i].Index()
	ij := l[j].Index()
	return ii < ij
}
583349
func (l *lagLogger) Min() int {
	if len(l.measurements) == 0 {
		return -1
	}
	min := int(l.measurements[0].highWaterMark - l.measurements[0].readOffset)
	for _, m := range l.measurements[1:] {
		lag := int(m.highWaterMark - m.readOffset)
		if lag < min {
			min = lag
		}
	}
	return min
}
304337
func (v List) Index(i int) Value {
	if !(0 <= i && i < len(v)) {
		return Undefined{}
	}
	return v[i]
}
1185993
func getIndex(s string) (int, string) {
	arrayMatches := arrayAccesRegex.FindStringSubmatch(s)
	if len(arrayMatches) > 0 {
		// Get the key into the map
		selector := arrayMatches[1]
		// Get the index into the array at the key
		// We know this cannt fail because arrayMatches[2] is an int for sure
		index, _ := strconv.Atoi(arrayMatches[2])
		return index, selector
	}
	return -1, s
}
839123
func valueToRangeIndex(indexValue Value, length int64, negativeIsZero bool) int64 {
	index := indexValue.number().int64
	if negativeIsZero {
		if index < 0 {
			index = 0
		}
		// minimum(index, length)
		if index >= length {
			index = length
		}
		return index
	}

	if index < 0 {
		index += length
		if index < 0 {
			index = 0
		}
	} else {
		if index > length {
			index = length
		}
	}
	return index
}
875871
func (t *LLRB) Min() Item {
	h := t.root
	if h == nil {
		return nil
	}
	for h.Left != nil {
		h = h.Left
	}
	return h.Item
}
73955
func (r *DateRule) Min(min time.Time) *DateRule {
	r.min = min
	return r
}
1299720
func MinimumDepthFor(max int64, shift uint32) (uint32, bool) {
	for depth := uint32(0); depth < 32; depth++ {
		if validIndexPos(int(max), shift, depth) {
			return depth, true
		}
	}
	return 0, false
}
196365
func min(i, k int) int {
	switch {
	case i < k:
		return i
	case k < i:
		return k
	default:
		return k
	}
}
1089995
func MinByDir(a, b int, dir Direction) int {
	if dir == POSITIVE {
		return a
	}

	return b
}
1374374
func Min(values []int64) int64 {
	if len(values) == 0 {
		return 0
	}
	if isSorted(values) {
		return values[0]
	}
	min := values[0]
	for i := 1; i < len(values); i++ {
		v := values[i]
		if min > v {
			min = v
		}
	}
	return min
}
73239
func (pd *PictureData) Index(at Vec) int {
	at = at.Sub(pd.Rect.Min.Map(math.Floor))
	x, y := int(at.X), int(at.Y)
	return y*pd.Stride + x
}
995292
func Min(v1, v2 Vect) (out Vect) {
	if v1.X < v2.X {
		out.X = v1.X
	} else {
		out.X = v2.X
	}

	if v1.Y < v2.Y {
		out.Y = v1.Y
	} else {
		out.Y = v2.Y
	}
	return
}
477079
func (t *Tree) Min() Interface {
	if t.Root == nil {
		return nil
	}
	return t.Root.min().Elem
}
997039
func (q *NumericRangeQuery) Min(min float32, inclusive bool) *NumericRangeQuery {
	q.options["min"] = min
	q.options["inclusive_min"] = inclusive
	return q
}
1303745
func minInt(x int, others ...int) int {
	min := x
	for _, y := range others {
		if y < min {
			min = y
		}
	}
	return min
}