meta: rename legacy object module to 'ds'
This commit is contained in:
94
ds/include/blue/ds/hashmap.h
Normal file
94
ds/include/blue/ds/hashmap.h
Normal file
@@ -0,0 +1,94 @@
|
||||
#ifndef BLUELIB_HASHMAP_H_
|
||||
#define BLUELIB_HASHMAP_H_
|
||||
|
||||
#include <blue/core/btree.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>
|
||||
|
||||
#define B_HASHMAP(p) ((b_hashmap *)(p))
|
||||
|
||||
#define B_HASHMAP_KEY(k, ks) \
|
||||
{ \
|
||||
.key_data = (k), .key_size = (ks) \
|
||||
}
|
||||
#define B_HASHMAP_VALUE(v, vs) \
|
||||
{ \
|
||||
.value_data = (v), .value_size = (vs) \
|
||||
}
|
||||
|
||||
#define B_HASHMAP_ITEM(k, ks, v, vs) \
|
||||
{ \
|
||||
.key = B_HASHMAP_KEY(k, ks), .value = B_HASHMAP_VALUE(v, vs) \
|
||||
}
|
||||
|
||||
#define B_HASHMAP_ITEM_END \
|
||||
{ \
|
||||
.key = {0}, .value = { 0 } \
|
||||
}
|
||||
|
||||
#define b_hashmap_foreach(it, hashmap) \
|
||||
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 *);
|
||||
|
||||
typedef struct b_hashmap_key {
|
||||
const void *key_data;
|
||||
size_t key_size;
|
||||
} b_hashmap_key;
|
||||
|
||||
typedef struct b_hashmap_value {
|
||||
void *value_data;
|
||||
size_t value_size;
|
||||
} b_hashmap_value;
|
||||
|
||||
typedef struct b_hashmap_item {
|
||||
b_hashmap_key key;
|
||||
b_hashmap_value value;
|
||||
} b_hashmap_item;
|
||||
|
||||
typedef struct b_hashmap_iterator {
|
||||
b_iterator _base;
|
||||
size_t i;
|
||||
const b_hashmap_key *key;
|
||||
const b_hashmap_value *value;
|
||||
|
||||
b_hashmap *_h;
|
||||
b_btree_node *_cbn;
|
||||
b_queue_entry *_cqe;
|
||||
} b_hashmap_iterator;
|
||||
|
||||
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(
|
||||
const b_hashmap *hashmap, const b_hashmap_key *key);
|
||||
|
||||
BLUE_API bool b_hashmap_has_key(const b_hashmap *hashmap, const b_hashmap_key *key);
|
||||
BLUE_API size_t b_hashmap_get_size(const b_hashmap *hashmap);
|
||||
BLUE_API bool b_hashmap_is_empty(const b_hashmap *hashmap);
|
||||
|
||||
BLUE_API int b_hashmap_iterator_begin(b_hashmap *hashmap, b_hashmap_iterator *it);
|
||||
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);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user