From 3fb5430080199a6d92a63f8259fe4a88df9b83ba Mon Sep 17 00:00:00 2001 From: JSDurand Date: Tue, 1 Feb 2022 12:22:34 +0800 Subject: 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. --- src/bsr.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/bsr.c') 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() { -- cgit v1.2.3-18-g5258