diff options
| author | steven-na <noreply.github@stvnc.dev> | 2026-10-02 00:28:46 -0700 |
|---|---|---|
| committer | steven-na <noreply.github@stvnc.dev> | 2026-10-02 00:28:46 -0700 |
| commit | e01d3f64d42e2fe88f737d4616424b1c5949ae85 (patch) | |
| tree | caf7102b19f8d2cc74069fe767e23fce6d27400b /src/map.h | |
| parent | b5f1cb4e373f859c41ec32d6fdb9b3c4597e37c2 (diff) | |
Improved map api
Diffstat (limited to 'src/map.h')
| -rw-r--r-- | src/map.h | 36 |
1 files changed, 32 insertions, 4 deletions
@@ -9,7 +9,35 @@ // Uses a5hash to hash keys. typedef struct _map_t* map_t; -map_t map_create(smrt_arena_t *arena, u64 table_size); - i32 map_insert(map_t const map, u8 const *key, u64 keylen, void *value); - i32 map_delete(map_t const map, u8 const *key, u64 keylen); - void *map_lookup(map_t const map, u8 const *key, u64 keylen); +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); |