summaryrefslogtreecommitdiff
path: root/ht.h
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2023-08-05 04:15:17 +0100
committerubq323 <ubq323@ubq323.website>2023-08-05 04:15:20 +0100
commit9ee73a8459eb2bb58adc29da02de312b7e4e7dca (patch)
treef41bddde050c61e254af8ba4c53a3bc11ca7b804 /ht.h
parent93fe66fb8ef5c731b46a30a804f74b4bf3b133d7 (diff)
refactor hashtables, and use objstrings for keys
doesn't yet work without string interning, which will require further refactoring
Diffstat (limited to 'ht.h')
-rw-r--r--ht.h17
1 files changed, 9 insertions, 8 deletions
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