diff options
| author | Ákos Kőrösi <korakos99@gmail.com> | 2026-05-17 01:00:28 +0200 |
|---|---|---|
| committer | Ákos Kőrösi <korakos99@gmail.com> | 2026-05-17 01:00:28 +0200 |
| commit | c664fcba196669b329e3e8f63c76120b5cd50df2 (patch) | |
| tree | dbe3a068c66a3ea5a280253ac317d769176e9e83 /typeutils.h | |
| parent | b4b2b83b94ce77de727e9eed2736908c649f62bb (diff) | |
cleanups
- put some definitions in `typeutils.h`
- remove superfluous code sections
Diffstat (limited to 'typeutils.h')
| -rw-r--r-- | typeutils.h | 54 |
1 files changed, 53 insertions, 1 deletions
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; + } + } +} |
