| 140 | |
| 141 | template <typename T> |
| 142 | bool |
| 143 | Trie<T>::Insert(const char *key, T *value, int rank, int key_len /* = -1 */) |
| 144 | { |
| 145 | _CheckArgs(key, key_len); |
| 146 | |
| 147 | Node *next_node; |
| 148 | Node *curr_node = &m_root; |
| 149 | int i = 0; |
| 150 | |
| 151 | while (true) { |
| 152 | if (dbg_ctl_insert.on()) { |
| 153 | Dbg(dbg_ctl_insert, "Visiting Node..."); |
| 154 | curr_node->Print(dbg_ctl_insert); |
| 155 | } |
| 156 | |
| 157 | if (i == key_len) { |
| 158 | break; |
| 159 | } |
| 160 | |
| 161 | next_node = curr_node->GetChild(key[i]); |
| 162 | if (!next_node) { |
| 163 | while (i < key_len) { |
| 164 | Dbg(dbg_ctl_insert, "Creating child node for char %c (%d)", key[i], key[i]); |
| 165 | curr_node = curr_node->AllocateChild(key[i]); |
| 166 | ++i; |
| 167 | } |
| 168 | break; |
| 169 | } |
| 170 | curr_node = next_node; |
| 171 | ++i; |
| 172 | } |
| 173 | |
| 174 | if (curr_node->occupied) { |
| 175 | Dbg(dbg_ctl_insert, "Cannot insert duplicate!"); |
| 176 | return false; |
| 177 | } |
| 178 | |
| 179 | curr_node->occupied = true; |
| 180 | curr_node->value = value; |
| 181 | curr_node->rank = rank; |
| 182 | m_value_list.enqueue(curr_node->value); |
| 183 | Dbg(dbg_ctl_insert, "inserted new element!"); |
| 184 | return true; |
| 185 | } |
| 186 | |
| 187 | template <typename T> |
| 188 | T * |
nothing calls this directly
no test coverage detected