summaryrefslogtreecommitdiff
path: root/src/ht.c
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2022-01-31 09:23:20 +0800
committerJSDurand <mmemmew@gmail.com>2022-01-31 09:23:20 +0800
commita8bd5e9d85ac9928bd29add82e887f82642af893 (patch)
tree74e377f9fccffc2779ff97fa0bd8ad180b9c865c /src/ht.c
parente555c88b8107caf886da229444c2bed1aaef6c2c (diff)
test/check_cnp: working algorithm
I now have a working algorithm in test/check_cnp. It can correctly parse the grammar for an esoteric language called "Brainfuck". This language does not matter. What matters is that it contains parentheses. So this shows that at least for grammars as complex as parentheses, this parser works well. Haha.
Diffstat (limited to 'src/ht.c')
-rw-r--r--src/ht.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/ht.c b/src/ht.c
index 7965941..45953f4 100644
--- a/src/ht.c
+++ b/src/ht.c
@@ -323,6 +323,36 @@ ht_delete(ht * const restrict htp, void *key, HT_DELETE_FLAG flag)
return 0;
}
+void
+ht_reset(ht * const restrict htp, HT_DELETE_FLAG flag)
+{
+ for (int i = 0; i < htp->size; i++) {
+ switch (flag) {
+ case DELETE_KEY:
+ case DELETE_EVERY:
+ free(*(htp->keys+i));
+ break;
+ default:
+ break;
+ }
+
+ switch (flag) {
+ case DELETE_VALUE:
+ case DELETE_EVERY:
+ free(*(htp->values+i));
+ break;
+ default:
+ break;
+ }
+ }
+
+ htp->size = 0;
+
+ memset(htp->values, 0, sizeof(void*) * htp->capability);
+ memset(htp->keys, 0, sizeof(void*) * htp->capability);
+ memset(htp->indices, 0xff, sizeof (NUM) * htp->capability);
+}
+
P_ATTR
void *
ht_find(CCR_MOD(ht *) htp, void *key)