// For any index defined by IndexFields, if a matcher can match only (a subset)
// of objects that return <value> for a given index, a pair (<index name>, <value>)
// wil be returned.
// TODO: Consider supporting also labels.
727
func (s *SelectionPredicate) MatcherIndex() []MatchValue {
	var result []MatchValue
	for _, field := range s.IndexFields {
		if value, ok := s.Field.RequiresExactMatch(field); ok {
			result = append(result, MatchValue{IndexName: field, Value: value})
		}
	}
	return result
}
1579
func PostingsForMatchers(ix IndexReader, ms ...labels.Matcher) (index.Postings, error) {
	var its, notIts []index.Postings
	// See which label must be non-empty.
	labelMustBeSet := make(map[string]bool, len(ms))
	for _, m := range ms {
		if !m.Matches("") {
			labelMustBeSet[m.Name()] = true
		}
	}

	for _, m := range ms {
		matchesEmpty := m.Matches("")
		if labelMustBeSet[m.Name()] || !matchesEmpty {
			// If this matcher must be non-empty, we can be smarter.
			nm, isNot := m.(*labels.NotMatcher)
			if isNot && matchesEmpty { // l!="foo"
				// If the label can't be empty and is a Not and the inner matcher
				// doesn't match empty, then subtract it out at the end.
				it, err := postingsForMatcher(ix, nm.Matcher)
				if err != nil {
					return nil, err
				}
				notIts = append(notIts, it)
			} else if isNot && !matchesEmpty { // l!=""
				// If the label can't be empty and is a Not, but the inner matcher can
				// be empty we need to use inversePostingsForMatcher.
				it, err := inversePostingsForMatcher(ix, nm.Matcher)
				if err != nil {
					return nil, err
				}
				its = append(its, it)
			} else { // l="a"
				// Non-Not matcher, use normal postingsForMatcher.
				it, err := postingsForMatcher(ix, m)
				if err != nil {
					return nil, err
				}
				its = append(its, it)
			}
		} else { // l=""
			// If the matchers for a labelname selects an empty value, it selects all
			// the series which don't have the label name set too. See:
			// https://github.com/prometheus/prometheus/issues/3575 and
			// https://github.com/prometheus/prometheus/pull/3578#issuecomment-351653555
			it, err := inversePostingsForMatcher(ix, m)
			if err != nil {
				return nil, err
			}
			notIts = append(notIts, it)
		}
	}

	// If there's nothing to subtract from, add in everything and remove the notIts later.
	if len(its) == 0 && len(notIts) != 0 {
		allPostings, err := ix.Postings(index.AllPostingsKey())
		if err != nil {
			return nil, err
		}
		its = append(its, allPostings)
	}

	it := index.Intersect(its...)

	for _, n := range notIts {
		if _, ok := n.(*index.ListPostings); !ok {
			// Best to pre-calculate the merged lists via next rather than have a ton
			// of seeks in Without.
			pl, err := index.ExpandPostings(n)
			if err != nil {
				return nil, err
			}
			n = index.NewListPostings(pl)
		}
		it = index.Without(it, n)
	}

	return ix.SortedPostings(it), nil
}
1341895
func (self *Collection) GetFieldByIndex(index int) (Field, bool) {
	if index == self.IdentityFieldIndex {
		return Field{
			Name:     self.GetIdentityFieldName(),
			Type:     self.IdentityFieldType,
			Index:    self.IdentityFieldIndex,
			Identity: true,
			Key:      true,
			Required: true,
		}, true
	} else {
		for _, field := range self.Fields {
			if field.Index == index {
				return field, true
			}
		}
	}

	return Field{}, false
}
514391
func (i InventoryCollection) IndexByFieldsAndType(fields []string, indexType string) (InventoryIndex, bool) {
	for _, idx := range i.Indexes {
		if idx.Type == indexType && idx.FieldsEqual(fields) {
			return idx, true
		}
	}
	return InventoryIndex{}, false
}
1205202
func (s *SearchService) Indices(indices ...string) *SearchService {
	if s.indices == nil {
		s.indices = make([]string, 0)
	}
	s.indices = append(s.indices, indices...)
	return s
}
295718
func (c *Client) IndexNames() ([]string, error) {
	res, err := c.IndexGetSettings().Index("_all").Do()
	if err != nil {
		return nil, err
	}
	var names []string
	for name, _ := range res {
		names = append(names, name)
	}
	return names, nil
}
1040981
func index(l []interface{}, valToLookUp interface{}, mergeKey string, kind reflect.Kind) int {
	var getValFn func(interface{}) interface{}
	// Get the correct `getValFn` based on item `kind`.
	// It should return the value of merge key for maps and
	// return the item for other kinds.
	switch kind {
	case reflect.Map:
		getValFn = func(item interface{}) interface{} {
			typedItem, ok := item.(map[string]interface{})
			if !ok {
				return nil
			}
			val := typedItem[mergeKey]
			return val
		}
	default:
		getValFn = func(item interface{}) interface{} {
			return item
		}
	}

	for i, v := range l {
		if getValFn(valToLookUp) == getValFn(v) {
			return i
		}
	}
	return -1
}
510610
func (n EndpointSelector) GetMatch(key string) ([]string, bool) {
	if value, ok := n.MatchLabels[key]; ok {
		return []string{value}, true
	}
	for _, v := range n.MatchExpressions {
		if v.Key == key && v.Operator == metav1.LabelSelectorOpIn {
			return v.Values, true
		}
	}
	return nil, false
}
990496
func collectFieldIndexes(s reflect.Type) (out [][]int, err error) {
	if s.Kind() != reflect.Struct {
		return nil, fmt.Errorf("expected a struct but got %q", s)
	}
	defer decorate(&err, s.String)
	for i := 0; i < s.NumField(); i++ {
		f := s.Field(i)
		if f.Anonymous {
			children, err := collectFieldIndexes(f.Type)
			if err != nil {
				return nil, err
			}
			for _, idx := range children {
				out = append(out, append(f.Index, idx...))
			}
		} else if fieldLexerTag(f) != "" {
			out = append(out, f.Index)
		}
	}
	return
}
1126287
func (s Selector) MatchAll(n *html.Node) []*html.Node {
	return s.matchAllInto(n, nil)
}
492154
func (set Set) Match(caps [][]string) []string {
	if set == nil {
		return nil
	}
anyof:
	for _, andList := range caps {
		for _, cap := range andList {
			if _, ok := set[cap]; !ok {
				continue anyof
			}
		}
		return andList
	}
	// match anything
	return nil
}
458325
func (rs Runes) IndexAll(r, sub []rune) int {
	return rs.IndexAllEx(r, sub, false)
}
345218
func propByIndex(t reflect.Type, x []int) *Properties {
	if len(x) != 1 {
		fmt.Fprintf(os.Stderr, "proto: field index dimension %d (not 1) for type %s\n", len(x), t)
		return nil
	}
	prop := GetProperties(t)
	return prop.Prop[x[0]]
}
746194
func (idx *index) match(key string) bool {
	if idx.pattern == "*" {
		return true
	}
	if idx.opts.CaseInsensitiveKeyMatching {
		for i := 0; i < len(key); i++ {
			if key[i] >= 'A' && key[i] <= 'Z' {
				key = strings.ToLower(key)
				break
			}
		}
	}
	return match.Match(key, idx.pattern)
}
1277832
func (s *IndexService) Index(index string) *IndexService {
	s.index = index
	return s
}
861987
func (s *IndicesSegmentsService) Index(indices ...string) *IndicesSegmentsService {
	s.index = append(s.index, indices...)
	return s
}
942152
func match(topicName, topicFilter string) bool {
	// Tokenize the Topic Name.
	nameTokens := strings.Split(topicName, "/")
	nameTokensLen := len(nameTokens)

	// Tolenize the Topic Filter.
	filterTokens := strings.Split(topicFilter, "/")

	for i, t := range filterTokens {
		switch t {
		case "#":
			return i != 0 || !strings.HasPrefix(nameTokens[0], "$")
		case "+":
			if i == 0 && strings.HasPrefix(nameTokens[0], "$") {
				return false
			}

			if nameTokensLen <= i {
				return false
			}
		default:
			if nameTokensLen <= i || t != nameTokens[i] {
				return false
			}
		}
	}

	return len(filterTokens) == nameTokensLen
}