// Reduce runs the RadialGeo reduction using the threshold of the RadialGeoReducer.
// The threshold is expected to be in meters.
550391
func (r RadialGeoReducer) Reduce(path *geo.Path) *geo.Path {
	return RadialGeo(path, r.Threshold)
}
157504
func (s *SelectStatement) Reduce(valuer Valuer) *SelectStatement {
	stmt := s.Clone()
	stmt.Condition = Reduce(stmt.Condition, valuer)
	for _, d := range stmt.Dimensions {
		d.Expr = Reduce(d.Expr, valuer)
	}

	for _, source := range stmt.Sources {
		switch source := source.(type) {
		case *SubQuery:
			source.Statement = source.Statement.Reduce(valuer)
		}
	}
	return stmt
}
656131
func (r *renoState) reduceSlowStartThreshold() {
	r.s.sndSsthresh = r.s.outstanding / 2
	if r.s.sndSsthresh < 2 {
		r.s.sndSsthresh = 2
	}

}
938803
func (daemon *Daemon) reducePsContainer(container *container.Snapshot, ctx *listContext, reducer containerReducer) (*types.Container, error) {
	// filter containers to return
	switch includeContainerInList(container, ctx) {
	case excludeContainer:
		return nil, nil
	case stopIteration:
		return nil, errStopIteration
	}

	// transform internal container struct into api structs
	newC, err := reducer(container, ctx)
	if err != nil {
		return nil, err
	}

	// release lock because size calculation is slow
	if ctx.Size {
		sizeRw, sizeRootFs := daemon.imageService.GetContainerLayerSize(newC.ID)
		newC.SizeRw = sizeRw
		newC.SizeRootFs = sizeRootFs
	}
	return newC, nil
}
536239
func (d *distanceHeap) Less(i, j int) bool {
	return d.nodes[i].dist < d.nodes[j].dist
}
1121040
func (s ByEmergencyShutdown) Less(i, j int) bool {
	if s.CancellableServices[i].EmergencyShutdownLevel == s.CancellableServices[j].EmergencyShutdownLevel {
		// If emergency shutdown level is the same, order by reverse start level
		return s.CancellableServices[i].StartLevel-1 > s.CancellableServices[j].StartLevel-1
	} else {
		return s.CancellableServices[i].EmergencyShutdownLevel-1 < s.CancellableServices[j].EmergencyShutdownLevel-1
	}
}
244002
func Reduce(rf Reducer, rs ...mesos.Resource) (r *mesos.Resource) {
	if rf == nil {
		panic("Reduce: reducer func may not be nil")
	}
	for i := range rs {
		r = rf(r, &rs[i])
	}
	return
}
1062302
func (s *containerSorter) Less(i, j int) bool {
	return s.by(s.containers[i], s.containers[j])
}
469573
func Reduce(f func(a, b float32) float32, def float32, l ...float32) (retVal float32) {
	retVal = def
	if len(l) == 0 {
		return
	}

	for _, v := range l {
		retVal = f(retVal, v)
	}
	return
}
609275
func (g *Geometry) Simplify(tolerance float64) (*Geometry, error) {
	return g.simplify("simplify", cGEOSSimplify, tolerance)
}
119066
func (daemon *Daemon) reduceContainers(config *types.ContainerListOptions, reducer containerReducer) ([]*types.Container, error) {
	if err := config.Filters.Validate(acceptedPsFilterTags); err != nil {
		return nil, err
	}

	var (
		view       = daemon.containersReplica.Snapshot()
		containers = []*types.Container{}
	)

	ctx, err := daemon.foldFilter(view, config)
	if err != nil {
		return nil, err
	}

	// fastpath to only look at a subset of containers if specific name
	// or ID matches were provided by the user--otherwise we potentially
	// end up querying many more containers than intended
	containerList, err := daemon.filterByNameIDMatches(view, ctx)
	if err != nil {
		return nil, err
	}

	for i := range containerList {
		t, err := daemon.reducePsContainer(&containerList[i], ctx, reducer)
		if err != nil {
			if err != errStopIteration {
				return nil, err
			}
			break
		}
		if t != nil {
			containers = append(containers, t)
			ctx.idx++
		}
	}

	return containers, nil
}
327774
func (b *Buffer) Truncate(n int) {
	switch {
	case n < 0 || n > b.Len():
		panic("leveldb/util.Buffer: truncation out of range")
	case n == 0:
		// Reuse buffer space.
		b.off = 0
	}
	b.buf = b.buf[0 : b.off+n]
}
53708
func MapReduce(mr MapReducer) error {
	mapEmitChan := make(KeyValueChan)
	reduceEmitChan := make(KeyValueChan)

	go performReducing(mr, mapEmitChan, reduceEmitChan)
	go performMapping(mr, mapEmitChan)

	return mr.Consume(reduceEmitChan)
}
1369223
func Reduce(arr, reduceFunc, acc interface{}) float64 {
	arrValue := redirectValue(reflect.ValueOf(arr))

	if !IsIteratee(arrValue.Interface()) {
		panic("First parameter must be an iteratee")
	}

	returnType := reflect.TypeOf(Reduce).Out(0)

	isFunc := IsFunction(reduceFunc, 2, 1)
	isRune := reflect.TypeOf(reduceFunc).Kind() == reflect.Int32

	if !(isFunc || isRune) {
		panic("Second argument must be a valid function or rune")
	}

	accValue := reflect.ValueOf(acc)
	sliceElemType := sliceElem(arrValue.Type())

	if isRune {
		if arrValue.Kind() == reflect.Slice && sliceElemType.Kind() == reflect.Interface {
			accValue = accValue.Convert(returnType)
		} else {
			accValue = accValue.Convert(sliceElemType)
		}
	} else {
		accValue = accValue.Convert(reflect.TypeOf(reduceFunc).In(0))
	}

	accType := accValue.Type()

	// Generate reduce function if was passed as rune
	if isRune {
		reduceSign := reduceFunc.(int32)

		if ok := map[rune]bool{'+': true, '*': true}[reduceSign]; !ok {
			panic("Invalid reduce sign, allowed: '+' and '*'")
		}

		in := []reflect.Type{accType, sliceElemType}
		out := []reflect.Type{accType}
		funcType := reflect.FuncOf(in, out, false)

		reduceFunc = reflect.MakeFunc(funcType, func(args []reflect.Value) []reflect.Value {
			acc := args[0].Interface()
			elem := args[1].Interface()

			var result float64
			params := []interface{}{acc, elem}
			switch reduceSign {
			case '+':
				result = Sum(params)
			case '*':
				result = Product(params)
			}

			return []reflect.Value{reflect.ValueOf(result).Convert(accType)}
		}).Interface()
	}

	funcValue := reflect.ValueOf(reduceFunc)
	funcType := funcValue.Type()

	for i := 0; i < arrValue.Len(); i++ {
		if accType.ConvertibleTo(funcType.In(0)) {
			accValue = accValue.Convert(funcType.In(0))
		}

		arrElementValue := arrValue.Index(i)
		if sliceElemType.ConvertibleTo(funcType.In(1)) {
			arrElementValue = arrElementValue.Convert(funcType.In(1))
		}

		result := funcValue.Call([]reflect.Value{accValue, arrElementValue})
		accValue = result[0]
	}

	resultInterface := accValue.Convert(returnType).Interface()
	return resultInterface.(float64)
}
116941
func (p *Point) Normalize() *Point {
	dist := math.Sqrt(p[0]*p[0] + p[1]*p[1])

	if dist == 0 {
		p[0] = 0
		p[1] = 0

		return p
	}

	p[0] /= dist
	p[1] /= dist

	return p
}
6500
func (d *Dataset) Reduce(name string, reducerId gio.ReducerId) (ret *Dataset) {

	name = name + ".Reduce"

	ret = d.LocalReduceBy(name+".LocalReduce", reducerId, nil)
	if len(d.Shards) > 1 {
		ret = ret.MergeTo(name, 1).LocalReduceBy(name+".LocalReduce2", reducerId, nil)
	}
	return ret
}
1019003
func Reduce(expr Expr, valuer Valuer) Expr {
	expr = reduce(expr, valuer)

	// Unwrap parens at top level.
	if expr, ok := expr.(*ParenExpr); ok {
		return expr.Expr
	}
	return expr
}