#ifndef BLUELIB_DICT_H_ #define BLUELIB_DICT_H_ #include #include #include #include #include #include #define B_DICT(p) ((b_dict *)(p)) #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 b_dict; typedef struct b_dict_iterator { b_iterator _base; size_t i; const char *key; b_object *value; b_dict *_d; 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; extern b_dict *b_dict_create(void); extern b_dict *b_dict_create_with_items(const b_dict_item *items); static inline b_dict *b_dict_retain(b_dict *dict) { return B_DICT(b_retain(B_OBJECT(dict))); } static inline void b_dict_release(b_dict *dict) { b_release(B_OBJECT(dict)); } extern b_status b_dict_put(b_dict *dict, const char *key, b_object *value); extern b_object *b_dict_at(const b_dict *dict, const char *key); extern b_object *b_dict_get(b_dict *dict, const char *key); extern bool b_dict_has_key(const b_dict *dict, const char *key); extern size_t b_dict_get_size(const b_dict *dict); extern bool b_dict_is_empty(const b_dict *dict); extern int b_dict_iterator_begin(b_dict *dict, b_dict_iterator *it); extern bool b_dict_iterator_next(b_dict_iterator *it); extern b_status b_dict_iterator_erase(b_dict_iterator *it); extern bool b_dict_iterator_is_valid(const b_dict_iterator *it); #endif