From bad2b1934da66021cbc7f0d715686706bd444449 Mon Sep 17 00:00:00 2001 From: JSDurand Date: Sat, 22 Jan 2022 02:36:54 +0800 Subject: Implemented a hash table with any type of keys --- src/test/check_grammar.c | 48 +++++++++++++++++++++++++----------------------- src/test/check_ht.c | 21 ++++++++++++--------- 2 files changed, 37 insertions(+), 32 deletions(-) (limited to 'src/test') diff --git a/src/test/check_grammar.c b/src/test/check_grammar.c index ca70fa9..2b6c8f2 100644 --- a/src/test/check_grammar.c +++ b/src/test/check_grammar.c @@ -3,6 +3,8 @@ #include #include "../grammar.h" +#define GET_KEY(T, K, N) *((T*)*(K+N)) + #define READ_INTO_CPA(N, U, I, VA, VI, CP) do { \ U = new_utf8(N, 1); \ I = get_info((str *)U, 0); \ @@ -174,11 +176,11 @@ main(UNUSED int argc, UNUSED char **argv) for (NUM i = 0; i < left_len; i++) { ht *temp = NULL; - temp = new_ht(left_len << 1); + temp = new_ht(left_len << 1, 0); *(terminal_hts+i) = *temp; free(temp); - temp = new_ht(left_len << 1); + temp = new_ht(left_len << 1, 0); *(predicate_hts+i) = *temp; free(temp); } @@ -188,15 +190,15 @@ main(UNUSED int argc, UNUSED char **argv) goto cleanup; } - NUM ht_len = 0, *keys = NULL; + NUM ht_len = 0, **keys = NULL; for (NUM i = 0; i < left_len;) { printf("Nonterminal %ld contains the following terminals in the " "FIRST set:\n", i); ht_len = ht_size(terminal_hts+i); - keys = ht_keys(terminal_hts+i++); + keys = (NUM **) ht_keys(terminal_hts+i++); for (NUM j = 0; j < ht_len;) { - printf("T %ld", *(keys+j)); + printf("T %ld", GET_KEY(NUM, keys, j)); if (++j