/*
Add a [virtual] epsilon transition between source and dest. Dest
state must already have all transitions added because this method
simply copies those same transitions over to source.
*/
548910
func (a *Automaton) addEpsilon(source, dest int) {
	t := newTransition()
	count := a.initTransition(dest, t)
	for i := 0; i < count; i++ {
		a.nextTransition(t)
		a.addTransitionRange(source, t.dest, t.min, t.max)
	}
	if a.IsAccept(dest) {
		a.setAccept(source, true)
	}
}
1263977
func (c Cap) ApproxEqual(other Cap) bool {
	const epsilon = 1e-14
	return c.center.ApproxEqual(other.center) &&
		math.Abs(c.height-other.height) <= epsilon ||
		c.IsEmpty() && other.height <= epsilon ||
		other.IsEmpty() && c.height <= epsilon ||
		c.IsFull() && other.height >= 2-epsilon ||
		other.IsFull() && c.height >= 2-epsilon
}
221654
func InEpsilonf(t TestingT, expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) bool {
	if h, ok := t.(tHelper); ok {
		h.Helper()
	}
	return InEpsilon(t, expected, actual, epsilon, append([]interface{}{msg}, args...)...)
}
724146
func (g *Generator) AddProcessCapabilityBounding(c string) error {
	cp := strings.ToUpper(c)
	if err := validate.CapValid(cp, g.HostSpecific); err != nil {
		return err
	}

	g.initConfigProcessCapabilities()

	var foundBounding bool
	for _, cap := range g.Config.Process.Capabilities.Bounding {
		if strings.ToUpper(cap) == cp {
			foundBounding = true
			break
		}
	}
	if !foundBounding {
		g.Config.Process.Capabilities.Bounding = append(g.Config.Process.Capabilities.Bounding, cp)
	}

	return nil
}
39709
func (b *Blueprint) Add(t *Transition) {
	idx := b.transitions.InsertPos(t)
	trans := make(list, len(b.transitions)+1)

	copy(trans, b.transitions[:idx])
	copy(trans[idx+1:], b.transitions[idx:])
	trans[idx] = t
	b.transitions = trans
}
1331116
func (s *Scheme) AddGeneratedConversionFunc(a, b interface{}, fn conversion.ConversionFunc) error {
	return s.converter.RegisterGeneratedUntypedConversionFunc(a, b, fn)
}
765105
func (r *RefCtr) Add(i uint32) {
	if v := atomic.AddUint32(&r.refcnt, i); v == 0 {
		r.cancel()
	}
}
447072
func (g *Generator) AddProcessCapabilityPermitted(c string) error {
	cp := strings.ToUpper(c)
	if err := validate.CapValid(cp, g.HostSpecific); err != nil {
		return err
	}

	g.initConfigProcessCapabilities()

	var foundPermitted bool
	for _, cap := range g.Config.Process.Capabilities.Permitted {
		if strings.ToUpper(cap) == cp {
			foundPermitted = true
			break
		}
	}
	if !foundPermitted {
		g.Config.Process.Capabilities.Permitted = append(g.Config.Process.Capabilities.Permitted, cp)
	}

	return nil
}
616583
func (tsv *TabletServer) transition(newState int64) {
	tsv.mu.Lock()
	tsv.setState(newState)
	tsv.mu.Unlock()
}
147449
func (wo *WriteOperations) AddStep(js json.RawMessage) error {
	t, err := GetElementType(js)
	if err != nil {
		return err
	}
	switch t {
	case "tee":
		ts, err := NewTeeFromJSON(js)
		if err != nil {
			return err
		}
		wo.Steps = append(wo.Steps, ts)
	case "encoder":
		step, err := EncoderFromJSON(js)
		if err != nil {
			return err
		}
		wo.Steps = append(wo.Steps, step)
	case "output":
		return errors.New("element of type 'output' should appear only once as the last element of a writer")
	default:
		return fmt.Errorf("element of type '%s' is not available inside a writer", t)
	}
	return nil
}
353869
func (g *Generator) AddMultipleProcessEnv(envs []string) {
	g.initConfigProcess()

	for _, val := range envs {
		split := strings.SplitN(val, "=", 2)
		g.addEnv(val, split[0])
	}
}
591815
func (s *Staert) AddSource(src Source) {
	s.sources = append(s.sources, src)
}
1088263
func (a *Automaton) finishCurrentState() {
	numTransitions := a.states[2*a.curState+1]
	assert(numTransitions > 0)

	offset := a.states[2*a.curState]
	start := offset / 3
	util.NewInPlaceMergeSorter(destMinMaxSorter(a.transitions)).Sort(start, start+numTransitions)

	// reduce any "adjacent" transitions:
	upto, min, max, dest := 0, -1, -1, -1

	for i := 0; i < numTransitions; i++ {
		tDest := a.transitions[offset+3*i]
		tMin := a.transitions[offset+3*i+1]
		tMax := a.transitions[offset+3*i+2]

		if dest == tDest {
			if tMin <= max+1 {
				if tMax > max {
					max = tMax
				}
			} else {
				if dest != -1 {
					a.transitions[offset+3*upto] = dest
					a.transitions[offset+3*upto+1] = min
					a.transitions[offset+3*upto+2] = max
					upto++
				}
				min, max = tMin, tMax
			}
		} else {
			if dest != -1 {
				a.transitions[offset+3*upto] = dest
				a.transitions[offset+3*upto+1] = min
				a.transitions[offset+3*upto+2] = max
				upto++
			}
			dest, min, max = tDest, tMin, tMax
		}
	}

	if dest != -1 {
		// last transition
		a.transitions[offset+3*upto] = dest
		a.transitions[offset+3*upto+1] = min
		a.transitions[offset+3*upto+2] = max
		upto++
	}

	a.transitions = a.transitions[:len(a.transitions)-(numTransitions-upto)*3]
	a.states[2*a.curState+1] = upto

	// sort transitions by min/max/dest:
	util.NewInPlaceMergeSorter(minMaxDestSorter(a.transitions)).Sort(start, start+upto)

	if a.deterministic && upto > 1 {
		lastMax := a.transitions[offset+2]
		for i := 1; i < upto; i++ {
			min = a.transitions[offset+3*i+1]
			if min <= lastMax {
				a.deterministic = false
				break
			}
			lastMax = a.transitions[offset+3*i+2]
		}
	}
}
1340543
func (s *State) T(matcher matcher.Matcher, next *State) *State {
	s.Transitions = append(s.Transitions, &Transition{Matcher: matcher, Next: next})
	return next
}
1144125
func (a *MovFnAggregation) Source() (interface{}, error) {
	source := make(map[string]interface{})
	params := make(map[string]interface{})
	source["moving_fn"] = params

	// Add buckets paths
	switch len(a.bucketsPaths) {
	case 0:
	case 1:
		params["buckets_path"] = a.bucketsPaths[0]
	default:
		params["buckets_path"] = a.bucketsPaths
	}

	// Script
	if a.script != nil {
		src, err := a.script.Source()
		if err != nil {
			return nil, err
		}
		params["script"] = src
	}

	if a.format != "" {
		params["format"] = a.format
	}
	if a.gapPolicy != "" {
		params["gap_policy"] = a.gapPolicy
	}
	params["window"] = a.window

	// Add Meta data if available
	if len(a.meta) > 0 {
		source["meta"] = a.meta
	}

	return source, nil
}
431202
func (s *Attempt_State) Evolve(newState Attempt_State) error {
	nextStates := validAttemptStateEvolution[*s]
	if nextStates == nil {
		return fmt.Errorf("invalid state transition: no transitions defined for %s", *s)
	}

	if newState == *s {
		return nil
	}

	for _, val := range nextStates {
		if newState == val {
			*s = newState
			return nil
		}
	}

	return fmt.Errorf("invalid state transition %v -> %v", *s, newState)
}
1253546
func (f *FSM) Transition() error {
	f.eventMu.Lock()
	defer f.eventMu.Unlock()
	return f.doTransition()
}