insert a single word at a Trie node.
(s string)
| 20 | |
| 21 | // insert a single word at a Trie node. |
| 22 | func (n *Node) insert(s string) { |
| 23 | curr := n |
| 24 | for _, c := range s { |
| 25 | next, ok := curr.children[c] |
| 26 | if !ok { |
| 27 | next = NewNode() |
| 28 | curr.children[c] = next |
| 29 | } |
| 30 | curr = next |
| 31 | } |
| 32 | curr.isLeaf = true |
| 33 | } |
| 34 | |
| 35 | // Insert zero, one or more words at a Trie node. |
| 36 | func (n *Node) Insert(s ...string) { |