summaryrefslogtreecommitdiff
path: root/src/bsr.c
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2022-02-01 12:22:34 +0800
committerJSDurand <mmemmew@gmail.com>2022-02-01 12:22:34 +0800
commit3fb5430080199a6d92a63f8259fe4a88df9b83ba (patch)
tree767c3266b59566e98234ec81b228cf8115096939 /src/bsr.c
parenteb007d554251456a2a508849edf91b15aab1333e (diff)
need to stop abusing hash tables
Hash tables take too much space! If I use hash tables, the length of the input will be severely limited, to an unacceptable extent. So we have to use arrays instead.
Diffstat (limited to 'src/bsr.c')
-rw-r--r--src/bsr.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/bsr.c b/src/bsr.c
index bd0a84c..c034072 100644
--- a/src/bsr.c
+++ b/src/bsr.c
@@ -474,6 +474,33 @@ bsr_find(CCR_MOD(bsr *) b, CCR_MOD(Grammar *) g,
return result;
}
+ht *
+bsr_lookup(CCR_MOD(bsr *) b, BOOL * const restrict errorp,
+ NUM X, NUM i, NUM j)
+{
+ *errorp = 0;
+ ht *result = NULL;
+
+ if (X < 0 || X >= b->f.len) {
+ fleprintf("Invalid X: %ld\n", X);
+ goto cleanup;
+ }
+
+ if (!((b->f.array+X)->initialized)) goto success;
+
+ pair2 p2 = (pair2) { .x = i, .y = j };
+
+ result = (ht *) ht_find((b->f.array+X)->table, &p2);
+
+ goto success;
+
+ cleanup:
+ *errorp = 1;
+
+ success:
+ return result;
+}
+
static void
print_sep()
{