summaryrefslogtreecommitdiff
path: root/src/map.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/map.h')
-rw-r--r--src/map.h36
1 files changed, 32 insertions, 4 deletions
diff --git a/src/map.h b/src/map.h
index 6678ddd..f0d10ca 100644
--- a/src/map.h
+++ b/src/map.h
@@ -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);