// Add adds a key to the Trie, including a value. The value
// is stored as `interface{}` and must be type cast by the caller.
// Upon the Add(), the old value added with the same key is removed from the trie.
Add adds a key to the Trie, including a value. The value
is stored as `interface{}` and must be type cast by the caller.
Upon the Add(), the old value added with the same key is removed from the trie.
// Add adds a key to the Trie including a value . The value // is stored as ` interface {} ` and must be type cast by the caller . // Upon the Add () the old value added with the same key is removed from the trie .
func (t *Trie) Add(key string, value interface{}) {
	t.mu.Lock()
	defer t.mu.Unlock()
	cnt := 1
	runes := []rune(key)
	if node := findNode(t.root, runes); node != nil {
		if node, ok := node.children[nul]; ok && node.term {
			cnt = 0
		}
	}
	t.size = t.size + cnt
	bitmask := maskruneslice(runes)
	node := t.root
	node.mask |= bitmask
	node.termCount = node.termCount + cnt
	for i := range runes {
		r := runes[i]
		bitmask = maskruneslice(runes[i:])
		if n, ok := node.children[r]; ok {
			node = n
			node.mask |= bitmask
		} else {
			node = node.newChild(r, "", bitmask, nil, false)
		}
		node.termCount = node.termCount + cnt
	}
	node = node.newChild(nul, key, 0, value, true)
}
func ( t * Trie ) Add ( key string , value interface { } ) { t . mu . Lock ( ) defer t . mu . Unlock ( ) cnt := 1 runes := [ ] rune ( key ) if node := findNode ( t . root , runes ) ; node != nil { if node , ok := node . children [ nul ] ; ok && node . term { cnt = 0 } } t . size = t . size + cnt bitmask := maskruneslice ( runes ) node := t . root node . mask |= bitmask node . termCount = node . termCount + cnt for i := range runes { r := runes [ i ] bitmask = maskruneslice ( runes [ i : ] ) if n , ok := node . children [ r ] ; ok { node = n node . mask |= bitmask } else { node = node . newChild ( r , " " , bitmask , nil , false ) } node . termCount = node . termCount + cnt } node = node . newChild ( nul , key , 0 , value , true ) }
Add adds a key to the Trie, including a value.
Add adds a key to the Trie including a value .
// check the node exists