From 9ee73a8459eb2bb58adc29da02de312b7e4e7dca Mon Sep 17 00:00:00 2001 From: ubq323 Date: Sat, 5 Aug 2023 04:15:17 +0100 Subject: refactor hashtables, and use objstrings for keys doesn't yet work without string interning, which will require further refactoring --- ht.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'ht.h') diff --git a/ht.h b/ht.h index 5aaffe7..65e9012 100644 --- a/ht.h +++ b/ht.h @@ -1,22 +1,23 @@ #ifndef _ht_h #define _ht_h -#define HT_SIZE 128 +#include "val.h" typedef struct { - char *k; - int v; + ObjString *k; + Val v; } HtEntry; typedef struct { - int len; - HtEntry b[HT_SIZE]; + size_t len; + size_t cap; + HtEntry *b; } Ht; -typedef Ht Env; +uint32_t hash(char *s, size_t len); Ht ht_new(); -void ht_put(Ht *h, char *k, int v); -int ht_get(Ht *h, char *k, int *v); +void ht_put(Ht *h, ObjString *k, Val v); +Val ht_get(Ht *h, ObjString *k); #endif -- cgit v1.2.3