ds: dict: update iterator interface

This commit is contained in:
2025-10-29 14:35:07 +00:00
parent 824d436a1c
commit bae95909ca
2 changed files with 192 additions and 99 deletions

View File

@@ -10,15 +10,20 @@
B_DECLS_BEGIN;
#define B_TYPE_DICT (b_dict_get_type())
#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}
@@ -26,28 +31,19 @@ B_TYPE_CLASS_DECLARATION_END(b_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;
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);
@@ -61,11 +57,6 @@ 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