summaryrefslogtreecommitdiff
path: root/src/test/check_cnp.c
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2022-02-05 17:30:11 +0800
committerJSDurand <mmemmew@gmail.com>2022-02-05 17:30:11 +0800
commit510b10b96b546fcc6c6b6be85050305ddd192a41 (patch)
tree997d6c3f2c0a1ad6e27127d54a94655527e57864 /src/test/check_cnp.c
parent3fb5430080199a6d92a63f8259fe4a88df9b83ba (diff)
replace some hash table usage by tuples
Previously I used hash tables, which consume too much memory. Now the critical parts are replaced by a new hand-written library called "tuple.h". Now we can easily parse larger inputs. I haven't tested its limits, though.
Diffstat (limited to 'src/test/check_cnp.c')
-rw-r--r--src/test/check_cnp.c41
1 files changed, 18 insertions, 23 deletions
diff --git a/src/test/check_cnp.c b/src/test/check_cnp.c
index 91952ef..a21d74e 100644
--- a/src/test/check_cnp.c
+++ b/src/test/check_cnp.c
@@ -1,9 +1,16 @@
#include "time.h"
#include "../cnp.h"
-#define TIC do { \
- clock_gettime(CLOCK_MONOTONIC_RAW, &tic); \
- } while (0)
+UNUSED
+static void
+print_label6(pair6 label)
+{
+ printf("(%ld, %ld, %ld, %ld, %ld, %ld)\n",
+ label.x, label.y, label.z, label.u, label.v, label.w);
+}
+
+#define TIC struct timespec tic, toc; \
+ do { clock_gettime(CLOCK_MONOTONIC_RAW, &tic); } while (0)
#define TOC do { \
clock_gettime(CLOCK_MONOTONIC_RAW, &toc); \
@@ -175,13 +182,13 @@ main(int UNUSED argc, char ** UNUSED argv)
string = new_utf8("aab", 3);
break;
case 2:
- string = new_utf8("[+-[.,]><][+-[.,]><][+-[.,]><][+-[.,]><][+-[.,]><][+-[.,]><][+-[.,]><][+-[.,]><][+-[.,]><][+-[.,]><]", 100);
+ string = new_utf8("[[[[[[[[[[[[[[[[[[[[[[[++[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]--]]]]]]]]]]]]]]]]]]]]]]]", 204);
break;
case 3:
- string = new_utf8("bbbbb", 5);
+ string = new_utf8("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", 100);
break;
case 4:
- string = new_utf8("aaaaaaaaaaaa", 12);
+ string = new_utf8("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 48);
break;
default:
fleprintf0("Forgot to assign input!\n");
@@ -190,7 +197,6 @@ main(int UNUSED argc, char ** UNUSED argv)
printf("\nPrinting the input...\n%s\n", get_data((str *) string));
- struct timespec tic, toc;
TIC;
Environment *env = cnp_parse(g, (str *) string);
@@ -199,33 +205,22 @@ main(int UNUSED argc, char ** UNUSED argv)
if (env) {
if (!(env_error_p(env))) {
- BOOL error = 0;
- ht *result = bsr_lookup
- (env_bsrp(env), &error, 0, 0, str_length((str *) string));
-
- if (error) {
- printf("There are errors!\n");
- goto destroy;
- }
+ BOOL result = bsr_lookup
+ (env_bsrp(env), 0, 0, str_length((str *) string));
- if (result && ht_size(result)) {
+ if (result) {
printf("\nSuccessfully parsed the input!\n");
- for (NUM i = 0; i < ht_size(result); i++)
- printf("(%d, %ld, %d, %ld, %ld)\n",
- 0, (*((pair2 **) ht_keys(result)+i))->x,
- 0, (*((pair2 **) ht_keys(result)+i))->y,
- str_length((str *) string));
} else {
printf("\nThe input does not parse!\n");
}
printf("\nAll BSRs follow:\n\n");
- bsr_print(env_bsrp(env), env_grammar(env), 1);
+ if (argc == 1)
+ bsr_print(env_bsrp(env), env_grammar(env), 1);
} else {
printf("There are errors!\n");
}
- destroy:
destroy_env(env);
}