summaryrefslogtreecommitdiff
path: root/src/test/check_grammar.c
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2022-01-22 02:36:54 +0800
committerJSDurand <mmemmew@gmail.com>2022-01-22 02:36:54 +0800
commitbad2b1934da66021cbc7f0d715686706bd444449 (patch)
tree78c340d5f834bbc5864a97dcb23ff4ec41e23072 /src/test/check_grammar.c
parent53865aad225ffbe5cf3c42736e5a2095092f9fff (diff)
Implemented a hash table with any type of keys
Diffstat (limited to 'src/test/check_grammar.c')
-rw-r--r--src/test/check_grammar.c48
1 files changed, 25 insertions, 23 deletions
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 <stdlib.h>
#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<ht_len) printf(", ");
else printf("\n");
}
@@ -210,11 +212,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);
*(test_terminal_hts+i) = *temp;
free(temp);
- temp = new_ht(left_len << 1);
+ temp = new_ht(left_len << 1, 0);
*(test_predicate_hts+i) = *temp;
free(temp);
}
@@ -238,17 +240,17 @@ main(UNUSED int argc, UNUSED char **argv)
printf(" has the following FIRST set:\n");
ht_len = ht_size(test_terminal_hts);
- keys = ht_keys(test_terminal_hts);
+ keys = (NUM **) ht_keys(test_terminal_hts);
for (NUM i = 0; i < ht_len;) {
- printf("T %ld", *(keys+i));
+ printf("T %ld", GET_KEY(NUM, keys, i));
if (++i<ht_len) printf(", ");
else printf("\n");
}
ht_len = ht_size(test_predicate_hts);
- keys = ht_keys(test_predicate_hts);
+ keys = (NUM **) ht_keys(test_predicate_hts);
for (NUM i = 0; i < ht_len;) {
- printf("PT %ld", *(keys+i));
+ printf("PT %ld", GET_KEY(NUM, keys, i));
if (++i<ht_len) printf(", ");
else printf("\n");
}
@@ -265,11 +267,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);
*(result_terminal_hts+i) = *temp;
free(temp);
- temp = new_ht(left_len << 1);
+ temp = new_ht(left_len << 1, 0);
*(result_predicate_hts+i) = *temp;
free(temp);
}
@@ -284,10 +286,10 @@ main(UNUSED int argc, UNUSED char **argv)
printf("Nonterminal %ld contains the following terminals in the "
"FOLLOW set:\n", i);
ht_len = ht_size(result_terminal_hts+i);
- keys = ht_keys(result_terminal_hts+i++);
+ keys = (NUM **) ht_keys(result_terminal_hts+i++);
for (NUM j = 0; j < ht_len;) {
- if (*(keys+j) == END_OF_INPUT) printf("T $");
- else printf("T %ld", *(keys+j));
+ if (GET_KEY(NUM, keys, j) == END_OF_INPUT) printf("T $");
+ else printf("T %ld", GET_KEY(NUM, keys, j));
if (++j<ht_len) printf(", ");
else printf("\n");
}
@@ -297,42 +299,42 @@ main(UNUSED int argc, UNUSED char **argv)
if (epsilon_array) free(epsilon_array);
if (terminal_hts) {
for (NUM i = 0; i < left_len; i++)
- destroy_ht(terminal_hts+i, DESTROY_NONE_NO_SELF);
+ destroy_ht(terminal_hts+i, DESTROY_KEY_NO_SELF);
free(terminal_hts);
}
if (predicate_hts) {
for (NUM i = 0; i < left_len; i++)
- destroy_ht(predicate_hts+i, DESTROY_NONE_NO_SELF);
+ destroy_ht(predicate_hts+i, DESTROY_KEY_NO_SELF);
free(predicate_hts);
}
if (test_terminal_hts) {
for (NUM i = 0; i < left_len; i++)
- destroy_ht(test_terminal_hts+i, DESTROY_NONE_NO_SELF);
+ destroy_ht(test_terminal_hts+i, DESTROY_KEY_NO_SELF);
free(test_terminal_hts);
}
if (test_predicate_hts) {
for (NUM i = 0; i < left_len; i++)
- destroy_ht(test_predicate_hts+i, DESTROY_NONE_NO_SELF);
+ destroy_ht(test_predicate_hts+i, DESTROY_KEY_NO_SELF);
free(test_predicate_hts);
}
if (result_terminal_hts) {
for (NUM i = 0; i < left_len; i++)
- destroy_ht(result_terminal_hts+i, DESTROY_NONE_NO_SELF);
+ destroy_ht(result_terminal_hts+i, DESTROY_KEY_NO_SELF);
free(result_terminal_hts);
}
if (result_predicate_hts) {
for (NUM i = 0; i < left_len; i++)
- destroy_ht(result_predicate_hts+i, DESTROY_NONE_NO_SELF);
+ destroy_ht(result_predicate_hts+i, DESTROY_KEY_NO_SELF);
free(result_predicate_hts);
}
if (test_tnt_string) destroy_list(test_tnt_string, 1);
- if (tnt_ht) destroy_ht(tnt_ht, DESTROY_NONE_SELF);
+ if (tnt_ht) destroy_ht(tnt_ht, DESTROY_KEY_NO_SELF);
destroy_grammar(g, 1);