+ if (depth == 0) {
+ /* add node to root */
+ rules->trie_root[key] = new_node_idx;
+ } else {
+ /* add node to parent */
+ struct trie_node *parent;
+ struct trie_child *new_child;
+ unsigned int new_child_idx;
+
+ /* get new child link for list of childs of parent */
+ new_child_idx = rules->trie_childs_cur;
+ rules->trie_childs_cur++;
+ new_child = &rules->trie_childs[new_child_idx];
+ new_child->next_idx = 0;
+ new_child->node_idx = new_node_idx;
+ new_child->key = key;
+
+ /* append child link to list of childs of parent */
+ parent = &rules->trie_nodes[node_idx];
+ if (parent->child_idx == 0) {
+ parent->child_idx = new_child_idx;
+ } else {
+ struct trie_child *last_child;
+
+ last_child = &rules->trie_childs[parent->last_child_idx];
+ last_child->next_idx = new_child_idx;
+ }
+ parent->last_child_idx = new_child_idx;
+ }