MCPcopy Create free account
hub / github.com/apache/trafficserver / Insert

Method Insert

include/tscore/Trie.h:142–185  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

140
141template <typename T>
142bool
143Trie<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
187template <typename T>
188T *

Callers

nothing calls this directly

Calls 5

GetChildMethod · 0.80
AllocateChildMethod · 0.80
onMethod · 0.45
PrintMethod · 0.45
enqueueMethod · 0.45

Tested by

no test coverage detected