// search attempts to find the index of the sequence set value that contains q.
// If no values contain q, the returned index is the position where q should be
// inserted and ok is set to false.
771645
func (s SeqSet) search(q uint32) (i int, ok bool) {
	min, max := 0, len(s.Set)-1
	for min < max {
		if mid := (min + max) >> 1; s.Set[mid].Less(q) {
			min = mid + 1
		} else {
			max = mid
		}
	}
	if max < 0 || s.Set[min].Less(q) {
		return len(s.Set), false // q is the new largest value
	}
	return min, s.Set[min].Contains(q)
}
1338374
func (a *BooleanArray) search(v int64) int {
	// Define: f(x) → a.Timestamps[x] < v
	// Define: f(-1) == true, f(n) == false
	// Invariant: f(lo-1) == true, f(hi) == false
	lo := 0
	hi := a.Len()
	for lo < hi {
		mid := int(uint(lo+hi) >> 1)
		if a.Timestamps[mid] < v {
			lo = mid + 1 // preserves f(lo-1) == true
		} else {
			hi = mid // preserves f(hi) == false
		}
	}

	// lo == hi
	return lo
}
962522
func (driver *elastigoLogDriver) ScrollSearch(scrollID string) (elastigocore.SearchResult, error) {
	prettyPrint := false
	return elastigocore.Scroll(prettyPrint, scrollID, esLogstashScrollTimeout)
}
417509
func (b Bing) Search(searchTerm string, searchResults chan<- []Result) {
	log.Printf("Bing : Seared : Started : searchTerm[%s]\n", searchTerm)

	// Build a proper search url.
	searchTerm = strings.Replace(searchTerm, " ", "+", -1)
	uri := "http://www.bing.com/search?q=" + searchTerm + "&format=rss"

	// Perform a RSS search.
	rssSearch("Bing", uri, searchResults)

	log.Println("Bing : Search : Completed")
}
383289
func (i *indexImpl) Search(req *SearchRequest) (sr *SearchResult, err error) {
	return i.SearchInContext(context.Background(), req)
}
386657
func (ri *readerOffsetsIterator) Seek(key []byte, b *faultBuffer) (exact, ok bool) {
	ri.first = false

	pre, i, j, pi := keyPrefix(key), 0, len(ri.r.offsets), 0

	for i < j {
		h := int(uint(i+j) >> 1)
		pi = ri.r.searchPrefix(h)
		ri.setIndex(h, pi)

		switch ri.Compare(key, pre, b) {
		case -1:
			i = h + 1
		case 1:
			j = h
		default:
			return true, true
		}
	}

	ri.setIndex(i, pi)
	if ri.i >= len(ri.r.offsets) {
		return false, false
	}

	for ri.pi < len(ri.r.prefixes) && ri.i >= ri.r.prefixes[ri.pi].total {
		ri.pi++
	}

	return bytes.Equal(ri.Key(b), key), true
}
225287
func (r *Regex) Find(data string, pos int) MatchObject {
	// if the new position is less than last search start position
	// ???: why we can't always do r.lastFound = pos?
	if pos < r.lastIndex {
		r.lastFound = pos
	}
	r.lastIndex = pos
	for ; r.lastFound < len(data); r.lastFound++ {
		ret := r.re.FindStringSubmatchIndex(data[r.lastFound:])
		if ret == nil {
			return nil
		}
		if (ret[0] + r.lastFound) >= pos {
			mo := MatchObject(ret)
			mo.fix(r.lastFound)
			return mo
		}
		if ret[0] != 0 {
			// ???: why shouldn't this be r.lastFound += ret[0]
			r.lastFound += ret[0] - 1
		}
	}
	return nil
}
463504
func (c *Client) Search(indices ...string) *SearchService {
	builder := NewSearchService(c)
	builder.Indices(indices...)
	return builder
}
345246
func (c *Verification) Search(m *VerifySearchRequest) (*VerifySearchResponse, error) {
	var verifySearchResponse *VerifySearchResponse

	if !c.client.useOauth {
		m.apiKey = c.client.apiKey
		m.apiSecret = c.client.apiSecret
	}

	var r *http.Request
	buf, err := json.Marshal(m)
	if err != nil {
		return nil, errors.New("invalid message struct - unable to convert to JSON")
	}

	b := bytes.NewBuffer(buf)
	r, err = http.NewRequest("POST", apiRootv2+"/verify/search/json", b)
	if err != nil {
		return nil, err
	}

	r.Header.Add("Accept", "application/json")
	r.Header.Add("Content-Type", "application/json")

	resp, err := c.client.HTTPClient.Do(r)
	if err != nil {
		return nil, err
	}

	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, err
	}

	err = json.Unmarshal(body, &verifySearchResponse)
	if err != nil {
		return nil, err
	}

	return verifySearchResponse, nil
}
558710
func (r TemplateSearcher) Search(precise bool, terms ...string) (ComponentMatches, []error) {
	matches := ComponentMatches{}
	var errs []error
	for _, term := range terms {
		ref, err := parseTemplateReference(term)
		if err != nil {
			klog.V(2).Infof("template references must be of the form [<namespace>/]<name>, term %q did not qualify", term)
			continue
		}
		if term == "__template_fail" {
			errs = append(errs, fmt.Errorf("unable to find the specified template: %s", term))
			continue
		}

		namespaces := r.Namespaces
		if ref.hasNamespace() {
			namespaces = []string{ref.Namespace}
		}

		checkedNamespaces := sets.NewString()
		for _, namespace := range namespaces {
			if checkedNamespaces.Has(namespace) {
				continue
			}
			checkedNamespaces.Insert(namespace)

			templates, err := r.Client.Templates(namespace).List(metav1.ListOptions{})
			if err != nil {
				if errors.IsNotFound(err) || errors.IsForbidden(err) {
					continue
				}
				errs = append(errs, err)
				continue
			}

			exact := false
			for i := range templates.Items {
				template := &templates.Items[i]
				klog.V(4).Infof("checking namespace %s for template %s", namespace, ref.Name)
				if score, scored := templateScorer(*template, ref.Name); scored {
					if score == 0.0 {
						exact = true
					}
					klog.V(4).Infof("Adding template %q in project %q with score %f", template.Name, template.Namespace, score)
					fullName := fmt.Sprintf("%s/%s", template.Namespace, template.Name)
					matches = append(matches, &ComponentMatch{
						Value:       term,
						Argument:    fmt.Sprintf("--template=%q", fullName),
						Name:        fullName,
						Description: fmt.Sprintf("Template %q in project %q", template.Name, template.Namespace),
						Score:       score,
						Template:    template,
					})
				}
			}

			// If we found one or more exact matches in this namespace, do not continue looking at
			// other namespaces
			if exact && precise {
				break
			}
		}
	}

	return matches, errs
}
485197
func (c *Cluster) SearchQuery(q SearchQuery, opts *SearchQueryOptions) (*SearchResults, error) {
	if opts == nil {
		opts = &SearchQueryOptions{}
	}
	ctx := opts.Context
	if ctx == nil {
		ctx = context.Background()
	}

	var span opentracing.Span
	if opts.ParentSpanContext == nil {
		span = opentracing.GlobalTracer().StartSpan("ExecuteSearchQuery",
			opentracing.Tag{Key: "couchbase.service", Value: "fts"})
	} else {
		span = opentracing.GlobalTracer().StartSpan("ExecuteSearchQuery",
			opentracing.Tag{Key: "couchbase.service", Value: "fts"}, opentracing.ChildOf(opts.ParentSpanContext))
	}
	defer span.Finish()

	provider, err := c.getHTTPProvider()
	if err != nil {
		return nil, err
	}

	return c.searchQuery(ctx, span.Context(), q, opts, provider)
}
645788
func (t *Tree) Search(qname string) (*Elem, bool) {
	if t.Root == nil {
		return nil, false
	}
	n, res := t.Root.search(qname)
	if n == nil {
		return nil, res
	}
	return n.Elem, res
}
268524
func (t list) Search(x uint16) *Transition {
	low, high := 0, len(t)-1
	for low <= high {
		i := (low + high) / 2
		if t[i].hash > x {
			high = i - 1
		} else if t[i].hash < x {
			low = i + 1
		} else {
			return t[i]
		}
	}

	return nil
}
540246
func (b *BinaryTree) search(target Comparable) *node {
	current := b.root
	for current != nil {
		switch current.value.CompareTo(target) {
		case -1:
			current = current.left
		case 0:
			return current
		case 1:
			current = current.right
		}
	}
	return nil
}
845791
func (d *Context) Search() (daemon *os.Process, err error) {
	return d.search()
}
389284
func (c *CCache) Search(ctx context.Context, metric schema.AMKey, from, until uint32) (*CCSearchResult, error) {
	if from >= until {
		return nil, ErrInvalidRange
	}

	res := &CCSearchResult{
		From:  from,
		Until: until,
	}

	if c == nil {
		accnt.CacheMetricMiss.Inc()
		return res, nil
	}

	ctx, span := tracing.NewSpan(ctx, c.tracer, "CCache.Search")
	defer span.Finish()

	c.RLock()
	defer c.RUnlock()

	cm, ok := c.metricCache[metric]
	if !ok {
		span.SetTag("cache", "miss")
		accnt.CacheMetricMiss.Inc()
		return res, nil
	}

	cm.Search(ctx, metric, res, from, until)
	if len(res.Start) == 0 && len(res.End) == 0 {
		span.SetTag("cache", "miss")
		accnt.CacheMetricMiss.Inc()
	} else {

		accnt.CacheChunkHit.Add(len(res.Start) + len(res.End))
		go func() {
			c.accnt.HitChunks(metric, res.Start)
			c.accnt.HitChunks(metric, res.End)
		}()

		if res.Complete {
			span.SetTag("cache", "hit-full")
			accnt.CacheMetricHitFull.Inc()
		} else {
			span.SetTag("cache", "hit-partial")
			accnt.CacheMetricHitPartial.Inc()
		}
	}

	return res, nil
}
909364
func (t *Trie) search(key []byte) *node {
	n := &t.root
	for n.internal != nil {
		n = &n.internal.child[n.internal.direction(key)]
	}
	return n
}