// TODO: could we somehow [partially] tableize arc lookups
// look automaton?
/** Finds an arc leaving the incoming arc, replacing the arc in place.
 *  This returns null if the arc was not found, else the incoming arc. */
358151
func (t *FST) FindTargetArc(labelToMatch int, follow *Arc, arc *Arc, in BytesReader) (target *Arc, err error) {
	if labelToMatch == FST_END_LABEL {
		if follow.IsFinal() {
			if follow.target <= 0 {
				arc.flags = FST_BIT_LAST_ARC
			} else {
				arc.flags = 0
				// NOTE: nextArc is a node (not an address!) in this case:
				arc.nextArc = follow.target
				arc.node = follow.target
			}
			arc.Output = follow.NextFinalOutput
			arc.Label = FST_END_LABEL
			return arc, nil
		} else {
			return nil, nil
		}
	}

	// Short-circuit if this arc is in the root arc cache:
	if follow.target == t.startNode && labelToMatch < len(t.cachedRootArcs) {
		// LUCENE-5152: detect tricky cases where caller
		// modified previously returned cached root-arcs:
		t.assertRootArcs()
		if result := t.cachedRootArcs[labelToMatch]; result != nil {
			arc.copyFrom(result)
			return arc, nil
		}
		return nil, nil
	}

	if !targetHasArcs(follow) {
		return nil, nil
	}

	in.setPosition(t.getNodeAddress(follow.target))

	arc.node = follow.target

	// log.Printf("fta label=%v", labelToMatch)

	b, err := in.ReadByte()
	if err != nil {
		return nil, err
	}
	if b == FST_ARCS_AS_FIXED_ARRAY {
		// Arcs are full array; do binary search:
		arc.numArcs, err = AsInt(in.ReadVInt())
		if err != nil {
			return nil, err
		}
		if t.packed || t.version >= FST_VERSION_VINT_TARGET {
			arc.bytesPerArc, err = AsInt(in.ReadVInt())
			if err != nil {
				return nil, err
			}
		} else {
			arc.bytesPerArc, err = AsInt(in.ReadInt())
			if err != nil {
				return nil, err
			}
		}
		arc.posArcsStart = in.getPosition()
		for low, high := 0, arc.numArcs-1; low < high; {
			// log.Println("    cycle")
			mid := int(uint(low+high) / 2)
			in.setPosition(arc.posArcsStart)
			in.skipBytes(int64(arc.bytesPerArc*mid) + 1)
			midLabel, err := t.readLabel(in)
			if err != nil {
				return nil, err
			}
			cmp := midLabel - labelToMatch
			if cmp < 0 {
				low = mid + 1
			} else if cmp > 0 {
				high = mid - 1
			} else {
				arc.arcIdx = mid - 1
				// log.Println("    found!")
				return t.readNextRealArc(arc, in)
			}
		}

		return nil, nil
	}

	// Linear scan

	if _, err = t.readFirstRealTargetArc(follow.target, arc, in); err != nil {
		return nil, err
	}

	for {
		//System.out.println("  non-bs cycle");
		// TODO: we should fix this code to not have to create
		// object for the output of every arc we scan... only
		// for the matching arc, if found
		if arc.Label == labelToMatch {
			//System.out.println("    found!");
			return arc, nil
		} else if arc.Label > labelToMatch {
			return nil, nil
		} else if arc.isLast() {
			return nil, nil
		} else {
			if _, err = t.readNextRealArc(arc, in); err != nil {
				return nil, err
			}
		}
	}
}
85078
func (nm *NullMater) Go(a, b *IGenome) (IGenome, IGenome) {
	return NewGenome(*(*a).GetBits()), NewGenome(*(*b).GetBits())
}
1015962
func (r *rewinder) Lookahead() *rewinder {
	clone := &rewinder{}
	*clone = *r
	clone.limit = clone.cursor
	return clone
}
1242877
func (d *compressor) findMatch(pos int, prevHead int, prevLength int, lookahead int) (length, offset int, ok bool) {
	minMatchLook := maxMatchLength
	if lookahead < minMatchLook {
		minMatchLook = lookahead
	}

	win := d.window[0 : pos+minMatchLook]

	// We quit when we get a match that's at least nice long
	nice := len(win) - pos
	if d.nice < nice {
		nice = d.nice
	}

	// If we've got a match that's good enough, only look in 1/4 the chain.
	tries := d.chain
	length = prevLength
	if length >= d.good {
		tries >>= 2
	}

	wEnd := win[pos+length]
	wPos := win[pos:]
	minIndex := pos - windowSize

	for i := prevHead; tries > 0; tries-- {
		if wEnd == win[i+length] {
			n := matchLen(win[i:], wPos, minMatchLook)

			if n > length && (n > minMatchLength || pos-i <= 4096) {
				length = n
				offset = pos - i
				ok = true
				if n >= nice {
					// The match is good enough that we don't try to find a better one.
					break
				}
				wEnd = win[pos+n]
			}
		}
		if i == minIndex {
			// hashPrev[i & windowMask] has already been overwritten, so stop now.
			break
		}
		i = int(d.hashPrev[i&windowMask]) - d.hashOffset
		if i < minIndex || i < 0 {
			break
		}
	}
	return
}
766863
func (m *NullClusterManager) Inspect(arg0 string) (api.Node, error) {
	return api.Node{}, ErrNotImplemented
}
789838
func (s fakeObjectSlice) find(name string) int {
	lb := s.lowerBound(name)
	if lb < len(s) && s[lb].metadata.Name == name {
		return lb
	}

	return len(s)
}
264803
func FindParent(node *html.Node, matcher Matcher) (n *html.Node, ok bool) {
	for p := node.Parent; p != nil; p = p.Parent {
		if matcher(p) {
			return p, true
		}
	}
	return nil, false
}
849808
func (c *ARCCache) replace(b2ContainsKey bool) {
	t1Len := c.t1.Len()
	if t1Len > 0 && (t1Len > c.p || (t1Len == c.p && b2ContainsKey)) {
		k, _, ok := c.t1.RemoveOldest()
		if ok {
			c.b1.Add(k, nil)
		}
	} else {
		k, _, ok := c.t2.RemoveOldest()
		if ok {
			c.b2.Add(k, nil)
		}
	}
}
514706
func (association *Association) Find(value interface{}) *Association {
	association.scope.related(value, association.column)
	return association.setErr(association.scope.db.Error)
}
247612
func (b *Bmattermost) replaceAction(text string) (string, bool) {
	if strings.HasPrefix(text, "*") && strings.HasSuffix(text, "*") {
		return strings.Replace(text, "*", "", -1), true
	}
	return text, false
}
1101300
func (v *evalVisitor) findBlockParam(node *ast.PathExpression) (string, interface{}) {
	if len(node.Parts) > 0 {
		name := node.Parts[0]
		if value := v.blockParam(name); value != nil {
			return name, value
		}
	}

	return "", nil
}
16624
func reverse(a *Automaton) (*Automaton, map[int]bool) {
	if isEmpty(a) {
		return newEmptyAutomaton(), nil
	}

	numStates := a.numStates()

	// build a new automaton with all edges reversed
	b := newAutomatonBuilder()

	// initial node; we'll add epsilon transitions in the end:
	b.createState()
	for s := 0; s < numStates; s++ {
		b.createState()
	}

	// old initial state becomes new accept state:
	b.setAccept(1, true)

	t := newTransition()
	for s := 0; s < numStates; s++ {
		numTransitions := a.numTransitions(s)
		a.initTransition(s, t)
		for i := 0; i < numTransitions; i++ {
			a.nextTransition(t)
			b.addTransitionRange(t.dest+1, s+1, t.min, t.max)
		}
	}

	ans := b.finish()
	initialStates := make(map[int]bool)

	acceptStates := a.isAccept
	for s := acceptStates.NextSetBit(0); s != -1; s = acceptStates.NextSetBit(s + 1) {
		ans.addEpsilon(0, int(s+1))
		initialStates[int(s+1)] = true
	}

	ans.finishState()
	return ans, initialStates
}
1041852
func (d *DeploymentStatusRequest) GetAutoInactive() bool {
	if d == nil || d.AutoInactive == nil {
		return false
	}
	return *d.AutoInactive
}
454780
func lookupHelper(obj interface{}, field string, options *Options) interface{} {
	return Str(options.Eval(obj, field))
}
364336
func minimizeHopcroft(a *Automaton) *Automaton {
	if a.numStates() == 0 || !a.IsAccept(0) && a.numTransitions(0) == 0 {
		// fastmatch for common case
		return newEmptyAutomaton()
	}
	a = determinize(a)
	if a.numTransitions(0) == 1 {
		t := newTransition()
		a.transition(0, 0, t)
		if t.dest == 0 && t.min == MIN_CODE_POINT &&
			t.max == unicode.MaxRune {
			// accepts all strings
			return a
		}
	}
	a = totalize(a)

	// initialize data structure
	sigma := a.startPoints()
	sigmaLen, statesLen := len(sigma), a.numStates()

	reverse := make([][][]int, statesLen)
	for i, _ := range reverse {
		reverse[i] = make([][]int, sigmaLen)
	}
	partition := make([]map[int]bool, statesLen)
	splitblock := make([][]int, statesLen)
	block := make([]int, statesLen)
	active := make([][]*StateList, statesLen)
	for i, _ := range active {
		active[i] = make([]*StateList, sigmaLen)
	}
	active2 := make([][]*StateListNode, statesLen)
	for i, _ := range active2 {
		active2[i] = make([]*StateListNode, sigmaLen)
	}
	pending := list.New()
	pending2 := util.NewOpenBitSet() // sigmaLen * statesLen bits
	split := util.NewOpenBitSet()    // statesLen bits
	refine := util.NewOpenBitSet()   // statesLen bits
	refine2 := util.NewOpenBitSet()  // statesLen bits
	for q, _ := range splitblock {
		partition[q] = make(map[int]bool)
		for x, _ := range active[q] {
			active[q][x] = new(StateList)
		}
	}
	// find initial partition and reverse edges
	for q := 0; q < statesLen; q++ {
		j := or(a.IsAccept(q), 0, 1).(int)
		partition[j][q] = true
		block[q] = j
		for x, v := range sigma {
			n := a.step(q, v)
			assert2(n >= 0 && n < len(reverse), "%v", n)
			r := reverse[a.step(q, v)]
			r[x] = append(r[x], q)
		}
	}
	// initialize active sets
	for j := 0; j <= 1; j++ {
		for x := 0; x < sigmaLen; x++ {
			for q, _ := range partition[j] {
				if reverse[q][x] != nil {
					active2[q][x] = active[j][x].add(q)
				}
			}
		}
	}
	// initialize pending
	for x := 0; x < sigmaLen; x++ {
		j := or(active[0][x].size <= active[1][x].size, 0, 1).(int)
		pending.PushBack(&IntPair{j, x})
		pending2.Set(int64(x*statesLen + j))
	}
	// process pending until fixed point
	k := 2
	// fmt.Println("start min")
	for pending.Len() > 0 {
		// fmt.Println("  cycle pending")
		ip := pending.Remove(pending.Front()).(*IntPair)
		p, x := ip.n1, ip.n2
		// fmt.Printf("    pop n1=%v n2=%v\n", ip.n1, ip.n2)
		pending2.Clear(int64(x*statesLen + p))
		// find states that need to be split off their blocks
		for m := active[p][x].first; m != nil; m = m.next {
			if r := reverse[m.q][x]; r != nil {
				for _, i := range r {
					if !split.Get(int64(i)) {
						split.Set(int64(i))
						j := block[i]
						splitblock[j] = append(splitblock[j], i)
						if !refine2.Get(int64(j)) {
							refine2.Set(int64(j))
							refine.Set(int64(j))
						}
					}
				}
			}
		}
		// refine blocks
		for j := int(refine.NextSetBit(0)); j >= 0; j = int(refine.NextSetBit(int64(j) + 1)) {
			sb := splitblock[j]
			if len(sb) < len(partition[j]) {
				b1, b2 := partition[j], partition[k]
				for _, s := range sb {
					delete(b1, s)
					b2[s] = true
					block[s] = k
					for c, sn := range active2[s] {
						if sn != nil && sn.sl == active[j][c] {
							sn.remove()
							active2[s][c] = active[k][c].add(s)
						}
					}
				}
				// update pending
				for c, _ := range active[j] {
					aj := active[j][c].size
					ak := active[k][c].size
					ofs := int64(c * statesLen)
					if !pending2.Get(ofs+int64(j)) && 0 < aj && aj <= ak {
						pending2.Set(ofs + int64(j))
						pending.PushBack(&IntPair{j, c})
					} else {
						pending2.Set(ofs + int64(k))
						pending.PushBack(&IntPair{k, c})
					}
				}
				k++
			}
			refine2.Clear(int64(j))
			for _, s := range sb {
				split.Clear(int64(s))
			}
			splitblock[j] = nil // clear sb
		}
		refine = util.NewOpenBitSet() // not quite efficient
	}

	ans := newEmptyAutomaton()
	t := newTransition()
	// fmt.Printf("  k=%v\n", k)

	// make a new state for each equivalence class, set initial state
	stateMap := make([]int, statesLen)
	stateRep := make([]int, k)

	ans.createState()

	// fmt.Printf("min: k=%v\n", k)
	for n := 0; n < k; n++ {
		// fmt.Printf("    n=%v\n", n)

		isInitial := false
		for q, _ := range partition[n] {
			if q == 0 {
				isInitial = true
				// fmt.Println("    isInitial!")
				break
			}
		}

		newState := 0
		if !isInitial {
			newState = ans.createState()
		}

		// fmt.Printf("  newState=%v\n", newState)

		for q, _ := range partition[n] {
			stateMap[q] = newState
			// fmt.Printf("      q=%v isAccept?=%v\n", q, a.IsAccept(q))
			ans.setAccept(newState, a.IsAccept(q))
			stateRep[newState] = q // select representative
		}
	}

	// build transitions and set acceptance
	for n := 0; n < k; n++ {
		numTransitions := a.initTransition(stateRep[n], t)
		for i := 0; i < numTransitions; i++ {
			a.nextTransition(t)
			// fmt.Println("  add trans")
			ans.addTransitionRange(n, stateMap[t.dest], t.min, t.max)
		}
	}
	ans.finishState()
	// fmt.Printf("%v states\n", ans.numStates())

	return removeDeadStates(ans)
}
296417
func (cr *Context) Arc(xc, yc, radius, angle1, angle2 float64) {
	C.cairo_arc(cr.Ptr, C.double(xc), C.double(yc), C.double(radius), C.double(angle1), C.double(angle2))
	if err := cr.status(); err != nil {
		panic(err)
	}
}
927683
func (builder *Builder) Find(q grimoire.Query) (string, []interface{}) {
	qs, args := builder.query(q)
	return builder.fields(q.AsDistinct, q.Fields...) + qs, args
}