/** Inserts a word into the trie. */
Inserts a word into the trie.
/ ** Inserts a word into the trie . * /
func (this *Trie) Insert(word string) {
	root := this
	for _, v := range word {
		value, ok := root.subTrie[string(v)]
		fmt.Println("root:", root, "v:", "sub:", root.subTrie, v, "value", value, "ok:", ok)
		if ok {
			root = value
		} else {
			newNode := make(map[string]*Trie, 0)
			root.subTrie[string(v)] = &Trie{
				name:    string(v),
				subTrie: newNode,
				isWord:  false,
			}
			root = root.subTrie[string(v)]
		}
	}
	root.isWord = true
}
func ( this * Trie ) Insert ( word string ) { root := this for _ , v := range word { value , ok := root . subTrie [ string ( v ) ] fmt . Println ( " " , root , " " , " " , root . subTrie , v , " " , value , " " , ok ) if ok { root = value } else { newNode := make ( map [ string ] * Trie , 0 ) root . subTrie [ string ( v ) ] = & Trie { name : string ( v ) , subTrie : newNode , isWord : false , } root = root . subTrie [ string ( v ) ] } } root . isWord = true }
Inserts a word into the trie.
Inserts a word into the trie .
// 检查单词在当前深度的嵌套字典中是否已经存在, // 第一次插入时肯定时不存在的 // 之后的插入会有用到,判断分支 // 初始化前缀字典 // 交换root,形成嵌套 // 一个字符串遍历完成,设定到此