Files
fx/ds/include/blue/ds/dict.h

63 lines
1.9 KiB
C

#ifndef BLUE_DS_DICT_H_
#define BLUE_DS_DICT_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/string.h>
B_DECLS_BEGIN;
#define B_TYPE_DICT (b_dict_get_type())
#define B_TYPE_DICT_ITERATOR (b_dict_iterator_get_type())
struct b_dict_p;
B_DECLARE_TYPE(b_dict);
B_DECLARE_TYPE(b_dict_iterator);
B_TYPE_CLASS_DECLARATION_BEGIN(b_dict)
B_TYPE_CLASS_DECLARATION_END(b_dict)
B_TYPE_CLASS_DECLARATION_BEGIN(b_dict_iterator)
B_TYPE_CLASS_DECLARATION_END(b_dict_iterator)
#define B_DICT_ITEM(k, v) {.key = (k), .value = (v)}
#define B_DICT_ITEM_END {.key = NULL, .value = NULL}
#define b_dict_foreach(it, dict) \
for (int z__b_unique_name() = b_dict_iterator_begin(dict, it); \
(it)->key != NULL; b_dict_iterator_next(it))
typedef struct b_dict_item {
const b_string *key;
b_object *value;
} b_dict_item;
BLUE_API b_type b_dict_get_type(void);
BLUE_API b_type b_dict_iterator_get_type(void);
B_TYPE_DEFAULT_CONSTRUCTOR(b_dict, B_TYPE_DICT);
#if 0
BLUE_API b_dict *b_dict_create_with_items(const b_dict_item *items);
#endif
BLUE_API b_status b_dict_put(b_dict *dict, const char *key, b_object *value);
BLUE_API b_status b_dict_put_sk(b_dict *dict, const b_string *key, b_object *value);
BLUE_API b_object *b_dict_at(const b_dict *dict, const char *key);
BLUE_API b_object *b_dict_at_sk(const b_dict *dict, const b_string *key);
BLUE_API b_object *b_dict_get(b_dict *dict, const char *key);
BLUE_API b_object *b_dict_get_sk(b_dict *dict, const b_string *key);
BLUE_API bool b_dict_has_key(const b_dict *dict, const char *key);
BLUE_API bool b_dict_has_skey(const b_dict *dict, const b_string *key);
BLUE_API size_t b_dict_get_size(const b_dict *dict);
BLUE_API bool b_dict_is_empty(const b_dict *dict);
B_DECLS_END;
#endif