72 lines
2.1 KiB
C
72 lines
2.1 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())
|
|
|
|
struct b_dict_p;
|
|
|
|
B_DECLARE_TYPE(b_dict);
|
|
|
|
B_TYPE_CLASS_DECLARATION_BEGIN(b_dict)
|
|
B_TYPE_CLASS_DECLARATION_END(b_dict)
|
|
|
|
#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_iterator {
|
|
b_iterator _base;
|
|
size_t i;
|
|
const b_string *key;
|
|
b_object *value;
|
|
|
|
b_dict *_d;
|
|
struct b_dict_p *_d_p;
|
|
b_btree_node *_cbn;
|
|
b_queue_entry *_cqe;
|
|
} b_dict_iterator;
|
|
|
|
typedef struct b_dict_item {
|
|
const char *key;
|
|
b_object *value;
|
|
} b_dict_item;
|
|
|
|
BLUE_API b_type b_dict_get_type(void);
|
|
|
|
B_TYPE_DEFAULT_CONSTRUCTOR(b_dict, B_TYPE_DICT);
|
|
|
|
BLUE_API b_dict *b_dict_create_with_items(const b_dict_item *items);
|
|
|
|
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);
|
|
|
|
BLUE_API int b_dict_iterator_begin(b_dict *dict, b_dict_iterator *it);
|
|
BLUE_API bool b_dict_iterator_next(b_dict_iterator *it);
|
|
BLUE_API b_status b_dict_iterator_erase(b_dict_iterator *it);
|
|
BLUE_API bool b_dict_iterator_is_valid(const b_dict_iterator *it);
|
|
|
|
B_DECLS_END;
|
|
|
|
#endif
|