Add the search feature.

This commit is contained in:
Danila Fedorin 2018-02-10 17:57:24 -08:00
parent a27bdc37f5
commit 1a6a80d26b
2 changed files with 15 additions and 1 deletions

View File

@ -51,6 +51,13 @@ typedef struct table_entry table_entry;
* @param table the table to initialize.
*/
void table_init(table* table);
/**
* Searches for the given string in the table.
* @param table the table to search.
* @param string the string to search for.
* @return the table entry, or NULL if an entry was not found.
*/
table_entry* table_search(table* table, const char* string);
/**
* Frees the resources allocated by the
* given table.

View File

@ -5,7 +5,14 @@ void table_init(table* table) {
ht_init(&table->table);
table->parent = NULL;
}
table_entry* table_search(table* table, const char* string) {
void* to_return = NULL;
do {
to_return = ht_get(&table->table, string);
table = table->parent;
} while(table && to_return == NULL);
return to_return;
}
void table_free(table* table) {
ht_free(&table->table);
}