object: hashmap: implement key/value destructors

This commit is contained in:
2025-06-27 21:46:55 +01:00
parent 5634506433
commit 579a9e8505
3 changed files with 42 additions and 11 deletions

View File

@@ -26,7 +26,7 @@
#define B_HASHMAP_ITEM_END \
{ \
.key = {0}, .value = {0} \
.key = {0}, .value = { 0 } \
}
#define b_hashmap_foreach(it, hashmap) \
@@ -35,16 +35,17 @@
typedef struct b_hashmap b_hashmap;
typedef void (*b_hashmap_key_destructor)(void *);
typedef void (*b_hashmap_value_destructor)(void *);
typedef struct b_hashmap_key {
const void *key_data;
size_t key_size;
bool key_owned;
} b_hashmap_key;
typedef struct b_hashmap_value {
void *value_data;
size_t value_size;
bool value_owned;
} b_hashmap_value;
typedef struct b_hashmap_item {
@@ -63,7 +64,8 @@ typedef struct b_hashmap_iterator {
b_queue_entry *_cqe;
} b_hashmap_iterator;
BLUE_API b_hashmap *b_hashmap_create(void);
BLUE_API b_hashmap *b_hashmap_create(
b_hashmap_key_destructor key_dtor, b_hashmap_value_destructor value_dtor);
BLUE_API b_hashmap *b_hashmap_create_with_items(const b_hashmap_item *items);
static inline b_hashmap *b_hashmap_retain(b_hashmap *hashmap)