struct Stab *trie_insert(struct Trie_node *root, const char *name, int lineno) { struct Trie_node *p = root; const char *t; for (t = name; *t; t++) { int index = get_index(*t); if (p->next[index] == NULL) p->next[index] = trie_new_node(); p = p->next[index]; } if (p->symbol == NULL) { p->symbol = stab_new(name, lineno); return p->symbol; } return NULL; }
void trie_insert(trie_t *root, char *key, int value) { trie_t *t = root; while(*key) { /* Create a node if necessary */ if(!(t->key[*key])) t->key[*key] = trie_new_node(); /* Walk */ t = t->key[*key]; key++; } /* Insert the data */ t->value = value; }
trie_t * trie_new() { return trie_new_node(); }