Files
bluelib/ds/dict.c

721 lines
17 KiB
C
Raw Normal View History

2024-10-24 19:24:54 +01:00
#include <blue/core/status.h>
#include <blue/core/stream.h>
#include <blue/ds/dict.h>
#include <blue/ds/string.h>
2024-10-24 19:24:54 +01:00
#include <stdbool.h>
#include <stdlib.h>
#define HASH_OFFSET_BASIS 0xcbf29ce484222325
#define HASH_PRIME 0x100000001b3
2025-10-19 11:53:08 +01:00
/*** PRIVATE DATA *************************************************************/
2024-10-24 19:24:54 +01:00
2025-10-19 11:53:08 +01:00
struct b_dict_bucket_item {
b_queue_entry bi_entry;
b_string *bi_str;
b_object *bi_value;
};
2024-10-24 19:24:54 +01:00
2025-10-19 11:53:08 +01:00
struct b_dict_bucket {
b_btree_node bk_node;
uint64_t bk_hash;
b_queue bk_items;
};
2024-10-24 19:24:54 +01:00
2025-10-19 11:53:08 +01:00
struct b_dict_p {
b_btree d_buckets;
2024-10-24 19:24:54 +01:00
};
2025-10-29 14:35:07 +00:00
struct b_dict_iterator_p {
size_t i;
b_dict_item item;
b_dict *_d;
struct b_dict_p *_d_p;
b_btree_node *_cbn;
b_queue_entry *_cqe;
};
2025-10-19 11:53:08 +01:00
/*** MISC FUNCTIONS ***********************************************************/
2024-10-24 19:24:54 +01:00
2025-10-19 11:53:08 +01:00
static B_BTREE_DEFINE_SIMPLE_GET(
struct b_dict_bucket, uint64_t, bk_node, bk_hash, get_bucket);
static B_BTREE_DEFINE_SIMPLE_INSERT(
struct b_dict_bucket, bk_node, bk_hash, put_bucket);
2024-10-24 19:24:54 +01:00
2025-10-19 11:53:08 +01:00
uint64_t b_cstr_hash(const char *s)
2024-10-24 19:24:54 +01:00
{
2025-10-19 11:53:08 +01:00
uint64_t hash = HASH_OFFSET_BASIS;
2024-10-24 19:24:54 +01:00
2025-10-19 11:53:08 +01:00
for (size_t i = 0; s[i]; i++) {
hash *= HASH_PRIME;
hash ^= s[i];
2024-10-24 19:24:54 +01:00
}
2025-10-19 11:53:08 +01:00
return hash;
2024-10-24 19:24:54 +01:00
}
2025-10-19 11:53:08 +01:00
/*** PRIVATE FUNCTIONS ********************************************************/
2024-10-24 19:24:54 +01:00
2025-10-19 11:53:08 +01:00
static struct b_dict_bucket *create_bucket(void)
2024-10-24 19:24:54 +01:00
{
struct b_dict_bucket *bucket = malloc(sizeof *bucket);
if (!bucket) {
return NULL;
}
memset(bucket, 0x0, sizeof *bucket);
return bucket;
}
static struct b_dict_bucket_item *create_bucket_item(void)
{
struct b_dict_bucket_item *item = malloc(sizeof *item);
if (!item) {
return NULL;
}
memset(item, 0x0, sizeof *item);
return item;
}
2025-10-19 11:53:08 +01:00
static b_status dict_put(struct b_dict_p *dict, const char *key, b_object *value)
2024-10-24 19:24:54 +01:00
{
uint64_t hash = b_cstr_hash(key);
struct b_dict_bucket *bucket = get_bucket(&dict->d_buckets, hash);
if (!bucket) {
bucket = create_bucket();
if (!bucket) {
return B_ERR_NO_MEMORY;
}
bucket->bk_hash = hash;
put_bucket(&dict->d_buckets, bucket);
}
struct b_dict_bucket_item *item = create_bucket_item();
if (!item) {
return B_ERR_NO_MEMORY;
}
item->bi_str = b_string_create_from_cstr(key);
2025-10-19 11:53:08 +01:00
item->bi_value = b_object_ref(value);
b_queue_push_back(&bucket->bk_items, &item->bi_entry);
return B_SUCCESS;
}
2025-10-19 11:53:08 +01:00
static b_status dict_put_sk(
struct b_dict_p *dict, const b_string *key, b_object *value)
{
uint64_t hash = b_string_hash(key);
struct b_dict_bucket *bucket = get_bucket(&dict->d_buckets, hash);
if (!bucket) {
bucket = create_bucket();
if (!bucket) {
return B_ERR_NO_MEMORY;
}
bucket->bk_hash = hash;
put_bucket(&dict->d_buckets, bucket);
}
struct b_dict_bucket_item *item = create_bucket_item();
if (!item) {
return B_ERR_NO_MEMORY;
}
item->bi_str = b_string_duplicate(key);
2025-10-19 11:53:08 +01:00
item->bi_value = b_object_ref(value);
2024-10-24 19:24:54 +01:00
b_queue_push_back(&bucket->bk_items, &item->bi_entry);
return B_SUCCESS;
}
2025-10-19 11:53:08 +01:00
static b_object *dict_at(const struct b_dict_p *dict, const char *key)
2024-10-24 19:24:54 +01:00
{
uint64_t hash = b_cstr_hash(key);
struct b_dict_bucket *bucket = get_bucket(&dict->d_buckets, hash);
if (!bucket) {
return NULL;
}
2025-10-29 14:35:07 +00:00
struct b_queue_entry *entry = b_queue_first(&bucket->bk_items);
while (entry) {
2024-10-24 19:24:54 +01:00
struct b_dict_bucket_item *item
2025-10-29 14:35:07 +00:00
= b_unbox(struct b_dict_bucket_item, entry, bi_entry);
2024-10-24 19:24:54 +01:00
if (!strcmp(b_string_ptr(item->bi_str), key)) {
return item->bi_value;
}
2025-10-29 14:35:07 +00:00
entry = b_queue_next(entry);
}
return NULL;
}
2025-10-19 11:53:08 +01:00
static b_object *dict_at_sk(const struct b_dict_p *dict, const b_string *key)
{
uint64_t hash = b_string_hash(key);
struct b_dict_bucket *bucket = get_bucket(&dict->d_buckets, hash);
if (!bucket) {
return NULL;
}
2025-10-29 14:35:07 +00:00
struct b_queue_entry *entry = b_queue_first(&bucket->bk_items);
while (entry) {
struct b_dict_bucket_item *item
2025-10-29 14:35:07 +00:00
= b_unbox(struct b_dict_bucket_item, entry, bi_entry);
if (b_string_compare(item->bi_str, key)) {
2024-10-24 19:24:54 +01:00
return item->bi_value;
}
2025-10-29 14:35:07 +00:00
entry = b_queue_next(entry);
2024-10-24 19:24:54 +01:00
}
return NULL;
}
2025-10-19 11:53:08 +01:00
static b_object *dict_get(struct b_dict_p *dict, const char *key)
2024-10-24 19:24:54 +01:00
{
2025-10-19 11:53:08 +01:00
b_object *value = dict_at(dict, key);
2024-10-24 19:24:54 +01:00
if (value) {
2025-10-19 11:53:08 +01:00
b_object_ref(value);
2024-10-24 19:24:54 +01:00
}
return value;
}
2025-10-19 11:53:08 +01:00
static b_object *dict_get_sk(struct b_dict_p *dict, const b_string *key)
{
2025-10-19 11:53:08 +01:00
b_object *value = dict_at_sk(dict, key);
if (value) {
2025-10-19 11:53:08 +01:00
b_object_ref(value);
}
return value;
}
2025-10-19 11:53:08 +01:00
static bool dict_has_key(const struct b_dict_p *dict, const char *key)
2024-10-24 19:24:54 +01:00
{
2025-10-19 11:53:08 +01:00
return dict_at(dict, key) != NULL;
2024-10-24 19:24:54 +01:00
}
2025-10-19 11:53:08 +01:00
static bool dict_has_skey(const struct b_dict_p *dict, const b_string *key)
{
2025-10-19 11:53:08 +01:00
return dict_at_sk(dict, key) != NULL;
}
2025-10-19 11:53:08 +01:00
static size_t dict_get_size(const struct b_dict_p *dict)
2024-10-24 19:24:54 +01:00
{
size_t count = 0;
2025-10-29 14:35:07 +00:00
#if 0
2024-10-24 19:24:54 +01:00
b_btree_iterator it1;
b_queue_iterator it2;
b_btree_foreach (&it1, &dict->d_buckets) {
struct b_dict_bucket *bucket
= b_unbox(struct b_dict_bucket, it1.node, bk_node);
b_queue_foreach (&it2, &bucket->bk_items) {
count++;
}
}
2025-10-29 14:35:07 +00:00
#endif
2024-10-24 19:24:54 +01:00
return count;
}
2025-10-19 11:53:08 +01:00
static bool dict_is_empty(const struct b_dict_p *dict)
2024-10-24 19:24:54 +01:00
{
b_btree_node *first_node = b_btree_first(&dict->d_buckets);
struct b_dict_bucket *first_bucket
= b_unbox(struct b_dict_bucket, first_node, bk_node);
if (!first_bucket) {
return true;
}
b_queue_entry *first_entry = b_queue_first(&first_bucket->bk_items);
struct b_dict_bucket_item *first_item
= b_unbox(struct b_dict_bucket_item, first_entry, bi_entry);
if (!first_item) {
return true;
}
return false;
}
2025-10-19 11:53:08 +01:00
static bool get_next_node(
struct b_btree_node *cur_node, struct b_queue_entry *cur_entry,
struct b_btree_node **out_next_node, struct b_queue_entry **out_next_entry)
{
struct b_dict_bucket *cur_bucket
= b_unbox(struct b_dict_bucket, cur_node, bk_node);
if (!cur_bucket) {
return false;
}
struct b_dict_bucket_item *cur_item
= b_unbox(struct b_dict_bucket_item, cur_entry, bi_entry);
if (!cur_item) {
return false;
}
struct b_btree_node *next_node = cur_node;
struct b_queue_entry *next_entry = b_queue_next(cur_entry);
if (!next_entry) {
next_node = b_btree_next(cur_node);
if (!next_node) {
return false;
}
struct b_dict_bucket *next_bucket
= b_unbox(struct b_dict_bucket, next_node, bk_node);
if (!next_bucket) {
return false;
}
next_entry = b_queue_first(&next_bucket->bk_items);
if (!next_entry) {
return false;
}
}
struct b_dict_bucket_item *next_item
= b_unbox(struct b_dict_bucket_item, next_entry, bi_entry);
if (!next_item) {
return false;
}
*out_next_node = next_node;
*out_next_entry = next_entry;
return true;
}
static b_status delete_item(
struct b_dict_p *dict, struct b_dict_bucket *bucket,
struct b_dict_bucket_item *item)
{
b_queue_delete(&bucket->bk_items, &item->bi_entry);
free(item);
if (b_queue_empty(&bucket->bk_items)) {
b_btree_delete(&dict->d_buckets, &bucket->bk_node);
free(bucket);
}
return B_SUCCESS;
}
/*** PUBLIC FUNCTIONS *********************************************************/
2025-10-29 14:35:07 +00:00
#if 0
2025-10-19 11:53:08 +01:00
b_dict *b_dict_create_with_items(const b_dict_item *items)
{
b_dict *dict = b_dict_create();
if (!dict) {
return NULL;
}
struct b_dict_p *p = b_object_get_private(dict, B_TYPE_DICT);
for (size_t i = 0; items[i].key; i++) {
dict_put(p, items[i].key, items[i].value);
}
return dict;
}
2025-10-29 14:35:07 +00:00
#endif
2025-10-19 11:53:08 +01:00
b_status b_dict_put(b_dict *dict, const char *key, b_object *value)
{
B_CLASS_DISPATCH_STATIC(B_TYPE_DICT, dict_put, dict, key, value);
}
b_status b_dict_put_sk(b_dict *dict, const b_string *key, b_object *value)
{
B_CLASS_DISPATCH_STATIC(B_TYPE_DICT, dict_put_sk, dict, key, value);
}
b_object *b_dict_at(const b_dict *dict, const char *key)
{
B_CLASS_DISPATCH_STATIC(B_TYPE_DICT, dict_at, dict, key);
}
b_object *b_dict_at_sk(const b_dict *dict, const b_string *key)
{
B_CLASS_DISPATCH_STATIC(B_TYPE_DICT, dict_at_sk, dict, key);
}
b_object *b_dict_get(b_dict *dict, const char *key)
{
B_CLASS_DISPATCH_STATIC(B_TYPE_DICT, dict_get, dict, key);
}
b_object *b_dict_get_sk(b_dict *dict, const b_string *key)
{
B_CLASS_DISPATCH_STATIC(B_TYPE_DICT, dict_get_sk, dict, key);
}
bool b_dict_has_key(const b_dict *dict, const char *key)
{
B_CLASS_DISPATCH_STATIC(B_TYPE_DICT, dict_has_key, dict, key);
}
bool b_dict_has_skey(const b_dict *dict, const b_string *key)
{
B_CLASS_DISPATCH_STATIC(B_TYPE_DICT, dict_has_skey, dict, key);
}
size_t b_dict_get_size(const b_dict *dict)
{
B_CLASS_DISPATCH_STATIC_0(B_TYPE_DICT, dict_get_size, dict);
}
bool b_dict_is_empty(const b_dict *dict)
{
B_CLASS_DISPATCH_STATIC_0(B_TYPE_DICT, dict_is_empty, dict);
}
/*** PUBLIC ALIAS FUNCTIONS ***************************************************/
/*** VIRTUAL FUNCTIONS ********************************************************/
static void dict_init(b_object *obj, void *priv)
{
struct b_dict_p *dict = priv;
}
static void dict_fini(b_object *obj, void *priv)
2024-10-24 19:24:54 +01:00
{
2025-10-19 11:53:08 +01:00
struct b_dict_p *dict = priv;
2024-10-24 19:24:54 +01:00
struct b_btree_node *node = b_btree_first(&dict->d_buckets);
while (node) {
2025-10-19 11:53:08 +01:00
struct b_dict_bucket *bucket
= 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);
2025-10-19 11:53:08 +01:00
struct b_queue_entry *entry = b_queue_first(&bucket->bk_items);
while (entry) {
2025-10-19 11:53:08 +01:00
struct b_dict_bucket_item *item = b_unbox(
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);
2025-10-19 11:53:08 +01:00
free(item->bi_str);
b_object_unref(item->bi_value);
free(item);
entry = next_entry;
2025-10-19 11:53:08 +01:00
}
free(bucket);
node = next_node;
2025-10-19 11:53:08 +01:00
}
}
static void dict_to_string(const b_object *obj, b_stream *out)
2025-10-19 11:53:08 +01:00
{
struct b_dict_p *dict = b_object_get_private(obj, B_TYPE_DICT);
if (dict_is_empty(dict)) {
b_stream_write_string(out, "{}", NULL);
2024-10-24 19:24:54 +01:00
return;
}
b_stream_write_string(out, "{\n", NULL);
2024-10-24 19:24:54 +01:00
b_stream_push_indent(out, 1);
2025-10-19 11:53:08 +01:00
size_t len = dict_get_size(dict);
size_t i = 0;
2024-10-24 19:24:54 +01:00
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);
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);
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);
2024-10-24 19:24:54 +01:00
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);
}
2024-10-24 19:24:54 +01:00
b_stream_write_char(out, '\n');
entry = b_queue_next(entry);
i++;
}
node = b_btree_next(node);
2024-10-24 19:24:54 +01:00
}
b_stream_pop_indent(out);
b_stream_write_char(out, '}');
2024-10-24 19:24:54 +01:00
}
2025-10-29 14:35:07 +00:00
/*** ITERATOR FUNCTIONS *******************************************************/
2025-10-19 11:53:08 +01:00
2025-10-29 14:35:07 +00:00
static b_iterator *iterable_begin(b_dict *dict)
{
b_iterator *it_obj = b_object_create(B_TYPE_DICT_ITERATOR);
if (!it_obj) {
return NULL;
}
2025-10-19 11:53:08 +01:00
2025-10-29 14:35:07 +00:00
struct b_dict_iterator_p *it
= b_object_get_private(it_obj, B_TYPE_DICT_ITERATOR);
2025-10-19 11:53:08 +01:00
2025-10-29 14:35:07 +00:00
it->i = 0;
it->_d = dict;
it->_d_p = b_object_get_private(dict, B_TYPE_DICT);
2025-10-19 11:53:08 +01:00
2025-10-29 14:35:07 +00:00
if (dict_is_empty(it->_d_p)) {
it->item.key = NULL;
it->item.value = NULL;
return it_obj;
}
2024-10-24 19:24:54 +01:00
2025-10-29 14:35:07 +00:00
b_btree_node *first_node = b_btree_first(&it->_d_p->d_buckets);
struct b_dict_bucket *first_bucket
= b_unbox(struct b_dict_bucket, first_node, bk_node);
if (!first_bucket) {
it->item.key = NULL;
it->item.value = NULL;
return it_obj;
}
2024-10-24 19:24:54 +01:00
2025-10-29 14:35:07 +00:00
b_queue_entry *first_entry = b_queue_first(&first_bucket->bk_items);
struct b_dict_bucket_item *first_item
= b_unbox(struct b_dict_bucket_item, first_entry, bi_entry);
if (!first_item) {
it->item.key = NULL;
it->item.value = NULL;
return it_obj;
}
2024-10-24 19:24:54 +01:00
2025-10-29 14:35:07 +00:00
it->item.key = first_item->bi_str;
it->item.value = first_item->bi_value;
it->_d = dict;
it->_cbn = first_node;
it->_cqe = first_entry;
2024-10-24 19:24:54 +01:00
2025-10-29 14:35:07 +00:00
return it_obj;
}
static const b_iterator *iterable_cbegin(const b_dict *dict)
2024-10-24 19:24:54 +01:00
{
2025-10-29 14:35:07 +00:00
b_iterator *it_obj = b_object_create(B_TYPE_DICT_ITERATOR);
if (!it_obj) {
return NULL;
}
struct b_dict_iterator_p *it
= b_object_get_private(it_obj, B_TYPE_DICT_ITERATOR);
2024-10-24 19:24:54 +01:00
it->i = 0;
2025-10-29 14:35:07 +00:00
it->_d = (b_dict *)dict;
2025-10-19 11:53:08 +01:00
it->_d_p = b_object_get_private(dict, B_TYPE_DICT);
if (dict_is_empty(it->_d_p)) {
2025-10-29 14:35:07 +00:00
it->item.key = NULL;
it->item.value = NULL;
b_iterator_set_status(it_obj, B_ERR_NO_DATA);
return it_obj;
2024-10-24 19:24:54 +01:00
}
2025-10-19 11:53:08 +01:00
b_btree_node *first_node = b_btree_first(&it->_d_p->d_buckets);
2024-10-24 19:24:54 +01:00
struct b_dict_bucket *first_bucket
= b_unbox(struct b_dict_bucket, first_node, bk_node);
if (!first_bucket) {
2025-10-29 14:35:07 +00:00
it->item.key = NULL;
it->item.value = NULL;
b_iterator_set_status(it_obj, B_ERR_NO_DATA);
return it_obj;
2024-10-24 19:24:54 +01:00
}
b_queue_entry *first_entry = b_queue_first(&first_bucket->bk_items);
struct b_dict_bucket_item *first_item
= b_unbox(struct b_dict_bucket_item, first_entry, bi_entry);
if (!first_item) {
2025-10-29 14:35:07 +00:00
it->item.key = NULL;
it->item.value = NULL;
b_iterator_set_status(it_obj, B_ERR_NO_DATA);
return it_obj;
2024-10-24 19:24:54 +01:00
}
2025-10-29 14:35:07 +00:00
it->item.key = first_item->bi_str;
it->item.value = first_item->bi_value;
2024-10-24 19:24:54 +01:00
it->_cbn = first_node;
it->_cqe = first_entry;
2025-10-29 14:35:07 +00:00
return it_obj;
2024-10-24 19:24:54 +01:00
}
2025-10-29 14:35:07 +00:00
static enum b_status iterator_move_next(const b_iterator *obj)
2024-10-24 19:24:54 +01:00
{
2025-10-29 14:35:07 +00:00
struct b_dict_iterator_p *it
= b_object_get_private(obj, B_TYPE_DICT_ITERATOR);
2024-10-24 19:24:54 +01:00
struct b_btree_node *next_node;
struct b_queue_entry *next_entry;
if (!get_next_node(it->_cbn, it->_cqe, &next_node, &next_entry)) {
2025-10-29 14:35:07 +00:00
it->item.key = NULL;
it->item.value = NULL;
return B_ERR_NO_DATA;
2024-10-24 19:24:54 +01:00
}
struct b_dict_bucket_item *next_item
= b_unbox(struct b_dict_bucket_item, next_entry, bi_entry);
if (!next_item) {
2025-10-29 14:35:07 +00:00
it->item.key = NULL;
it->item.value = NULL;
return B_ERR_NO_DATA;
2024-10-24 19:24:54 +01:00
}
it->i++;
2025-10-29 14:35:07 +00:00
it->item.key = next_item->bi_str;
it->item.value = next_item->bi_value;
2024-10-24 19:24:54 +01:00
it->_cbn = next_node;
it->_cqe = next_entry;
2025-10-29 14:35:07 +00:00
return B_SUCCESS;
2024-10-24 19:24:54 +01:00
}
2025-10-29 14:35:07 +00:00
static enum b_status iterator_erase(b_iterator *obj)
2024-10-24 19:24:54 +01:00
{
2025-10-29 14:35:07 +00:00
struct b_dict_iterator_p *it
= b_object_get_private(obj, B_TYPE_DICT_ITERATOR);
if ((it->item.key || it->item.value) && !(it->_cbn && it->_cqe)) {
2024-10-24 19:24:54 +01:00
return B_ERR_BAD_STATE;
}
2025-10-29 14:35:07 +00:00
if (!it->item.key || !it->_cqe) {
return B_ERR_NO_DATA;
2024-10-24 19:24:54 +01:00
}
struct b_btree_node *next_node;
struct b_queue_entry *next_entry;
if (!get_next_node(it->_cbn, it->_cqe, &next_node, &next_entry)) {
2025-10-29 14:35:07 +00:00
it->item.key = NULL;
it->item.value = NULL;
return B_ERR_NO_DATA;
2024-10-24 19:24:54 +01:00
}
struct b_dict_bucket *cur_bucket
= b_unbox(struct b_dict_bucket, it->_cbn, bk_node);
struct b_dict_bucket_item *cur_item
= b_unbox(struct b_dict_bucket_item, it->_cqe, bi_entry);
struct b_dict_bucket_item *next_item
= b_unbox(struct b_dict_bucket_item, next_entry, bi_entry);
2025-10-19 11:53:08 +01:00
b_status status = delete_item(it->_d_p, cur_bucket, cur_item);
2024-10-24 19:24:54 +01:00
if (B_ERR(status)) {
return status;
}
if (next_item) {
2025-10-29 14:35:07 +00:00
it->item.key = next_item->bi_str;
it->item.value = next_item->bi_value;
2024-10-24 19:24:54 +01:00
it->_cbn = next_node;
it->_cqe = next_entry;
} else {
2025-10-29 14:35:07 +00:00
it->item.key = NULL;
it->item.value = NULL;
2024-10-24 19:24:54 +01:00
it->_cbn = NULL;
it->_cqe = NULL;
}
return B_SUCCESS;
}
2025-10-29 14:35:07 +00:00
static b_iterator_value iterator_get_value(b_iterator *obj)
2024-10-24 19:24:54 +01:00
{
2025-10-29 14:35:07 +00:00
struct b_dict_iterator_p *it
= b_object_get_private(obj, B_TYPE_DICT_ITERATOR);
return B_ITERATOR_VALUE_PTR(&it->item);
}
static const b_iterator_value iterator_get_cvalue(const b_iterator *obj)
{
struct b_dict_iterator_p *it
= b_object_get_private(obj, B_TYPE_DICT_ITERATOR);
return B_ITERATOR_VALUE_CPTR(&it->item);
2024-10-24 19:24:54 +01:00
}
2025-10-29 14:35:07 +00:00
/*** CLASS DEFINITION *********************************************************/
// ---- b_dict DEFINITION
B_TYPE_CLASS_DEFINITION_BEGIN(b_dict)
B_TYPE_CLASS_INTERFACE_BEGIN(b_object, B_TYPE_OBJECT)
B_INTERFACE_ENTRY(to_string) = dict_to_string;
B_TYPE_CLASS_INTERFACE_END(b_object, B_TYPE_OBJECT)
B_TYPE_CLASS_INTERFACE_BEGIN(b_iterable, B_TYPE_ITERABLE)
B_INTERFACE_ENTRY(it_begin) = iterable_begin;
B_INTERFACE_ENTRY(it_cbegin) = iterable_cbegin;
B_TYPE_CLASS_INTERFACE_END(b_iterable, B_TYPE_ITERABLE)
B_TYPE_CLASS_DEFINITION_END(b_dict)
B_TYPE_DEFINITION_BEGIN(b_dict)
B_TYPE_ID(0xd2af61d9, 0xd0be, 0x4960, 0xbe3f, 0x509749814c10);
B_TYPE_CLASS(b_dict_class);
B_TYPE_IMPLEMENTS(B_TYPE_ITERABLE);
B_TYPE_INSTANCE_PRIVATE(struct b_dict_p);
B_TYPE_INSTANCE_INIT(dict_init);
B_TYPE_INSTANCE_FINI(dict_fini);
B_TYPE_DEFINITION_END(b_dict)
// ---- b_dict_iterator DEFINITION
B_TYPE_CLASS_DEFINITION_BEGIN(b_dict_iterator)
B_TYPE_CLASS_INTERFACE_BEGIN(b_object, B_TYPE_OBJECT)
B_INTERFACE_ENTRY(to_string) = NULL;
B_TYPE_CLASS_INTERFACE_END(b_object, B_TYPE_OBJECT)
B_TYPE_CLASS_INTERFACE_BEGIN(b_iterator, B_TYPE_ITERATOR)
B_INTERFACE_ENTRY(it_move_next) = iterator_move_next;
B_INTERFACE_ENTRY(it_erase) = iterator_erase;
B_INTERFACE_ENTRY(it_get_value) = iterator_get_value;
B_INTERFACE_ENTRY(it_get_cvalue) = iterator_get_cvalue;
B_TYPE_CLASS_INTERFACE_END(b_iterator, B_TYPE_ITERATOR)
B_TYPE_CLASS_DEFINITION_END(b_dict_iterator)
B_TYPE_DEFINITION_BEGIN(b_dict_iterator)
B_TYPE_ID(0x9ea96701, 0x1713, 0x4a3e, 0xbf63, 0xdc856b456f3b);
B_TYPE_EXTENDS(B_TYPE_ITERATOR);
B_TYPE_CLASS(b_dict_iterator_class);
B_TYPE_INSTANCE_PRIVATE(struct b_dict_iterator_p);
B_TYPE_DEFINITION_END(b_dict_iterator)