| 8 | trie() : root(new node()) { } |
| 9 | template <class I> |
| 10 | void insert(I begin, I end) { |
| 11 | node* cur = root; |
| 12 | while (true) { |
| 13 | cur->prefixes++; |
| 14 | if (begin == end) { cur->words++; break; } |
| 15 | else { |
| 16 | T head = *begin; |
| 17 | typename map<T, node*>::const_iterator it; |
| 18 | it = cur->children.find(head); |
| 19 | if (it == cur->children.end()) { |
| 20 | pair<T, node*> nw(head, new node()); |
| 21 | it = cur->children.insert(nw).first; |
| 22 | } begin++, cur = it->second; } } } |
| 23 | template<class I> |
| 24 | int countMatches(I begin, I end) { |
| 25 | node* cur = root; |