meta: rename to fx

This commit is contained in:
2026-03-16 10:35:43 +00:00
parent 84df46489a
commit e9d0e323f0
233 changed files with 12875 additions and 12869 deletions

538
ds/dict.c
View File

@@ -1,7 +1,7 @@
#include <blue/core/status.h>
#include <blue/core/stream.h>
#include <blue/ds/dict.h>
#include <blue/ds/string.h>
#include <fx/core/status.h>
#include <fx/core/stream.h>
#include <fx/ds/dict.h>
#include <fx/ds/string.h>
#include <stdbool.h>
#include <stdlib.h>
@@ -10,40 +10,40 @@
/*** PRIVATE DATA *************************************************************/
struct b_dict_bucket_item {
b_queue_entry bi_entry;
b_string *bi_str;
b_object *bi_value;
struct fx_dict_bucket_item {
fx_queue_entry bi_entry;
fx_string *bi_str;
fx_object *bi_value;
};
struct b_dict_bucket {
b_btree_node bk_node;
struct fx_dict_bucket {
fx_bst_node bk_node;
uint64_t bk_hash;
b_queue bk_items;
fx_queue bk_items;
};
struct b_dict_p {
b_btree d_buckets;
struct fx_dict_p {
fx_bst d_buckets;
};
struct b_dict_iterator_p {
struct fx_dict_iterator_p {
size_t i;
b_dict_item item;
fx_dict_item item;
b_dict *_d;
struct b_dict_p *_d_p;
b_btree_node *_cbn;
b_queue_entry *_cqe;
fx_dict *_d;
struct fx_dict_p *_d_p;
fx_bst_node *_cbn;
fx_queue_entry *_cqe;
};
/*** MISC FUNCTIONS ***********************************************************/
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);
static FX_BTREE_DEFINE_SIMPLE_GET(
struct fx_dict_bucket, uint64_t, bk_node, bk_hash, get_bucket);
static FX_BTREE_DEFINE_SIMPLE_INSERT(
struct fx_dict_bucket, bk_node, bk_hash, put_bucket);
uint64_t b_cstr_hash(const char *s)
uint64_t fx_cstr_hash(const char *s)
{
uint64_t hash = HASH_OFFSET_BASIS;
@@ -57,9 +57,9 @@ uint64_t b_cstr_hash(const char *s)
/*** PRIVATE FUNCTIONS ********************************************************/
static struct b_dict_bucket *create_bucket(void)
static struct fx_dict_bucket *create_bucket(void)
{
struct b_dict_bucket *bucket = malloc(sizeof *bucket);
struct fx_dict_bucket *bucket = malloc(sizeof *bucket);
if (!bucket) {
return NULL;
}
@@ -68,9 +68,9 @@ static struct b_dict_bucket *create_bucket(void)
return bucket;
}
static struct b_dict_bucket_item *create_bucket_item(void)
static struct fx_dict_bucket_item *create_bucket_item(void)
{
struct b_dict_bucket_item *item = malloc(sizeof *item);
struct fx_dict_bucket_item *item = malloc(sizeof *item);
if (!item) {
return NULL;
}
@@ -79,149 +79,149 @@ static struct b_dict_bucket_item *create_bucket_item(void)
return item;
}
static b_status dict_put(struct b_dict_p *dict, const char *key, b_object *value)
static fx_status dict_put(struct fx_dict_p *dict, const char *key, fx_object *value)
{
uint64_t hash = b_cstr_hash(key);
struct b_dict_bucket *bucket = get_bucket(&dict->d_buckets, hash);
uint64_t hash = fx_cstr_hash(key);
struct fx_dict_bucket *bucket = get_bucket(&dict->d_buckets, hash);
if (!bucket) {
bucket = create_bucket();
if (!bucket) {
return B_ERR_NO_MEMORY;
return FX_ERR_NO_MEMORY;
}
bucket->bk_hash = hash;
put_bucket(&dict->d_buckets, bucket);
}
struct b_dict_bucket_item *item = create_bucket_item();
struct fx_dict_bucket_item *item = create_bucket_item();
if (!item) {
return B_ERR_NO_MEMORY;
return FX_ERR_NO_MEMORY;
}
item->bi_str = b_string_create_from_cstr(key);
item->bi_value = b_object_ref(value);
item->bi_str = fx_string_create_from_cstr(key);
item->bi_value = fx_object_ref(value);
b_queue_push_back(&bucket->bk_items, &item->bi_entry);
fx_queue_push_back(&bucket->bk_items, &item->bi_entry);
return B_SUCCESS;
return FX_SUCCESS;
}
static b_status dict_put_sk(
struct b_dict_p *dict, const b_string *key, b_object *value)
static fx_status dict_put_sk(
struct fx_dict_p *dict, const fx_string *key, fx_object *value)
{
uint64_t hash = b_string_hash(key);
struct b_dict_bucket *bucket = get_bucket(&dict->d_buckets, hash);
uint64_t hash = fx_string_hash(key);
struct fx_dict_bucket *bucket = get_bucket(&dict->d_buckets, hash);
if (!bucket) {
bucket = create_bucket();
if (!bucket) {
return B_ERR_NO_MEMORY;
return FX_ERR_NO_MEMORY;
}
bucket->bk_hash = hash;
put_bucket(&dict->d_buckets, bucket);
}
struct b_dict_bucket_item *item = create_bucket_item();
struct fx_dict_bucket_item *item = create_bucket_item();
if (!item) {
return B_ERR_NO_MEMORY;
return FX_ERR_NO_MEMORY;
}
item->bi_str = b_string_duplicate(key);
item->bi_value = b_object_ref(value);
item->bi_str = fx_string_duplicate(key);
item->bi_value = fx_object_ref(value);
b_queue_push_back(&bucket->bk_items, &item->bi_entry);
fx_queue_push_back(&bucket->bk_items, &item->bi_entry);
return B_SUCCESS;
return FX_SUCCESS;
}
static b_object *dict_at(const struct b_dict_p *dict, const char *key)
static fx_object *dict_at(const struct fx_dict_p *dict, const char *key)
{
uint64_t hash = b_cstr_hash(key);
struct b_dict_bucket *bucket = get_bucket(&dict->d_buckets, hash);
uint64_t hash = fx_cstr_hash(key);
struct fx_dict_bucket *bucket = get_bucket(&dict->d_buckets, hash);
if (!bucket) {
return NULL;
}
struct b_queue_entry *entry = b_queue_first(&bucket->bk_items);
struct fx_queue_entry *entry = fx_queue_first(&bucket->bk_items);
while (entry) {
struct b_dict_bucket_item *item
= b_unbox(struct b_dict_bucket_item, entry, bi_entry);
struct fx_dict_bucket_item *item
= fx_unbox(struct fx_dict_bucket_item, entry, bi_entry);
if (!strcmp(b_string_ptr(item->bi_str), key)) {
if (!strcmp(fx_string_ptr(item->bi_str), key)) {
return item->bi_value;
}
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
return NULL;
}
static b_object *dict_at_sk(const struct b_dict_p *dict, const b_string *key)
static fx_object *dict_at_sk(const struct fx_dict_p *dict, const fx_string *key)
{
uint64_t hash = b_string_hash(key);
struct b_dict_bucket *bucket = get_bucket(&dict->d_buckets, hash);
uint64_t hash = fx_string_hash(key);
struct fx_dict_bucket *bucket = get_bucket(&dict->d_buckets, hash);
if (!bucket) {
return NULL;
}
struct b_queue_entry *entry = b_queue_first(&bucket->bk_items);
struct fx_queue_entry *entry = fx_queue_first(&bucket->bk_items);
while (entry) {
struct b_dict_bucket_item *item
= b_unbox(struct b_dict_bucket_item, entry, bi_entry);
struct fx_dict_bucket_item *item
= fx_unbox(struct fx_dict_bucket_item, entry, bi_entry);
if (b_string_compare(item->bi_str, key)) {
if (fx_string_compare(item->bi_str, key)) {
return item->bi_value;
}
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
return NULL;
}
static b_object *dict_get(struct b_dict_p *dict, const char *key)
static fx_object *dict_get(struct fx_dict_p *dict, const char *key)
{
b_object *value = dict_at(dict, key);
fx_object *value = dict_at(dict, key);
if (value) {
b_object_ref(value);
fx_object_ref(value);
}
return value;
}
static b_object *dict_get_sk(struct b_dict_p *dict, const b_string *key)
static fx_object *dict_get_sk(struct fx_dict_p *dict, const fx_string *key)
{
b_object *value = dict_at_sk(dict, key);
fx_object *value = dict_at_sk(dict, key);
if (value) {
b_object_ref(value);
fx_object_ref(value);
}
return value;
}
static bool dict_has_key(const struct b_dict_p *dict, const char *key)
static bool dict_has_key(const struct fx_dict_p *dict, const char *key)
{
return dict_at(dict, key) != NULL;
}
static bool dict_has_skey(const struct b_dict_p *dict, const b_string *key)
static bool dict_has_skey(const struct fx_dict_p *dict, const fx_string *key)
{
return dict_at_sk(dict, key) != NULL;
}
static size_t dict_get_size(const struct b_dict_p *dict)
static size_t dict_get_size(const struct fx_dict_p *dict)
{
size_t count = 0;
#if 0
b_btree_iterator it1;
b_queue_iterator it2;
fx_bst_iterator it1;
fx_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);
fx_bst_foreach (&it1, &dict->d_buckets) {
struct fx_dict_bucket *bucket
= fx_unbox(struct fx_dict_bucket, it1.node, bk_node);
b_queue_foreach (&it2, &bucket->bk_items) {
fx_queue_foreach (&it2, &bucket->bk_items) {
count++;
}
}
@@ -230,18 +230,18 @@ static size_t dict_get_size(const struct b_dict_p *dict)
return count;
}
static bool dict_is_empty(const struct b_dict_p *dict)
static bool dict_is_empty(const struct fx_dict_p *dict)
{
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);
fx_bst_node *first_node = fx_bst_first(&dict->d_buckets);
struct fx_dict_bucket *first_bucket
= fx_unbox(struct fx_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);
fx_queue_entry *first_entry = fx_queue_first(&first_bucket->bk_items);
struct fx_dict_bucket_item *first_item
= fx_unbox(struct fx_dict_bucket_item, first_entry, bi_entry);
if (!first_item) {
return true;
}
@@ -250,43 +250,43 @@ static bool dict_is_empty(const struct b_dict_p *dict)
}
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 fx_bst_node *cur_node, struct fx_queue_entry *cur_entry,
struct fx_bst_node **out_next_node, struct fx_queue_entry **out_next_entry)
{
struct b_dict_bucket *cur_bucket
= b_unbox(struct b_dict_bucket, cur_node, bk_node);
struct fx_dict_bucket *cur_bucket
= fx_unbox(struct fx_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);
struct fx_dict_bucket_item *cur_item
= fx_unbox(struct fx_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);
struct fx_bst_node *next_node = cur_node;
struct fx_queue_entry *next_entry = fx_queue_next(cur_entry);
if (!next_entry) {
next_node = b_btree_next(cur_node);
next_node = fx_bst_next(cur_node);
if (!next_node) {
return false;
}
struct b_dict_bucket *next_bucket
= b_unbox(struct b_dict_bucket, next_node, bk_node);
struct fx_dict_bucket *next_bucket
= fx_unbox(struct fx_dict_bucket, next_node, bk_node);
if (!next_bucket) {
return false;
}
next_entry = b_queue_first(&next_bucket->bk_items);
next_entry = fx_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);
struct fx_dict_bucket_item *next_item
= fx_unbox(struct fx_dict_bucket_item, next_entry, bi_entry);
if (!next_item) {
return false;
}
@@ -297,32 +297,32 @@ static bool get_next_node(
return true;
}
static b_status delete_item(
struct b_dict_p *dict, struct b_dict_bucket *bucket,
struct b_dict_bucket_item *item)
static fx_status delete_item(
struct fx_dict_p *dict, struct fx_dict_bucket *bucket,
struct fx_dict_bucket_item *item)
{
b_queue_delete(&bucket->bk_items, &item->bi_entry);
fx_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);
if (fx_queue_empty(&bucket->bk_items)) {
fx_bst_delete(&dict->d_buckets, &bucket->bk_node);
free(bucket);
}
return B_SUCCESS;
return FX_SUCCESS;
}
/*** PUBLIC FUNCTIONS *********************************************************/
#if 0
b_dict *b_dict_create_with_items(const b_dict_item *items)
fx_dict *fx_dict_create_with_items(const fx_dict_item *items)
{
b_dict *dict = b_dict_create();
fx_dict *dict = fx_dict_create();
if (!dict) {
return NULL;
}
struct b_dict_p *p = b_object_get_private(dict, B_TYPE_DICT);
struct fx_dict_p *p = fx_object_get_private(dict, FX_TYPE_DICT);
for (size_t i = 0; items[i].key; i++) {
dict_put(p, items[i].key, items[i].value);
@@ -332,84 +332,84 @@ b_dict *b_dict_create_with_items(const b_dict_item *items)
}
#endif
b_status b_dict_put(b_dict *dict, const char *key, b_object *value)
fx_status fx_dict_put(fx_dict *dict, const char *key, fx_object *value)
{
B_CLASS_DISPATCH_STATIC(B_TYPE_DICT, dict_put, dict, key, value);
FX_CLASS_DISPATCH_STATIC(FX_TYPE_DICT, dict_put, dict, key, value);
}
b_status b_dict_put_sk(b_dict *dict, const b_string *key, b_object *value)
fx_status fx_dict_put_sk(fx_dict *dict, const fx_string *key, fx_object *value)
{
B_CLASS_DISPATCH_STATIC(B_TYPE_DICT, dict_put_sk, dict, key, value);
FX_CLASS_DISPATCH_STATIC(FX_TYPE_DICT, dict_put_sk, dict, key, value);
}
b_object *b_dict_at(const b_dict *dict, const char *key)
fx_object *fx_dict_at(const fx_dict *dict, const char *key)
{
B_CLASS_DISPATCH_STATIC(B_TYPE_DICT, dict_at, dict, key);
FX_CLASS_DISPATCH_STATIC(FX_TYPE_DICT, dict_at, dict, key);
}
b_object *b_dict_at_sk(const b_dict *dict, const b_string *key)
fx_object *fx_dict_at_sk(const fx_dict *dict, const fx_string *key)
{
B_CLASS_DISPATCH_STATIC(B_TYPE_DICT, dict_at_sk, dict, key);
FX_CLASS_DISPATCH_STATIC(FX_TYPE_DICT, dict_at_sk, dict, key);
}
b_object *b_dict_get(b_dict *dict, const char *key)
fx_object *fx_dict_get(fx_dict *dict, const char *key)
{
B_CLASS_DISPATCH_STATIC(B_TYPE_DICT, dict_get, dict, key);
FX_CLASS_DISPATCH_STATIC(FX_TYPE_DICT, dict_get, dict, key);
}
b_object *b_dict_get_sk(b_dict *dict, const b_string *key)
fx_object *fx_dict_get_sk(fx_dict *dict, const fx_string *key)
{
B_CLASS_DISPATCH_STATIC(B_TYPE_DICT, dict_get_sk, dict, key);
FX_CLASS_DISPATCH_STATIC(FX_TYPE_DICT, dict_get_sk, dict, key);
}
bool b_dict_has_key(const b_dict *dict, const char *key)
bool fx_dict_has_key(const fx_dict *dict, const char *key)
{
B_CLASS_DISPATCH_STATIC(B_TYPE_DICT, dict_has_key, dict, key);
FX_CLASS_DISPATCH_STATIC(FX_TYPE_DICT, dict_has_key, dict, key);
}
bool b_dict_has_skey(const b_dict *dict, const b_string *key)
bool fx_dict_has_skey(const fx_dict *dict, const fx_string *key)
{
B_CLASS_DISPATCH_STATIC(B_TYPE_DICT, dict_has_skey, dict, key);
FX_CLASS_DISPATCH_STATIC(FX_TYPE_DICT, dict_has_skey, dict, key);
}
size_t b_dict_get_size(const b_dict *dict)
size_t fx_dict_get_size(const fx_dict *dict)
{
B_CLASS_DISPATCH_STATIC_0(B_TYPE_DICT, dict_get_size, dict);
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_DICT, dict_get_size, dict);
}
bool b_dict_is_empty(const b_dict *dict)
bool fx_dict_is_empty(const fx_dict *dict)
{
B_CLASS_DISPATCH_STATIC_0(B_TYPE_DICT, dict_is_empty, dict);
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_DICT, dict_is_empty, dict);
}
/*** PUBLIC ALIAS FUNCTIONS ***************************************************/
/*** VIRTUAL FUNCTIONS ********************************************************/
static void dict_init(b_object *obj, void *priv)
static void dict_init(fx_object *obj, void *priv)
{
struct b_dict_p *dict = priv;
struct fx_dict_p *dict = priv;
}
static void dict_fini(b_object *obj, void *priv)
static void dict_fini(fx_object *obj, void *priv)
{
struct b_dict_p *dict = priv;
struct fx_dict_p *dict = priv;
struct b_btree_node *node = b_btree_first(&dict->d_buckets);
struct fx_bst_node *node = fx_bst_first(&dict->d_buckets);
while (node) {
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);
struct fx_dict_bucket *bucket
= fx_unbox(struct fx_dict_bucket, node, bk_node);
struct fx_bst_node *next_node = fx_bst_next(node);
fx_bst_delete(&dict->d_buckets, node);
struct b_queue_entry *entry = b_queue_first(&bucket->bk_items);
struct fx_queue_entry *entry = fx_queue_first(&bucket->bk_items);
while (entry) {
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);
struct fx_dict_bucket_item *item = fx_unbox(
struct fx_dict_bucket_item, entry, bi_entry);
struct fx_queue_entry *next_entry = fx_queue_next(entry);
fx_queue_delete(&bucket->bk_items, entry);
free(item->bi_str);
b_object_unref(item->bi_value);
fx_object_unref(item->bi_value);
free(item);
entry = next_entry;
@@ -420,102 +420,102 @@ static void dict_fini(b_object *obj, void *priv)
}
}
static void dict_to_string(const b_object *obj, b_stream *out)
static void dict_to_string(const fx_object *obj, fx_stream *out)
{
struct b_dict_p *dict = b_object_get_private(obj, B_TYPE_DICT);
struct fx_dict_p *dict = fx_object_get_private(obj, FX_TYPE_DICT);
if (dict_is_empty(dict)) {
b_stream_write_string(out, "{}", NULL);
fx_stream_write_string(out, "{}", NULL);
return;
}
b_stream_write_string(out, "{\n", NULL);
fx_stream_write_string(out, "{\n", NULL);
b_stream_push_indent(out, 1);
fx_stream_push_indent(out, 1);
size_t len = dict_get_size(dict);
size_t i = 0;
struct b_btree_node *node = b_btree_first(&dict->d_buckets);
struct fx_bst_node *node = fx_bst_first(&dict->d_buckets);
while (node) {
struct b_dict_bucket *bucket
= b_unbox(struct b_dict_bucket, node, bk_node);
struct fx_dict_bucket *bucket
= fx_unbox(struct fx_dict_bucket, node, bk_node);
struct b_queue_entry *entry = b_queue_first(&bucket->bk_items);
struct fx_queue_entry *entry = fx_queue_first(&bucket->bk_items);
while (entry) {
struct b_dict_bucket_item *item = b_unbox(
struct b_dict_bucket_item, entry, bi_entry);
struct fx_dict_bucket_item *item = fx_unbox(
struct fx_dict_bucket_item, entry, bi_entry);
b_object_to_string(item->bi_str, out);
b_stream_write_string(out, ": ", NULL);
fx_object_to_string(item->bi_str, out);
fx_stream_write_string(out, ": ", NULL);
bool is_string
= b_object_is_type(item->bi_value, B_TYPE_STRING);
= fx_object_is_type(item->bi_value, FX_TYPE_STRING);
if (is_string) {
b_stream_write_char(out, '"');
fx_stream_write_char(out, '"');
}
b_object_to_string(item->bi_value, out);
fx_object_to_string(item->bi_value, out);
if (is_string) {
b_stream_write_char(out, '"');
fx_stream_write_char(out, '"');
}
if (i < len - 1) {
b_stream_write_string(out, ",", NULL);
fx_stream_write_string(out, ",", NULL);
}
b_stream_write_char(out, '\n');
entry = b_queue_next(entry);
fx_stream_write_char(out, '\n');
entry = fx_queue_next(entry);
i++;
}
node = b_btree_next(node);
node = fx_bst_next(node);
}
b_stream_pop_indent(out);
b_stream_write_char(out, '}');
fx_stream_pop_indent(out);
fx_stream_write_char(out, '}');
}
/*** ITERATOR FUNCTIONS *******************************************************/
static b_iterator *iterable_begin(b_dict *dict)
static fx_iterator *iterable_begin(fx_dict *dict)
{
b_iterator *it_obj = b_object_create(B_TYPE_DICT_ITERATOR);
fx_iterator *it_obj = fx_object_create(FX_TYPE_DICT_ITERATOR);
if (!it_obj) {
return NULL;
}
struct b_dict_iterator_p *it
= b_object_get_private(it_obj, B_TYPE_DICT_ITERATOR);
struct fx_dict_iterator_p *it
= fx_object_get_private(it_obj, FX_TYPE_DICT_ITERATOR);
it->i = 0;
it->_d = dict;
it->_d_p = b_object_get_private(dict, B_TYPE_DICT);
it->_d_p = fx_object_get_private(dict, FX_TYPE_DICT);
if (dict_is_empty(it->_d_p)) {
it->item.key = NULL;
it->item.value = NULL;
b_iterator_set_status(it_obj, B_ERR_NO_DATA);
fx_iterator_set_status(it_obj, FX_ERR_NO_DATA);
return it_obj;
}
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);
fx_bst_node *first_node = fx_bst_first(&it->_d_p->d_buckets);
struct fx_dict_bucket *first_bucket
= fx_unbox(struct fx_dict_bucket, first_node, bk_node);
if (!first_bucket) {
it->item.key = NULL;
it->item.value = NULL;
b_iterator_set_status(it_obj, B_ERR_NO_DATA);
fx_iterator_set_status(it_obj, FX_ERR_NO_DATA);
return it_obj;
}
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);
fx_queue_entry *first_entry = fx_queue_first(&first_bucket->bk_items);
struct fx_dict_bucket_item *first_item
= fx_unbox(struct fx_dict_bucket_item, first_entry, bi_entry);
if (!first_item) {
it->item.key = NULL;
it->item.value = NULL;
b_iterator_set_status(it_obj, B_ERR_NO_DATA);
fx_iterator_set_status(it_obj, FX_ERR_NO_DATA);
return it_obj;
}
@@ -529,44 +529,44 @@ static b_iterator *iterable_begin(b_dict *dict)
return it_obj;
}
static const b_iterator *iterable_cbegin(const b_dict *dict)
static const fx_iterator *iterable_cbegin(const fx_dict *dict)
{
b_iterator *it_obj = b_object_create(B_TYPE_DICT_ITERATOR);
fx_iterator *it_obj = fx_object_create(FX_TYPE_DICT_ITERATOR);
if (!it_obj) {
return NULL;
}
struct b_dict_iterator_p *it
= b_object_get_private(it_obj, B_TYPE_DICT_ITERATOR);
struct fx_dict_iterator_p *it
= fx_object_get_private(it_obj, FX_TYPE_DICT_ITERATOR);
it->i = 0;
it->_d = (b_dict *)dict;
it->_d_p = b_object_get_private(dict, B_TYPE_DICT);
it->_d = (fx_dict *)dict;
it->_d_p = fx_object_get_private(dict, FX_TYPE_DICT);
if (dict_is_empty(it->_d_p)) {
it->item.key = NULL;
it->item.value = NULL;
b_iterator_set_status(it_obj, B_ERR_NO_DATA);
fx_iterator_set_status(it_obj, FX_ERR_NO_DATA);
return it_obj;
}
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);
fx_bst_node *first_node = fx_bst_first(&it->_d_p->d_buckets);
struct fx_dict_bucket *first_bucket
= fx_unbox(struct fx_dict_bucket, first_node, bk_node);
if (!first_bucket) {
it->item.key = NULL;
it->item.value = NULL;
b_iterator_set_status(it_obj, B_ERR_NO_DATA);
fx_iterator_set_status(it_obj, FX_ERR_NO_DATA);
return it_obj;
}
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);
fx_queue_entry *first_entry = fx_queue_first(&first_bucket->bk_items);
struct fx_dict_bucket_item *first_item
= fx_unbox(struct fx_dict_bucket_item, first_entry, bi_entry);
if (!first_item) {
it->item.key = NULL;
it->item.value = NULL;
b_iterator_set_status(it_obj, B_ERR_NO_DATA);
fx_iterator_set_status(it_obj, FX_ERR_NO_DATA);
return it_obj;
}
@@ -579,26 +579,26 @@ static const b_iterator *iterable_cbegin(const b_dict *dict)
return it_obj;
}
static enum b_status iterator_move_next(const b_iterator *obj)
static enum fx_status iterator_move_next(const fx_iterator *obj)
{
struct b_dict_iterator_p *it
= b_object_get_private(obj, B_TYPE_DICT_ITERATOR);
struct fx_dict_iterator_p *it
= fx_object_get_private(obj, FX_TYPE_DICT_ITERATOR);
struct b_btree_node *next_node;
struct b_queue_entry *next_entry;
struct fx_bst_node *next_node;
struct fx_queue_entry *next_entry;
if (!get_next_node(it->_cbn, it->_cqe, &next_node, &next_entry)) {
it->item.key = NULL;
it->item.value = NULL;
return B_ERR_NO_DATA;
return FX_ERR_NO_DATA;
}
struct b_dict_bucket_item *next_item
= b_unbox(struct b_dict_bucket_item, next_entry, bi_entry);
struct fx_dict_bucket_item *next_item
= fx_unbox(struct fx_dict_bucket_item, next_entry, bi_entry);
if (!next_item) {
it->item.key = NULL;
it->item.value = NULL;
return B_ERR_NO_DATA;
return FX_ERR_NO_DATA;
}
it->i++;
@@ -608,40 +608,40 @@ static enum b_status iterator_move_next(const b_iterator *obj)
it->_cbn = next_node;
it->_cqe = next_entry;
return B_SUCCESS;
return FX_SUCCESS;
}
static enum b_status iterator_erase(b_iterator *obj)
static enum fx_status iterator_erase(fx_iterator *obj)
{
struct b_dict_iterator_p *it
= b_object_get_private(obj, B_TYPE_DICT_ITERATOR);
struct fx_dict_iterator_p *it
= fx_object_get_private(obj, FX_TYPE_DICT_ITERATOR);
if ((it->item.key || it->item.value) && !(it->_cbn && it->_cqe)) {
return B_ERR_BAD_STATE;
return FX_ERR_BAD_STATE;
}
if (!it->item.key || !it->_cqe) {
return B_ERR_NO_DATA;
return FX_ERR_NO_DATA;
}
struct b_btree_node *next_node;
struct b_queue_entry *next_entry;
struct fx_bst_node *next_node;
struct fx_queue_entry *next_entry;
if (!get_next_node(it->_cbn, it->_cqe, &next_node, &next_entry)) {
it->item.key = NULL;
it->item.value = NULL;
return B_ERR_NO_DATA;
return FX_ERR_NO_DATA;
}
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 fx_dict_bucket *cur_bucket
= fx_unbox(struct fx_dict_bucket, it->_cbn, bk_node);
struct fx_dict_bucket_item *cur_item
= fx_unbox(struct fx_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);
struct fx_dict_bucket_item *next_item
= fx_unbox(struct fx_dict_bucket_item, next_entry, bi_entry);
b_status status = delete_item(it->_d_p, cur_bucket, cur_item);
if (B_ERR(status)) {
fx_status status = delete_item(it->_d_p, cur_bucket, cur_item);
if (FX_ERR(status)) {
return status;
}
@@ -659,65 +659,65 @@ static enum b_status iterator_erase(b_iterator *obj)
it->_cqe = NULL;
}
return B_SUCCESS;
return FX_SUCCESS;
}
static b_iterator_value iterator_get_value(b_iterator *obj)
static fx_iterator_value iterator_get_value(fx_iterator *obj)
{
struct b_dict_iterator_p *it
= b_object_get_private(obj, B_TYPE_DICT_ITERATOR);
struct fx_dict_iterator_p *it
= fx_object_get_private(obj, FX_TYPE_DICT_ITERATOR);
return B_ITERATOR_VALUE_PTR(&it->item);
return FX_ITERATOR_VALUE_PTR(&it->item);
}
static const b_iterator_value iterator_get_cvalue(const b_iterator *obj)
static const fx_iterator_value iterator_get_cvalue(const fx_iterator *obj)
{
struct b_dict_iterator_p *it
= b_object_get_private(obj, B_TYPE_DICT_ITERATOR);
struct fx_dict_iterator_p *it
= fx_object_get_private(obj, FX_TYPE_DICT_ITERATOR);
return B_ITERATOR_VALUE_CPTR(&it->item);
return FX_ITERATOR_VALUE_CPTR(&it->item);
}
/*** 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)
// ---- fx_dict DEFINITION
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_dict)
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
FX_INTERFACE_ENTRY(to_string) = dict_to_string;
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_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)
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_iterable, FX_TYPE_ITERABLE)
FX_INTERFACE_ENTRY(it_begin) = iterable_begin;
FX_INTERFACE_ENTRY(it_cbegin) = iterable_cbegin;
FX_TYPE_CLASS_INTERFACE_END(fx_iterable, FX_TYPE_ITERABLE)
FX_TYPE_CLASS_DEFINITION_END(fx_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)
FX_TYPE_DEFINITION_BEGIN(fx_dict)
FX_TYPE_ID(0xd2af61d9, 0xd0be, 0x4960, 0xbe3f, 0x509749814c10);
FX_TYPE_CLASS(fx_dict_class);
FX_TYPE_IMPLEMENTS(FX_TYPE_ITERABLE);
FX_TYPE_INSTANCE_PRIVATE(struct fx_dict_p);
FX_TYPE_INSTANCE_INIT(dict_init);
FX_TYPE_INSTANCE_FINI(dict_fini);
FX_TYPE_DEFINITION_END(fx_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)
// ---- fx_dict_iterator DEFINITION
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_dict_iterator)
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
FX_INTERFACE_ENTRY(to_string) = NULL;
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_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)
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_iterator, FX_TYPE_ITERATOR)
FX_INTERFACE_ENTRY(it_move_next) = iterator_move_next;
FX_INTERFACE_ENTRY(it_erase) = iterator_erase;
FX_INTERFACE_ENTRY(it_get_value) = iterator_get_value;
FX_INTERFACE_ENTRY(it_get_cvalue) = iterator_get_cvalue;
FX_TYPE_CLASS_INTERFACE_END(fx_iterator, FX_TYPE_ITERATOR)
FX_TYPE_CLASS_DEFINITION_END(fx_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)
FX_TYPE_DEFINITION_BEGIN(fx_dict_iterator)
FX_TYPE_ID(0x9ea96701, 0x1713, 0x4a3e, 0xbf63, 0xdc856b456f3b);
FX_TYPE_EXTENDS(FX_TYPE_ITERATOR);
FX_TYPE_CLASS(fx_dict_iterator_class);
FX_TYPE_INSTANCE_PRIVATE(struct fx_dict_iterator_p);
FX_TYPE_DEFINITION_END(fx_dict_iterator)