From 26ad341a50a11920d48e5d7fdaeea681849193d0 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Sat, 24 Mar 2018 20:47:34 -0700 Subject: [PATCH] Switch the table to using tries. --- include/table.h | 4 ++-- src/table.c | 13 +++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/include/table.h b/include/table.h index 7a7fb58..0b9edad 100644 --- a/include/table.h +++ b/include/table.h @@ -1,9 +1,9 @@ #ifndef LIBABACUS_TABLE_H #define LIBABACUS_TABLE_H -#include "ht.h" #include "result.h" #include "custom.h" +#include "trie.h" /** * A struct that represents a structure @@ -20,7 +20,7 @@ struct libab_table_s { /** * The hash table used to store the data. */ - ht table; + libab_trie trie; }; /** diff --git a/src/table.c b/src/table.c index a59fa56..6c7f0ec 100644 --- a/src/table.c +++ b/src/table.c @@ -4,13 +4,14 @@ #include "lexer.h" void libab_table_init(libab_table* table) { - ht_init(&table->table); + libab_trie_init(&table->trie); table->parent = NULL; } libab_table_entry* libab_table_search_filter(libab_table* table, const char* string, void* data, compare_func compare) { void* to_return = NULL; do { - to_return = ht_find(&table->table, string, data, compare); + const ll* matches = libab_trie_get(&table->trie, string); + to_return = ll_find(matches, data, compare); table = table->parent; } while(table && to_return == NULL); return to_return; @@ -18,7 +19,7 @@ libab_table_entry* libab_table_search_filter(libab_table* table, const char* str libab_table_entry* libab_table_search(libab_table* table, const char* string) { void* to_return = NULL; do { - to_return = ht_get(&table->table, string); + to_return = ll_head(libab_trie_get(&table->trie, string)); table = table->parent; } while(table && to_return == NULL); return to_return; @@ -55,7 +56,7 @@ libab_function* libab_table_search_function(libab_table* table, const char* stri return entry ? &entry->data_u.function : NULL; } libab_result libab_table_put(libab_table* table, const char* string, libab_table_entry* entry) { - return libab_convert_ds_result(ht_put(&table->table, string, entry)); + return libab_trie_put(&table->trie, string, entry); } int _table_foreach_entry_free(void* data, va_list args) { libab_table_entry_free(data); @@ -63,8 +64,8 @@ int _table_foreach_entry_free(void* data, va_list args) { return 0; } void libab_table_free(libab_table* table) { - ht_foreach(&table->table, NULL, compare_always, _table_foreach_entry_free); - ht_free(&table->table); + libab_trie_foreach(&table->trie, NULL, compare_always, _table_foreach_entry_free); + libab_trie_free(&table->trie); } void libab_table_entry_free(libab_table_entry* entry) { if(entry->variant == ENTRY_OP) {