// FindLongestMatchingPrefix finds a prefix key matching longestly with `key`
// from the trie and then returns the its key and inserted value.
// the key found is the longest matched prefix of the input `key`.
FindLongestMatchingPrefix finds a prefix key matching longestly with `key`
from the trie and then returns the its key and inserted value.
the key found is the longest matched prefix of the input `key`.
// FindLongestMatchingPrefix finds a prefix key matching longestly with ` key ` // from the trie and then returns the its key and inserted value . // the key found is the longest matched prefix of the input ` key ` .
func (t *Trie) FindLongestMatchingPrefix(key string) (string, interface{}, bool) {
	t.mu.RLock()
	defer t.mu.RUnlock()
	var found *trieNode
	node := t.root
	if node == nil {
		return "", nil, false
	}
	for _, r := range []rune(key) {
		n, ok := node.children[r]
		if !ok {
			break
		}
		t, ok := n.children[nul]
		if ok && t.term {
			found = t
		}
		node = n
	}
	if found == nil {
		return "", nil, false
	}
	return found.path, found.value, true
}
func ( t * Trie ) FindLongestMatchingPrefix ( key string ) ( string , interface { } , bool ) { t . mu . RLock ( ) defer t . mu . RUnlock ( ) var found * trieNode node := t . root if node == nil { return " " , nil , false } for _ , r := range [ ] rune ( key ) { n , ok := node . children [ r ] if ! ok { break } t , ok := n . children [ nul ] if ok && t . term { found = t } node = n } if found == nil { return " " , nil , false } return found . path , found . value , true }
FindLongestMatchingPrefix finds a prefix key matching longestly with `key`
from the trie and then returns the its key and inserted value.
FindLongestMatchingPrefix finds a prefix key matching longestly with ` key ` from the trie and then returns the its key and inserted value .