// Traverse all keys with a certain prefix.
497603
func (ndb *nodeDB) traversePrefix(prefix []byte, fn func(k, v []byte)) {
	itr := dbm.IteratePrefix(ndb.db, prefix)
	defer itr.Close()

	for ; itr.Valid(); itr.Next() {
		fn(itr.Key(), itr.Value())
	}
}
725873
func ScanMetaWithPrefix(retriever kv.Retriever, prefix kv.Key, filter func(kv.Key, []byte) bool) error {
	iter, err := retriever.Iter(prefix, prefix.PrefixNext())
	if err != nil {
		return errors.Trace(err)
	}
	defer iter.Close()

	for {
		if err != nil {
			return errors.Trace(err)
		}

		if iter.Valid() && iter.Key().HasPrefix(prefix) {
			if !filter(iter.Key(), iter.Value()) {
				break
			}
			err = iter.Next()
			if err != nil {
				return errors.Trace(err)
			}
		} else {
			break
		}
	}

	return nil
}
1019650
func (e *EtcdStore) Keys(prefix string) ([]string, error) {
	kv, err := e.GetMultiMap(prefix)
	if err != nil {
		return []string{}, err
	}
	mk := make([]string, len(kv))
	i := 0
	for key := range kv {
		mk[i] = key
		i++
	}
	return mk, nil
}
1338603
func ContainsPrefix(prefixSet []string, item corev1.ResourceName) bool {
	for _, prefix := range prefixSet {
		if strings.HasPrefix(string(item), prefix) {
			return true
		}
	}
	return false
}
966113
func extractKey(s, prefix string) (string, error) {
	substrings := strings.SplitN(s, "/", 2)
	if len(substrings) <= 1 || substrings[0] != prefix {
		switch prefix {
		case deleteFromPrimitiveListDirectivePrefix:
			return "", mergepatch.ErrBadPatchFormatForPrimitiveList
		case setElementOrderDirectivePrefix:
			return "", mergepatch.ErrBadPatchFormatForSetElementOrderList
		default:
			return "", fmt.Errorf("fail to find unknown prefix %q in %s\n", prefix, s)
		}
	}
	return substrings[1], nil
}
1132530
func (t *Trie) HasPrefix(prefix string) bool {
	return t.Root.hasPrefix([]byte(prefix))
}
1048572
func (pb *ProgressBar) Prefix(prefix string) *ProgressBar {
	pb.mu.Lock()
	defer pb.mu.Unlock()
	pb.prefix = prefix
	return pb
}
724773
func (trie *Trie) VisitPrefixes(key Prefix, visitor VisitorFunc) error {
	// Nil key not allowed.
	if key == nil {
		panic(ErrNilPrefix)
	}

	// Empty trie must be handled explicitly.
	if trie.prefix == nil {
		return nil
	}

	// Walk the path matching key prefixes.
	node := trie
	prefix := key
	offset := 0
	for {
		// Compute what part of prefix matches.
		common := node.longestCommonPrefixLength(key)
		key = key[common:]
		offset += common

		// Partial match means that there is no subtree matching prefix.
		if common < len(node.prefix) {
			return nil
		}

		// Call the visitor.
		if item := node.item; item != nil {
			if err := visitor(prefix[:offset], item); err != nil {
				return err
			}
		}

		if len(key) == 0 {
			// This node represents key, we are finished.
			return nil
		}

		// There is some key suffix left, move to the children.
		child := node.children.next(key[0])
		if child == nil {
			// There is nowhere to continue, return.
			return nil
		}

		node = child
	}
}
388912
func getPrefix(tree *RegexTree) *Prefix {
	var concatNode *regexNode
	nextChild := 0

	curNode := tree.root

	for {
		switch curNode.t {
		case ntConcatenate:
			if len(curNode.children) > 0 {
				concatNode = curNode
				nextChild = 0
			}

		case ntGreedy, ntCapture:
			curNode = curNode.children[0]
			concatNode = nil
			continue

		case ntOneloop, ntOnelazy:
			if curNode.m > 0 {
				return &Prefix{
					PrefixStr:       repeat(curNode.ch, curNode.m),
					CaseInsensitive: (curNode.options & IgnoreCase) != 0,
				}
			}
			return nil

		case ntOne:
			return &Prefix{
				PrefixStr:       []rune{curNode.ch},
				CaseInsensitive: (curNode.options & IgnoreCase) != 0,
			}

		case ntMulti:
			return &Prefix{
				PrefixStr:       curNode.str,
				CaseInsensitive: (curNode.options & IgnoreCase) != 0,
			}

		case ntBol, ntEol, ntBoundary, ntECMABoundary, ntBeginning, ntStart,
			ntEndZ, ntEnd, ntEmpty, ntRequire, ntPrevent:

		default:
			return nil
		}

		if concatNode == nil || nextChild >= len(concatNode.children) {
			return nil
		}

		curNode = concatNode.children[nextChild]
		nextChild++
	}
}
1334038
func PrefixKey(handler cfg.Handler, prefix string) cfg.Handler {
	return Apply(func(key string) (string, error) { return fmt.Sprintf("%s%s", prefix, key), nil }, nil, handler)
}
896475
func (s *Search) PrefixSearch(prefix string, context contexts.Context, q *QueryOptions) (*SearchResponse, *QueryMeta, error) {
	var resp SearchResponse
	req := &SearchRequest{Prefix: prefix, Context: context}

	qm, err := s.client.putQuery("/v1/search", req, &resp, q)
	if err != nil {
		return nil, nil, err
	}

	return &resp, qm, nil
}
1272363
func (h *Handle) KeyPrefix() []string {
	h.Lock()
	defer h.Unlock()
	return []string{h.app}
}
946225
func (n *rootNode) GetKeys() (keys []string) {
	if err := n.genMapBuf(); err != nil {
		return
	}
	keys = make([]string, 0, len(n.mapBuf))
	for key := range n.mapBuf {
		keys = append(keys, key)
	}
	return
}
543413
func (t Trie) PrefixSearch(pre string) []string {
	node := findNode(t.Root(), []rune(pre))
	if node == nil {
		return nil
	}

	return collect(node)
}
878183
func (m *SortedMap) Each(prefix string, handle func(key string, value interface{}) bool) bool {
	return m.trie.Allprefixed([]byte(prefix), func(k []byte, v interface{}) bool {
		return handle(string(k), v)
	})
}
649432
func (that *JSONNode) GetKeys() []interface{} {
	var ret []interface{}
	switch that.t {
	case TypeMap:
		nb := len(that.m)
		ret = make([]interface{}, nb)
		for key := range that.m {
			nb--
			ret[nb] = key
		}
	case TypeArray:
		nb := len(that.a)
		ret = make([]interface{}, nb)
		for nb > 0 {
			nb--
			ret[nb] = nb
		}
	default:
		panic(ErrorGetKeys)
	}
	return ret
}
107607
func (m *MemStore) Keys(prefix string) ([]string, error) {
	m.mutex.Lock()
	defer m.mutex.Unlock()
	mk := make([]string, len(m.store))
	i := 0
	for key := range m.store {
		if strings.HasPrefix(key, prefix) {
			mk[i] = key
			i++
		}
	}
	if i == 0 {
		return []string{}, NewKeyNotFound(prefix)
	}
	return mk[0:i], nil
}