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/ht.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/ht.c') diff --git a/src/ht.c b/src/ht.c index 45953f4..770eff6 100644 --- a/src/ht.c +++ b/src/ht.c @@ -3,7 +3,7 @@ #include #include "ht.h" -#define HT_REHASH_THRESHOLD 0.5 +#define HT_REHASH_THRESHOLD 0.7 P_ATTR static NUM @@ -171,7 +171,10 @@ destroy_ht(ht * restrict htp, HT_DESTROY_FLAG flag) static BOOL ht_expand(ht *htp) { - htp->capability <<= 1; + UNUM newcap = htp->capability << 1; + + if (newcap < htp->capability + (1 << 20)) htp->capability = newcap; + else htp->capability = htp->capability + (1 << 20); void **keys = NULL; NUM size = htp->size; -- cgit v1.2.3-18-g5258