ds: dict: re-implement dict_fini and dict_to_string
This commit is contained in:
89
ds/dict.c
89
ds/dict.c
@@ -394,38 +394,30 @@ static void dict_fini(b_object *obj, void *priv)
|
|||||||
{
|
{
|
||||||
struct b_dict_p *dict = priv;
|
struct b_dict_p *dict = priv;
|
||||||
|
|
||||||
#if 0
|
struct b_btree_node *node = b_btree_first(&dict->d_buckets);
|
||||||
b_btree_iterator tree_it;
|
while (node) {
|
||||||
b_btree_iterator_begin(&dict->d_buckets, &tree_it);
|
|
||||||
while (b_btree_iterator_is_valid(&tree_it)) {
|
|
||||||
struct b_dict_bucket *bucket
|
struct b_dict_bucket *bucket
|
||||||
= b_unbox(struct b_dict_bucket, tree_it.node, bk_node);
|
= b_unbox(struct b_dict_bucket, node, bk_node);
|
||||||
b_btree_iterator_erase(&tree_it);
|
struct b_btree_node *next_node = b_btree_next(node);
|
||||||
|
b_btree_delete(&dict->d_buckets, node);
|
||||||
|
|
||||||
if (!bucket) {
|
struct b_queue_entry *entry = b_queue_first(&bucket->bk_items);
|
||||||
continue;
|
while (entry) {
|
||||||
}
|
|
||||||
|
|
||||||
b_queue_iterator bucket_it;
|
|
||||||
b_queue_iterator_begin(&bucket->bk_items, &bucket_it);
|
|
||||||
while (b_queue_iterator_is_valid(&bucket_it)) {
|
|
||||||
struct b_dict_bucket_item *item = b_unbox(
|
struct b_dict_bucket_item *item = b_unbox(
|
||||||
struct b_dict_bucket_item, bucket_it.entry,
|
struct b_dict_bucket_item, entry, bi_entry);
|
||||||
bi_entry);
|
struct b_queue_entry *next_entry = b_queue_next(entry);
|
||||||
b_queue_iterator_erase(&bucket_it);
|
b_queue_delete(&bucket->bk_items, entry);
|
||||||
|
|
||||||
if (!item) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
free(item->bi_str);
|
free(item->bi_str);
|
||||||
b_object_unref(item->bi_value);
|
b_object_unref(item->bi_value);
|
||||||
free(item);
|
free(item);
|
||||||
|
|
||||||
|
entry = next_entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(bucket);
|
free(bucket);
|
||||||
|
node = next_node;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dict_to_string(const b_object *obj, b_stream *out)
|
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);
|
b_stream_push_indent(out, 1);
|
||||||
size_t len = dict_get_size(dict);
|
size_t len = dict_get_size(dict);
|
||||||
|
size_t i = 0;
|
||||||
|
|
||||||
#if 0
|
struct b_btree_node *node = b_btree_first(&dict->d_buckets);
|
||||||
b_dict_iterator it;
|
while (node) {
|
||||||
b_dict_foreach(&it, (b_dict *)obj)
|
struct b_dict_bucket *bucket
|
||||||
{
|
= b_unbox(struct b_dict_bucket, node, bk_node);
|
||||||
b_object_to_string(it.key, out);
|
|
||||||
b_stream_write_string(out, ": ", NULL);
|
|
||||||
|
|
||||||
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_object_to_string(item->bi_str, out);
|
||||||
b_stream_write_char(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++;
|
||||||
}
|
}
|
||||||
|
node = b_btree_next(node);
|
||||||
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');
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
b_stream_pop_indent(out);
|
b_stream_pop_indent(out);
|
||||||
b_stream_write_char(out, '}');
|
b_stream_write_char(out, '}');
|
||||||
|
|||||||
Reference in New Issue
Block a user