#pragma once #include "common.h" #include "smrt_arena.h" // Hashmap structure that stores u8* keys and void* values. // API: map_create, map_insert, map_delete, map_lookup // There is no map_destroy. It is allocated on the arena // Uses a5hash to hash keys. typedef struct _map_t* map_t; typedef enum { MapInsertResultSuccessNew = 0, MapInsertResultSuccessPreexisted = 1, MapInsertResultFailedFull = -1, } MapInsertResultK; typedef enum { MapDeleteResultSuccess = 0, MapDeleteResultNotFound = -1, } MapDeleteResultK; typedef enum { MapChangeKeyPtrResultSuccess = 0, MapChangeKeyPtrResultKeyNotPresent = -1, } MapChangeKeyPtrResultK; map_t map_create(smrt_arena_t *arena, u64 table_size); MapInsertResultK map_insert(map_t map, u8 const *key, u64 keylen, void *value); MapDeleteResultK map_delete(map_t map, u8 const *key, u64 keylen); void map_clear(map_t map); void *map_lookup(map_t const map, u8 const *key, u64 keylen); #define map_lookup_or(map, key, keylen, default_val) \ ({ \ void *val = map_lookup((map), (key), (keylen); \ (val != NULL) ? val : (default_val); \ }) MapChangeKeyPtrResultK map_change_key_ptr(map_t map, u8 const *new_but_identical_key, u64 keylen);