ds: hashmap: convert to new object system

This commit is contained in:
2025-10-19 12:20:58 +01:00
parent 5bf3c50a7f
commit 59fdb55a8b
3 changed files with 386 additions and 340 deletions

View File

@@ -1,15 +1,23 @@
#ifndef BLUELIB_HASHMAP_H_
#define BLUELIB_HASHMAP_H_
#ifndef BLUE_DS_HASHMAP_H_
#define BLUE_DS_HASHMAP_H_
#include <blue/core/btree.h>
#include <blue/core/macros.h>
#include <blue/core/misc.h>
#include <blue/core/queue.h>
#include <blue/core/status.h>
#include <blue/ds/object.h>
#include <blue/ds/type.h>
#include <stddef.h>
#define B_HASHMAP(p) ((b_hashmap *)(p))
B_DECLS_BEGIN;
struct b_hashmap_p;
#define B_TYPE_HASHMAP (b_hashmap_get_type())
B_DECLARE_TYPE(b_hashmap);
B_TYPE_CLASS_DECLARATION_BEGIN(b_hashmap)
B_TYPE_CLASS_DECLARATION_END(b_hashmap)
#define B_HASHMAP_KEY(k, ks) {.key_data = (k), .key_size = (ks)}
#define B_HASHMAP_VALUE(v, vs) {.value_data = (v), .value_size = (vs)}
@@ -23,8 +31,6 @@
for (int z__b_unique_name() = b_hashmap_iterator_begin(hashmap, it); \
(it)->key != NULL; b_hashmap_iterator_next(it))
typedef struct b_hashmap b_hashmap;
typedef void (*b_hashmap_key_destructor)(void *);
typedef void (*b_hashmap_value_destructor)(void *);
@@ -55,23 +61,17 @@ typedef struct b_hashmap_iterator {
const b_hashmap_value *value;
b_hashmap *_h;
struct b_hashmap_p *_h_p;
b_btree_node *_cbn;
b_queue_entry *_cqe;
} b_hashmap_iterator;
BLUE_API b_type b_hashmap_get_type(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)
{
return B_HASHMAP(b_retain(B_DSREF(hashmap)));
}
static inline void b_hashmap_release(b_hashmap *hashmap)
{
b_release(B_DSREF(hashmap));
}
BLUE_API b_status b_hashmap_put(
b_hashmap *hashmap, const b_hashmap_key *key, const b_hashmap_value *value);
BLUE_API const b_hashmap_value *b_hashmap_get(
@@ -86,4 +86,6 @@ BLUE_API bool b_hashmap_iterator_next(b_hashmap_iterator *it);
BLUE_API b_status b_hashmap_iterator_erase(b_hashmap_iterator *it);
BLUE_API bool b_hashmap_iterator_is_valid(const b_hashmap_iterator *it);
B_DECLS_END;
#endif