From 0db19dcfafe5b2b3cbebaec9098ec50b9d6b1102 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Sat, 22 Mar 2025 16:55:57 +0200 Subject: use new hashmap --- include/ek/scope.h | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/ek/scope.h b/include/ek/scope.h index 8c56640..d09c086 100644 --- a/include/ek/scope.h +++ b/include/ek/scope.h @@ -11,6 +11,7 @@ */ #include +#include #include "ast.h" #include "debug.h" @@ -25,13 +26,10 @@ enum scope_flags { SCOPE_ROOT = (1 << 2) }; -struct visible_tuple { - struct ast *def; -}; - #define MAP_KEY char * #define MAP_TYPE struct ast * #define MAP_CMP(a, b) strcmp((a), (b)) +#define MAP_HASH(a) CONTS_MAP_STR_HASH(a) #define MAP_NAME visible #include @@ -50,16 +48,26 @@ static inline int expanded_key_cmp(struct expanded_key a, struct expanded_key b) return !type_lists_match(a.types, b.types); } +static inline size_t expanded_key_hash(struct expanded_key a) +{ + return (uintptr_t)a.def; +} + #define MAP_KEY struct expanded_key #define MAP_TYPE struct ast * #define MAP_CMP(a, b) expanded_key_cmp((a), (b)) +#define MAP_HASH(a) expanded_key_hash(a) #define MAP_NAME expanded #include -#define SPTREE_TYPE struct ast * -#define SPTREE_CMP(a, b) ((uintptr_t)(a) - (uintptr_t)(b)) -#define SPTREE_NAME exported -#include +/* use map like set, could maybe be added to conts directly with some + * convenience wrappers? */ +#define MAP_KEY struct ast * +#define MAP_TYPE struct ast * +#define MAP_CMP(a, b) ((uintptr_t)(a) - (uintptr_t)(b)) +#define MAP_HASH(a) ((uintptr_t)(a)) +#define MAP_NAME exported +#include /** * Scope. -- cgit v1.3