ds: dict: re-implement dict_fini and dict_to_string

This commit is contained in:
2025-10-29 15:01:03 +00:00
parent 2d5da8605d
commit 053dd26304

View File

@@ -394,38 +394,30 @@ static void dict_fini(b_object *obj, void *priv)
{
struct b_dict_p *dict = priv;
#if 0
b_btree_iterator tree_it;
b_btree_iterator_begin(&dict->d_buckets, &tree_it);
while (b_btree_iterator_is_valid(&tree_it)) {
struct b_btree_node *node = b_btree_first(&dict->d_buckets);
while (node) {
struct b_dict_bucket *bucket
= b_unbox(struct b_dict_bucket, tree_it.node, bk_node);
b_btree_iterator_erase(&tree_it);
= b_unbox(struct b_dict_bucket, node, bk_node);
struct b_btree_node *next_node = b_btree_next(node);
b_btree_delete(&dict->d_buckets, node);
if (!bucket) {
continue;
}
b_queue_iterator bucket_it;
b_queue_iterator_begin(&bucket->bk_items, &bucket_it);
while (b_queue_iterator_is_valid(&bucket_it)) {
struct b_queue_entry *entry = b_queue_first(&bucket->bk_items);
while (entry) {
struct b_dict_bucket_item *item = b_unbox(
struct b_dict_bucket_item, bucket_it.entry,
bi_entry);
b_queue_iterator_erase(&bucket_it);
if (!item) {
continue;
}
struct b_dict_bucket_item, entry, bi_entry);
struct b_queue_entry *next_entry = b_queue_next(entry);
b_queue_delete(&bucket->bk_items, entry);
free(item->bi_str);
b_object_unref(item->bi_value);
free(item);
entry = next_entry;
}
free(bucket);
node = next_node;
}
#endif
}
static void dict_to_string(const b_object *obj, b_stream *out)
@@ -441,33 +433,44 @@ static void dict_to_string(const b_object *obj, b_stream *out)
b_stream_push_indent(out, 1);
size_t len = dict_get_size(dict);
size_t i = 0;
#if 0
b_dict_iterator it;
b_dict_foreach(&it, (b_dict *)obj)
{
b_object_to_string(it.key, out);
b_stream_write_string(out, ": ", NULL);
struct b_btree_node *node = b_btree_first(&dict->d_buckets);
while (node) {
struct b_dict_bucket *bucket
= b_unbox(struct b_dict_bucket, node, bk_node);
bool is_string = b_object_is_type(it.value, B_TYPE_STRING);
struct b_queue_entry *entry = b_queue_first(&bucket->bk_items);
while (entry) {
struct b_dict_bucket_item *item = b_unbox(
struct b_dict_bucket_item, entry, bi_entry);
if (is_string) {
b_stream_write_char(out, '"');
b_object_to_string(item->bi_str, out);
b_stream_write_string(out, ": ", NULL);
bool is_string
= b_object_is_type(item->bi_value, B_TYPE_STRING);
if (is_string) {
b_stream_write_char(out, '"');
}
b_object_to_string(item->bi_value, out);
if (is_string) {
b_stream_write_char(out, '"');
}
if (i < len - 1) {
b_stream_write_string(out, ",", NULL);
}
b_stream_write_char(out, '\n');
entry = b_queue_next(entry);
i++;
}
b_object_to_string(it.value, out);
if (is_string) {
b_stream_write_char(out, '"');
}
if (it.i < len - 1) {
b_stream_write_string(out, ",", NULL);
}
b_stream_write_char(out, '\n');
node = b_btree_next(node);
}
#endif
b_stream_pop_indent(out);
b_stream_write_char(out, '}');