// PropagateConstant propagate constant values of deterministic predicates in a condition.
13745
func (s *propConstSolver) PropagateConstant(ctx sessionctx.Context, conditions []Expression) []Expression {
	s.ctx = ctx
	return s.solve(conditions)
}
1221845
func (a *AwaitPromiseArgs) SetGeneratePreview(generatePreview bool) *AwaitPromiseArgs {
	a.GeneratePreview = &generatePreview
	return a
}
234111
func (v *primitiveSchemaVisitor) VisitPrimitive(result *proto.Primitive) {
	v.Result = result
	v.Kind = "primitive"
}
904640
func (b *PlanBuilder) buildProjectionForWindow(p LogicalPlan, expr *ast.WindowFuncExpr, aggMap map[*ast.AggregateFuncExpr]int) (LogicalPlan, []property.Item, []property.Item, []expression.Expression, error) {
	b.optFlag |= flagEliminateProjection

	var items []*ast.ByItem
	if expr.Spec.Name.L != "" {
		ref, ok := b.windowSpecs[expr.Spec.Name.L]
		if !ok {
			return nil, nil, nil, nil, ErrWindowNoSuchWindow.GenWithStackByArgs(expr.Spec.Name.O)
		}
		expr.Spec = ref
	}
	spec := expr.Spec
	if spec.Ref.L != "" {
		ref, ok := b.windowSpecs[spec.Ref.L]
		if !ok {
			return nil, nil, nil, nil, ErrWindowNoSuchWindow.GenWithStackByArgs(spec.Ref.O)
		}
		err := mergeWindowSpec(&spec, &ref)
		if err != nil {
			return nil, nil, nil, nil, err
		}
	}

	lenPartition := 0
	if spec.PartitionBy != nil {
		items = append(items, spec.PartitionBy.Items...)
		lenPartition = len(spec.PartitionBy.Items)
	}
	if spec.OrderBy != nil {
		items = append(items, spec.OrderBy.Items...)
	}
	projLen := len(p.Schema().Columns) + len(items) + len(expr.Args)
	proj := LogicalProjection{Exprs: make([]expression.Expression, 0, projLen)}.Init(b.ctx)
	schema := expression.NewSchema(make([]*expression.Column, 0, projLen)...)
	for _, col := range p.Schema().Columns {
		proj.Exprs = append(proj.Exprs, col)
		schema.Append(col)
	}

	transformer := &itemTransformer{}
	propertyItems := make([]property.Item, 0, len(items))
	for _, item := range items {
		newExpr, _ := item.Expr.Accept(transformer)
		item.Expr = newExpr.(ast.ExprNode)
		it, np, err := b.rewrite(item.Expr, p, aggMap, true)
		if err != nil {
			return nil, nil, nil, nil, err
		}
		p = np
		if col, ok := it.(*expression.Column); ok {
			propertyItems = append(propertyItems, property.Item{Col: col, Desc: item.Desc})
			continue
		}
		proj.Exprs = append(proj.Exprs, it)
		col := &expression.Column{
			ColName:  model.NewCIStr(fmt.Sprintf("%d_proj_window_%d", p.ID(), schema.Len())),
			UniqueID: b.ctx.GetSessionVars().AllocPlanColumnID(),
			RetType:  it.GetType(),
		}
		schema.Append(col)
		propertyItems = append(propertyItems, property.Item{Col: col, Desc: item.Desc})
	}

	newArgList := make([]expression.Expression, 0, len(expr.Args))
	for _, arg := range expr.Args {
		newArg, np, err := b.rewrite(arg, p, aggMap, true)
		if err != nil {
			return nil, nil, nil, nil, err
		}
		p = np
		switch newArg.(type) {
		case *expression.Column, *expression.Constant:
			newArgList = append(newArgList, newArg)
			continue
		}
		proj.Exprs = append(proj.Exprs, newArg)
		col := &expression.Column{
			ColName:  model.NewCIStr(fmt.Sprintf("%d_proj_window_%d", p.ID(), schema.Len())),
			UniqueID: b.ctx.GetSessionVars().AllocPlanColumnID(),
			RetType:  newArg.GetType(),
		}
		schema.Append(col)
		newArgList = append(newArgList, col)
	}

	proj.SetSchema(schema)
	proj.SetChildren(p)
	return proj, propertyItems[:lenPartition], propertyItems[lenPartition:], newArgList, nil
}
176618
func (m ConcurrentMap) SetIfAbsent(key string, value interface{}) bool {
	// Get map shard.
	shard := m.GetShard(key)
	shard.Lock()
	_, ok := shard.items[key]
	if !ok {
		shard.items[key] = value
	}
	shard.Unlock()
	return !ok
}
726811
func buildConstantStruct(c ConstantMap) (*ConstantStruct, error) {
	fields := make(map[string]ConstantValue, len(c))
	for _, pair := range c {
		s, isString := pair.Key.(ConstantString)
		if !isString {
			return nil, fmt.Errorf(
				"%v is not a string: all keys must be strings", pair.Key)
		}
		fields[string(s)] = pair.Value
	}
	return &ConstantStruct{Fields: fields}, nil
}
650686
func (shardSwap *shardSchemaSwap) propagateToAllTablets(withMasterReparent bool) (err error) {
	shardSwap.markPropagationInProgress()
	defer shardSwap.markPropagationDone(&err)

	for {
		shardSwap.updatePropagationProgressUI()
		tablet, err := shardSwap.findNextTabletToSwap()
		// Update UI immediately after finding next tablet because the total number of tablets or
		// the number of tablets with swapped schema can change in it.
		shardSwap.updatePropagationProgressUI()
		if err == errOnlyMasterLeft {
			if withMasterReparent {
				err = shardSwap.reparentFromMaster(tablet)
				if err != nil {
					return err
				}
			} else {
				return nil
			}
		}
		if err == nil {
			if tablet == nil {
				shardSwap.propagationUINode.Message = ""
				shardSwap.propagationUINode.BroadcastChanges(false /* updateChildren */)
				return nil
			}
			err = shardSwap.swapOnTablet(tablet)
			if err == nil {
				shardSwap.numTabletsSwapped++
				shardSwap.addPropagationLog(fmt.Sprintf("Schema is successfully swapped on tablet %v.", tablet.Alias))
				continue
			}
			if err == errNoBackupWithSwap {
				if err := shardSwap.takeSeedBackup(); err != nil {
					return err
				}
				continue
			}
			shardSwap.addPropagationLog(fmt.Sprintf("Error swapping schema on tablet %v: %v", tablet.Alias, err))
		} else {
			shardSwap.addPropagationLog(fmt.Sprintf("Error searching for next tablet to swap schema on: %v.", err))
		}

		shardSwap.addPropagationLog(fmt.Sprintf("Sleeping for %v.", *delayBetweenErrors))
		select {
		case <-shardSwap.parent.ctx.Done():
			return shardSwap.parent.ctx.Err()
		case <-time.After(*delayBetweenErrors):
			// Waiting is done going to the next loop.
		}
		shardSwap.propagationUINode.Message = ""
		shardSwap.propagationUINode.BroadcastChanges(false /* updateChildren */)
	}
}
166897
func (adapter *Registry) PropagateChanges(ctx context.Context, txData map[string]datasync.ChangeValue) error {
	var events []func(done chan error)

	for _, sub := range adapter.subscriptions {
		var changes []datasync.ProtoWatchResp

		for _, prefix := range sub.KeyPrefixes {
			for key, val := range txData {
				if !strings.HasPrefix(key, prefix) {
					continue
				}

				var (
					prev   datasync.KeyVal
					curRev int64
				)

				if val.GetChangeType() == datasync.Delete {
					if _, prev = adapter.lastRev.Del(key); prev != nil {
						curRev = prev.GetRevision() + 1
					} else {
						continue
					}
				} else {
					_, prev, curRev = adapter.lastRev.Put(key, val)
				}

				changes = append(changes, &ChangeResp{
					Key:        key,
					ChangeType: val.GetChangeType(),
					CurrVal:    val,
					CurrRev:    curRev,
					PrevVal:    prev,
				})
			}
		}

		if len(changes) > 0 {
			sendTo := func(sub *Subscription) func(done chan error) {
				return func(done chan error) {
					sub.ChangeChan <- &ChangeEvent{
						ctx:      ctx,
						Changes:  changes,
						delegate: &DoneChannel{done},
					}
				}
			}
			events = append(events, sendTo(sub))
		}
	}

	done := make(chan error, 1)
	go AggregateDone(events, done)

	select {
	case err := <-done:
		if err != nil {
			return err
		}
	case <-time.After(PropagateChangesTimeout):
		logrus.DefaultLogger().Warnf("Timeout of aggregated data-change callbacks (%v)",
			PropagateChangesTimeout)
	}

	return nil
}
410776
func precomputeDistances(p PointSet) (float64, []float64) {
	total := 0.0
	dists := make([]float64, len(p)-1)
	for i := 0; i < len(p)-1; i++ {
		dists[i] = p[i].DistanceFrom(&p[i+1])
		total += dists[i]
	}

	return total, dists
}
254603
func init() {
	for i := range precomputedFactor {
		precomputedFactor[i] = math.Exp(-1.0 * float64(i) * lambda)
	}
}
371851
func (vs *volumeSnapshotter) propagateVolumeSnapshotCondition(snapshotDataName string, condition *crdv1.VolumeSnapshotCondition) error {
	var snapshotDataObj crdv1.VolumeSnapshotData
	err := vs.restClient.Get().
		Name(snapshotDataName).
		Resource(crdv1.VolumeSnapshotDataResourcePlural).
		Do().Into(&snapshotDataObj)
	if err != nil {
		return err
	}

	newCondition := &crdv1.VolumeSnapshotDataCondition{
		Type:               (crdv1.VolumeSnapshotDataConditionType)(condition.Type),
		Status:             condition.Status,
		Message:            condition.Message,
		LastTransitionTime: condition.LastTransitionTime,
	}
	oldStatus := snapshotDataObj.Status.DeepCopy()

	status := snapshotDataObj.Status
	isEqual := false
	if oldStatus.Conditions == nil || len(oldStatus.Conditions) == 0 || newCondition.Type != oldStatus.Conditions[len(oldStatus.Conditions)-1].Type {
		status.Conditions = append(status.Conditions, *newCondition)
	} else {
		oldCondition := oldStatus.Conditions[len(oldStatus.Conditions)-1]
		if newCondition.Status == oldCondition.Status {
			newCondition.LastTransitionTime = oldCondition.LastTransitionTime
		}
		status.Conditions[len(status.Conditions)-1] = *newCondition
		isEqual = newCondition.Type == oldCondition.Type &&
			newCondition.Status == oldCondition.Status &&
			newCondition.Reason == oldCondition.Reason &&
			newCondition.Message == oldCondition.Message &&
			newCondition.LastTransitionTime.Equal(&oldCondition.LastTransitionTime)
	}
	if !isEqual {
		var newSnapshotDataObj crdv1.VolumeSnapshotData
		snapshotDataObj.Status = status
		if snapshotDataObj.Status.CreationTimestamp.IsZero() && newCondition.Type == crdv1.VolumeSnapshotDataConditionReady {
			snapshotDataObj.Status.CreationTimestamp = newCondition.LastTransitionTime
		}
		err = vs.restClient.Put().
			Name(snapshotDataName).
			Resource(crdv1.VolumeSnapshotDataResourcePlural).
			Body(&snapshotDataObj).
			Do().Into(&newSnapshotDataObj)
		if err != nil {
			return err
		}
		glog.Infof("VolumeSnapshot status propagated to VolumeSnapshotData")
		return nil
	}

	return nil
}
993332
func (s *GroupType) SetPrecedence(v int64) *GroupType {
	s.Precedence = &v
	return s
}
18313
func (rc *ReadinessCheck) SetProtocol(proto string) *ReadinessCheck {
	rc.Protocol = proto
	return rc
}
190321
func (s *DescribeConditionalForwardersOutput) SetConditionalForwarders(v []*ConditionalForwarder) *DescribeConditionalForwardersOutput {
	s.ConditionalForwarders = v
	return s
}
321375
func promoteConstToTyped(from ConstType, c constValue, to reflect.Type, expr Expr) (
	constValue, []error) {
        return convertConstToTyped(from, c, to, false, expr)
}
78911
func (s *UpdateGroupInput) SetPrecedence(v int64) *UpdateGroupInput {
	s.Precedence = &v
	return s
}
1244150
func (pe *PathExp) WithInstance(instance string) (*PathExp, error) {
	parts, err := Split("instance", instance)
	if err != nil {
		return nil, err
	}

	segment, err := parseMultiple("instance", parts, true)
	if err != nil {
		return nil, err
	}

	return &PathExp{
		Org:        pe.Org,
		Project:    pe.Project,
		Envs:       pe.Envs,
		Services:   pe.Services,
		Identities: pe.Identities,
		Instances:  segment,
	}, nil
}