From c664fcba196669b329e3e8f63c76120b5cd50df2 Mon Sep 17 00:00:00 2001 From: Ákos Kőrösi Date: Sun, 17 May 2026 01:00:28 +0200 Subject: cleanups - put some definitions in `typeutils.h` - remove superfluous code sections --- typeutils.h | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) (limited to 'typeutils.h') diff --git a/typeutils.h b/typeutils.h index daf7c3d..7225fce 100644 --- a/typeutils.h +++ b/typeutils.h @@ -72,8 +72,10 @@ } -DECLARE_VEC(char, String); +DECLARE_VEC(int, IntVec) +DECLARE_VEC(char, String); +DECLARE_VEC(char*, StrVec) static void append_str_to_String(String* target, const char* src_str) { @@ -102,3 +104,53 @@ static inline char* inner(String* str) { bool some; \ T value; \ } Name; + +DECLARE_MAYBE(char*, MaybeStr) + + +typedef struct { + char* key; + char* val; +} StrPair; + +DECLARE_VEC(StrPair, KeyValMap) + +void set_map_pair(KeyValMap* map, char* key, char* val) { +for (int i = 0; i < map->count; i++) { + char* key_i = get_from_KeyValMap(map, i)->key; + if (key_i == NULL) continue; + if (strcmp(key_i, key) == 0) { + // TODO: maybe copy instead + strcpy( + map->blocks[i / map->block_size][i % map->block_size].val, + val + ); + break; + } + } +} + +MaybeStr get_map_value(KeyValMap* map, char* key) { + for (int i = 0; i < map->count; i++) { + char* key_i = get_from_KeyValMap(map, i)->key; + if (key_i == NULL) continue; + if (strcmp(key_i, key) == 0) { + return (MaybeStr){ + .some = true, + .value = get_from_KeyValMap(map, i)->val + }; + } + } + return (MaybeStr){.some = false}; +} + +void unset_map_key(KeyValMap* map, char* key) { + for (int i = 0; i < map->count; i++) { + char* key_i = get_from_KeyValMap(map, i)->key; + if (key_i == NULL) continue; + if (strcmp(key_i, key) == 0) { + map->blocks[i / map->block_size][i % map->block_size].key = NULL; + break; + } + } +} -- cgit v1.2.3