diff options
Diffstat (limited to 'src/symtab.c')
-rw-r--r-- | src/symtab.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/symtab.c b/src/symtab.c index 279fdb9..8fcba3c 100644 --- a/src/symtab.c +++ b/src/symtab.c @@ -11,6 +11,12 @@ struct symtab { symval_t val; }; +struct typetab { + typetab_t *child[4]; + strview_t key; + type_t *val; +}; + symval_t * symtab_insert(symtab_t **m, strview_t sv, arena_t *a) { @@ -25,3 +31,18 @@ symtab_insert(symtab_t **m, strview_t sv, arena_t *a) (*m)->key = sv; return &(*m)->val; } + +type_t ** +typetab_insert(typetab_t **m, strview_t sv, arena_t *a) +{ + for (uint64_t h = strview_hash(sv); *m; h <<= 2) { + if (strview_eq(sv, (*m)->key)) + return &(*m)->val; + m = &(*m)->child[h >> 62]; + } + if (a == NULL) + return NULL; + *m = arena_new(a, typetab_t, 1); + (*m)->key = sv; + return &(*m)->val; +} |