// Remove removes the `key` from the trie and return the value,
// ensuring that all bitmasks up to root are appropriately recalculated.
Remove removes the `key` from the trie and return the value,
ensuring that all bitmasks up to root are appropriately recalculated.
// Remove removes the ` key ` from the trie and return the value // ensuring that all bitmasks up to root are appropriately recalculated .
func (t *Trie) Remove(key string) interface{} {
	t.mu.Lock()
	defer t.mu.Unlock()
	var (
		i     int
		r     rune
		value interface{}
		rs    = []rune(key)
		node  = findNode(t.root, []rune(key))
	)
	if node == nil {
		return nil
	}
	target, ok := node.children[nul]
	if !ok || !target.term {
		return nil
	}
	value = target.value
	target.children = nil
	target.parent = nil
	target.value = nil
	t.size--
	node.removeChild(nul)
	for node.parent != nil {
		node.termCount--
		parent := node.parent
		if len(node.children) <= 0 {
			i++
			r = rs[len(rs)-i]
			parent.removeChild(r)
			node.parent = nil
			node.value = nil
			node.children = nil
		}
		node = parent
	}
	node.termCount--
	updateMask(node)
	return value
}
func ( t * Trie ) Remove ( key string ) interface { } { t . mu . Lock ( ) defer t . mu . Unlock ( ) var ( i int r rune value interface { } rs = [ ] rune ( key ) node = findNode ( t . root , [ ] rune ( key ) ) ) if node == nil { return nil } target , ok := node . children [ nul ] if ! ok || ! target . term { return nil } value = target . value target . children = nil target . parent = nil target . value = nil t . size -- node . removeChild ( nul ) for node . parent != nil { node . termCount -- parent := node . parent if len ( node . children ) <= 0 { i ++ r = rs [ len ( rs ) - i ] parent . removeChild ( r ) node . parent = nil node . value = nil node . children = nil } node = parent } node . termCount -- updateMask ( node ) return value }
Remove removes the `key` from the trie and return the value,
ensuring that all bitmasks up to root are appropriately recalculated.
Remove removes the ` key ` from the trie and return the value ensuring that all bitmasks up to root are appropriately recalculated .
// fmt.Printf("key %s, parent.rval %c n.rval %c r %c\n", target.path, n.parent.rval, n.rval, r)