// MinimumShiftFor returns the lowest minimum shift value that can be used to index
// the given maximum position with the given index depth.
769863
func MinimumShiftFor(max int64, depth uint32) (uint32, bool) {
	for shift := uint32(0); shift < 32; shift++ {
		if validIndexPos(int(max), shift, depth) {
			return shift, true
		}
	}
	return 0, false
}
562048
func (lt *LifeTime) Shift(d time.Duration) {
	if d > 0 && lt.timer != nil {
		lt.timer.Reset(d)
	}
}
1309260
func (r *RuneBuffer) MoveForward() {
	if r.idx == len(r.buf) {
		return
	}
	r.idx++
}
196365
func min(i, k int) int {
	switch {
	case i < k:
		return i
	case k < i:
		return k
	default:
		return k
	}
}
49107
func MinOf(a []float64) (retVal float64) {
	if len(a) < 1 {
		panic("Cannot find the min of an empty slice")
	}
	return Reduce(min, a[0], a[1:]...)
}
926180
func (e *executor) executeShiftShard(ctx context.Context, index string, c *pql.Call, shard uint64) (*Row, error) {
	n, _, err := c.IntArg("n")
	if err != nil {
		return nil, fmt.Errorf("executeShiftShard: %v", err)
	}

	if len(c.Children) == 0 {
		return nil, errors.New("Shift() requires an input row")
	} else if len(c.Children) > 1 {
		return nil, errors.New("Shift() only accepts a single row input")
	}

	row, err := e.executeBitmapCallShard(ctx, index, c.Children[0], shard)
	if err != nil {
		return nil, err
	}

	return row.Shift(n)
}
855198
func (z *Lexer) Shift() []byte {
	b := z.buf[z.start:z.pos]
	z.start = z.pos
	return b
}
862764
func (d *Driver) SupportsShifting() bool {
	if os.Getenv("_TEST_FORCE_SUPPORT_SHIFTING") == "yes-please" {
		return true
	}
	return d.options.mountProgram != ""
}
1042765
func SliceShiftRight(s1 []byte, bits uint) []byte {
	l := len(s1)
	s := make([]byte, l)

	r := bits / 8
	rs := bits - r*8

	for i := 0; i < l; i++ {
		// relative index
		ri := i - int(r)
		bl := byte(0)
		if ri >= 1 {
			bl = s1[ri-1] << (8 - rs)
		}

		bu := byte(0)
		if ri >= 0 {
			bu = s1[ri] >> rs
		}
		s[i] = bl | bu
	}

	return s
}
1140370
func (list *List) UnshiftN(n int) []string {
	if n < 1 || n >= list.length {
		return make([]string, 0)
	}
	slice := make([]string, n)
	for i := 0; i < n; i++ {
		slice[i] = list.Unshift()
	}
	return slice
}
277134
func MinBigInt(a, b *big.Int) *big.Int {
	if a.Cmp(b) < 0 {
		return a
	}
	return b
}
1270289
func SeriesSegmentSize(id uint16) uint32 {
	const min = 22 // 4MB
	const max = 28 // 256MB

	shift := id + min
	if shift >= max {
		shift = max
	}
	return 1 << shift
}
939100
func Min(data Interface) (min float64, min_index int) {
	Len := data.Len()
	min = data.Get(0)

	for i := 0; i < Len; i++ {
		xi := data.Get(i)

		if xi < min {
			min = xi
			min_index = i
		}

		if math.IsNaN(xi) {
			min = xi
			min_index = i
			return
		}
	}

	return
}
367594
func MinMaxIndex(inReal []float64, inTimePeriod int) ([]float64, []float64) {

	outMinIdx := make([]float64, len(inReal))
	outMaxIdx := make([]float64, len(inReal))

	nbInitialElementNeeded := (inTimePeriod - 1)
	startIdx := nbInitialElementNeeded
	outIdx := startIdx
	today := startIdx
	trailingIdx := startIdx - nbInitialElementNeeded
	highestIdx := -1
	highest := 0.0
	lowestIdx := -1
	lowest := 0.0
	for today < len(inReal) {
		tmpLow, tmpHigh := inReal[today], inReal[today]
		if highestIdx < trailingIdx {
			highestIdx = trailingIdx
			highest = inReal[highestIdx]
			i := highestIdx
			i++
			for i <= today {
				tmpHigh = inReal[i]
				if tmpHigh > highest {
					highestIdx = i
					highest = tmpHigh
				}
				i++
			}
		} else if tmpHigh >= highest {
			highestIdx = today
			highest = tmpHigh
		}
		if lowestIdx < trailingIdx {
			lowestIdx = trailingIdx
			lowest = inReal[lowestIdx]
			i := lowestIdx
			i++
			for i <= today {
				tmpLow = inReal[i]
				if tmpLow < lowest {
					lowestIdx = i
					lowest = tmpLow
				}
				i++
			}
		} else if tmpLow <= lowest {
			lowestIdx = today
			lowest = tmpLow
		}
		outMaxIdx[outIdx] = float64(highestIdx)
		outMinIdx[outIdx] = float64(lowestIdx)
		outIdx++
		trailingIdx++
		today++
	}
	return outMinIdx, outMaxIdx
}
821086
func FFTShiftF(buffer []float64) []float64 {
	var tmp float64
	size := len(buffer) / 2
	for i := 0; i < size; i++ {
		tmp = buffer[i]
		buffer[i] = buffer[size+i]
		buffer[size+i] = tmp
	}
	return buffer
}
283101
func leftShift(a *decimal, k uint) {
	delta := leftcheats[k].delta
	if prefixIsLessThan(a.d[0:a.nd], leftcheats[k].cutoff) {
		delta--
	}

	r := a.nd         // read index
	w := a.nd + delta // write index
	n := 0

	// Pick up a digit, put down a digit.
	for r--; r >= 0; r-- {
		n += (int(a.d[r]) - '0') << k
		quo := n / 10
		rem := n - 10*quo
		w--
		if w < len(a.d) {
			a.d[w] = byte(rem + '0')
		} else if rem != 0 {
			a.trunc = true
		}
		n = quo
	}

	// Put down extra digits.
	for n > 0 {
		quo := n / 10
		rem := n - 10*quo
		w--
		if w < len(a.d) {
			a.d[w] = byte(rem + '0')
		} else if rem != 0 {
			a.trunc = true
		}
		n = quo
	}

	a.nd += delta
	if a.nd >= len(a.d) {
		a.nd = len(a.d)
	}
	a.dp += delta
	trim(a)
}
1160696
func (s *rowSegment) Shift() (*rowSegment, error) {
	//TODO deal with overflow
	data, err := s.data.Shift(1)
	if err != nil {
		return nil, errors.Wrap(err, "shifting roaring data")
	}

	return &rowSegment{
		data:  *data,
		shard: s.shard,
		n:     data.Count(),
	}, nil
}