fx.collections: remove fx_tree
This commit is contained in:
@@ -1,58 +0,0 @@
|
|||||||
#ifndef FX_DS_TREE_H_
|
|
||||||
#define FX_DS_TREE_H_
|
|
||||||
|
|
||||||
#include <fx/macros.h>
|
|
||||||
#include <fx/misc.h>
|
|
||||||
#include <fx/queue.h>
|
|
||||||
#include <fx/string.h>
|
|
||||||
|
|
||||||
FX_DECLS_BEGIN;
|
|
||||||
|
|
||||||
#define FX_TYPE_TREE (fx_tree_get_type())
|
|
||||||
#define FX_TYPE_TREE_ITERATOR (fx_tree_iterator_get_type())
|
|
||||||
|
|
||||||
FX_DECLARE_TYPE(fx_tree);
|
|
||||||
FX_DECLARE_TYPE(fx_tree_iterator);
|
|
||||||
|
|
||||||
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_tree)
|
|
||||||
FX_TYPE_CLASS_DECLARATION_END(fx_tree)
|
|
||||||
|
|
||||||
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_tree_iterator)
|
|
||||||
FX_TYPE_CLASS_DECLARATION_END(fx_tree_iterator)
|
|
||||||
|
|
||||||
#define FX_TREE_NODE_INIT ((fx_tree_node) {0})
|
|
||||||
|
|
||||||
#define FX_TREE_CONTAINER(t, m, v) \
|
|
||||||
((void *)((v) ? (uintptr_t)(v) - (offsetof(t, m)) : 0))
|
|
||||||
|
|
||||||
typedef struct fx_tree_node {
|
|
||||||
struct fx_tree_node *__p01, *__p02, *__p03;
|
|
||||||
struct fx_queue_entry __q01;
|
|
||||||
} fx_tree_node;
|
|
||||||
|
|
||||||
FX_API fx_type_id fx_tree_get_type(void);
|
|
||||||
FX_API fx_type_id fx_tree_iterator_get_type(void);
|
|
||||||
|
|
||||||
FX_TYPE_DEFAULT_CONSTRUCTOR(fx_tree, FX_TYPE_TREE);
|
|
||||||
|
|
||||||
FX_API void fx_tree_set_root(fx_tree *tree, struct fx_tree_node *node);
|
|
||||||
|
|
||||||
FX_API void fx_tree_node_add_child(fx_tree_node *parent, fx_tree_node *child);
|
|
||||||
FX_API void fx_tree_node_add_sibling(fx_tree_node *node, fx_tree_node *to_add);
|
|
||||||
|
|
||||||
FX_API fx_tree_node *fx_tree_node_get_child(fx_tree_node *node, size_t at);
|
|
||||||
FX_API fx_tree_node *fx_tree_node_get_parent(fx_tree_node *node);
|
|
||||||
|
|
||||||
FX_API fx_iterator *fx_tree_begin(fx_tree *tree);
|
|
||||||
FX_API const fx_iterator *fx_tree_cbegin(const fx_tree *tree);
|
|
||||||
|
|
||||||
FX_API fx_iterator *fx_tree_node_begin(fx_tree_node *node);
|
|
||||||
FX_API const fx_iterator *fx_tree_node_cbegin(const fx_tree_node *node);
|
|
||||||
|
|
||||||
FX_API fx_iterator *fx_tree_node_begin_recursive(fx_tree_node *node);
|
|
||||||
FX_API const fx_iterator *fx_tree_node_cbegin_recursive(
|
|
||||||
const fx_tree_node *node);
|
|
||||||
|
|
||||||
FX_DECLS_END;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,128 +0,0 @@
|
|||||||
#include <fx/bst.h>
|
|
||||||
#include <fx/collections/dict.h>
|
|
||||||
#include <fx/collections/tree.h>
|
|
||||||
#include <fx/int.h>
|
|
||||||
#include <fx/iterator.h>
|
|
||||||
#include <inttypes.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#define NITEMS 16
|
|
||||||
|
|
||||||
struct tree_item {
|
|
||||||
int value;
|
|
||||||
fx_tree_node node;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct bst_item {
|
|
||||||
int value;
|
|
||||||
fx_bst_node node;
|
|
||||||
};
|
|
||||||
|
|
||||||
FX_BST_DEFINE_SIMPLE_GET(struct bst_item, int, node, value, get_node)
|
|
||||||
FX_BST_DEFINE_SIMPLE_INSERT(struct bst_item, node, value, put_node)
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
fx_dict *dict = fx_dict_create();
|
|
||||||
fx_dict_put(dict, "hello", fx_int_create(32));
|
|
||||||
fx_dict_put(dict, "world", fx_int_create(64));
|
|
||||||
fx_dict_put(dict, "more", fx_int_create(128));
|
|
||||||
fx_dict_put(dict, "other", fx_int_create(256));
|
|
||||||
|
|
||||||
fx_iterator *it = fx_iterator_begin(dict);
|
|
||||||
|
|
||||||
size_t i = 0;
|
|
||||||
fx_foreach(fx_dict_item *, item, it)
|
|
||||||
{
|
|
||||||
printf("item %zu: %s=%" PRIdPTR "\n",
|
|
||||||
i++,
|
|
||||||
fx_string_get_cstr(item->key),
|
|
||||||
fx_int_get_value(item->value));
|
|
||||||
}
|
|
||||||
|
|
||||||
fx_iterator_unref(it);
|
|
||||||
|
|
||||||
fx_tree *tree = fx_tree_create();
|
|
||||||
struct tree_item items2[NITEMS];
|
|
||||||
|
|
||||||
for (int i = 0; i < NITEMS; i++) {
|
|
||||||
items2[i].value = i;
|
|
||||||
items2[i].node = FX_TREE_NODE_INIT;
|
|
||||||
}
|
|
||||||
|
|
||||||
fx_tree_set_root(tree, &items2[0].node);
|
|
||||||
|
|
||||||
fx_tree_node_add_child(&items2[0].node, &items2[1].node);
|
|
||||||
fx_tree_node_add_child(&items2[0].node, &items2[2].node);
|
|
||||||
fx_tree_node_add_child(&items2[0].node, &items2[3].node);
|
|
||||||
fx_tree_node_add_child(&items2[0].node, &items2[7].node);
|
|
||||||
fx_tree_node_add_child(&items2[1].node, &items2[4].node);
|
|
||||||
fx_tree_node_add_child(&items2[1].node, &items2[5].node);
|
|
||||||
fx_tree_node_add_child(&items2[4].node, &items2[6].node);
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
it = fx_iterator_begin(tree);
|
|
||||||
fx_tree_iterator it2;
|
|
||||||
fx_tree_foreach(&it2, tree)
|
|
||||||
{
|
|
||||||
struct tree_item *item = fx_unbox(struct tree_item, it2.node, node);
|
|
||||||
|
|
||||||
for (size_t i = 0; i < it2.depth; i++) {
|
|
||||||
fputs(" ", stdout);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("%u\n", item->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
fx_bst bst = {0};
|
|
||||||
struct bst_item items3[NITEMS] = {0};
|
|
||||||
for (int i = 0; i < NITEMS; i++) {
|
|
||||||
items3[i].value = i;
|
|
||||||
put_node(&bst, &items3[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("\n\n");
|
|
||||||
|
|
||||||
fx_bst_iterator it3;
|
|
||||||
fx_bst_foreach (&it3, &bst) {
|
|
||||||
struct bst_item *item
|
|
||||||
= fx_unbox(struct bst_item, it3.node, node);
|
|
||||||
|
|
||||||
for (size_t i = 0; i < it3.depth; i++) {
|
|
||||||
fputs(" ", stdout);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("%d\n", item->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
fx_bst_iterator_begin(&bst, &it3);
|
|
||||||
while (fx_bst_iterator_is_valid(&it3)) {
|
|
||||||
struct bst_item *item
|
|
||||||
= fx_unbox(struct bst_item, it3.node, node);
|
|
||||||
|
|
||||||
if (item->value == 9) {
|
|
||||||
fx_bst_iterator_erase(&it3);
|
|
||||||
} else {
|
|
||||||
fx_bst_iterator_next(&it3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("\n\n");
|
|
||||||
|
|
||||||
fx_bst_foreach (&it3, &bst) {
|
|
||||||
struct bst_item *item
|
|
||||||
= fx_unbox(struct bst_item, it3.node, node);
|
|
||||||
|
|
||||||
for (size_t i = 0; i < it3.depth; i++) {
|
|
||||||
fputs(" ", stdout);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("%d\n", item->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
fx_tree_unref(tree);
|
|
||||||
#endif
|
|
||||||
fx_dict_unref(dict);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -1,390 +0,0 @@
|
|||||||
#include <fx/collections/tree.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#define ITERATOR_RECURSIVE 0x01u
|
|
||||||
|
|
||||||
#define ITERATOR_IS_RECURSIVE(it) (((it)->_f01 & ITERATOR_RECURSIVE) != 0)
|
|
||||||
#define ITERATOR_UNSET_RECURSIVE(it) ((it)->_f01 &= ~ITERATOR_RECURSIVE)
|
|
||||||
#define ITERATOR_SET_RECURSIVE(it) ((it)->_f01 |= ITERATOR_RECURSIVE)
|
|
||||||
|
|
||||||
#define NODE_PARENT(n) ((n)->__p01)
|
|
||||||
#define NODE_FIRST_CHILD(n) ((n)->__p02)
|
|
||||||
#define NODE_NEXT_SIBLING(n) ((n)->__p03)
|
|
||||||
|
|
||||||
/*** PRIVATE DATA *************************************************************/
|
|
||||||
|
|
||||||
struct fx_tree_p {
|
|
||||||
struct fx_tree_node *t_root;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct fx_tree_iterator_p {
|
|
||||||
size_t i, depth;
|
|
||||||
fx_tree_node *node;
|
|
||||||
|
|
||||||
unsigned char _f01;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*** PRIVATE FUNCTIONS ********************************************************/
|
|
||||||
|
|
||||||
static void tree_set_root(struct fx_tree_p *tree, struct fx_tree_node *node)
|
|
||||||
{
|
|
||||||
tree->t_root = node;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const struct fx_tree_node *next_node(
|
|
||||||
const struct fx_tree_node *node,
|
|
||||||
bool recursive,
|
|
||||||
int *depth_diff)
|
|
||||||
{
|
|
||||||
if (!node) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!recursive) {
|
|
||||||
node = NODE_NEXT_SIBLING(node);
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
|
|
||||||
int d = 0;
|
|
||||||
struct fx_tree_node *next = NODE_FIRST_CHILD(node);
|
|
||||||
if (next) {
|
|
||||||
d = 1;
|
|
||||||
*depth_diff = d;
|
|
||||||
return next;
|
|
||||||
}
|
|
||||||
|
|
||||||
const struct fx_tree_node *n = node;
|
|
||||||
next = NODE_NEXT_SIBLING(n);
|
|
||||||
while (!next) {
|
|
||||||
n = NODE_PARENT(n);
|
|
||||||
if (!n) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
d--;
|
|
||||||
next = NODE_NEXT_SIBLING(n);
|
|
||||||
}
|
|
||||||
|
|
||||||
*depth_diff = d;
|
|
||||||
return next;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void remove_node(struct fx_tree_node *node)
|
|
||||||
{
|
|
||||||
struct fx_tree_node *parent = NODE_PARENT(node);
|
|
||||||
if (!parent) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct fx_tree_node *n0 = NULL, *n1 = NULL;
|
|
||||||
n0 = NODE_FIRST_CHILD(parent);
|
|
||||||
|
|
||||||
while (n0) {
|
|
||||||
if (n0 == node) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
n1 = n0;
|
|
||||||
n0 = NODE_NEXT_SIBLING(n0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!n0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (n1) {
|
|
||||||
NODE_NEXT_SIBLING(n1) = NODE_NEXT_SIBLING(n0);
|
|
||||||
} else {
|
|
||||||
NODE_FIRST_CHILD(parent) = NODE_NEXT_SIBLING(n0);
|
|
||||||
}
|
|
||||||
|
|
||||||
NODE_PARENT(n0) = NODE_NEXT_SIBLING(n0) = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void reparent_children(
|
|
||||||
struct fx_tree_node *old_parent,
|
|
||||||
struct fx_tree_node *new_parent)
|
|
||||||
{
|
|
||||||
struct fx_tree_node *last = NODE_FIRST_CHILD(new_parent);
|
|
||||||
while (last && NODE_NEXT_SIBLING(last)) {
|
|
||||||
last = NODE_NEXT_SIBLING(last);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct fx_tree_node *cur = NODE_FIRST_CHILD(old_parent);
|
|
||||||
while (cur) {
|
|
||||||
struct fx_tree_node *next = NODE_NEXT_SIBLING(cur);
|
|
||||||
NODE_PARENT(cur) = new_parent;
|
|
||||||
NODE_NEXT_SIBLING(cur) = NULL;
|
|
||||||
|
|
||||||
if (last) {
|
|
||||||
NODE_NEXT_SIBLING(last) = cur;
|
|
||||||
} else {
|
|
||||||
NODE_FIRST_CHILD(new_parent) = cur;
|
|
||||||
}
|
|
||||||
|
|
||||||
last = cur;
|
|
||||||
cur = next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*** PUBLIC FUNCTIONS *********************************************************/
|
|
||||||
|
|
||||||
void fx_tree_set_root(fx_tree *tree, struct fx_tree_node *node)
|
|
||||||
{
|
|
||||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_TREE, tree_set_root, tree, node);
|
|
||||||
}
|
|
||||||
|
|
||||||
void fx_tree_node_add_child(
|
|
||||||
struct fx_tree_node *parent,
|
|
||||||
struct fx_tree_node *child)
|
|
||||||
{
|
|
||||||
if (NODE_PARENT(child)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
NODE_PARENT(child) = parent;
|
|
||||||
if (!NODE_FIRST_CHILD(parent)) {
|
|
||||||
NODE_FIRST_CHILD(parent) = child;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct fx_tree_node *cur = NODE_FIRST_CHILD(parent);
|
|
||||||
while (NODE_NEXT_SIBLING(cur)) {
|
|
||||||
cur = NODE_NEXT_SIBLING(cur);
|
|
||||||
}
|
|
||||||
|
|
||||||
NODE_NEXT_SIBLING(cur) = child;
|
|
||||||
}
|
|
||||||
|
|
||||||
void fx_tree_node_add_sibling(
|
|
||||||
struct fx_tree_node *node,
|
|
||||||
struct fx_tree_node *to_add)
|
|
||||||
{
|
|
||||||
if (NODE_PARENT(to_add) || !NODE_PARENT(node)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
fx_tree_node_add_child(NODE_PARENT(node), to_add);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct fx_tree_node *fx_tree_node_get_child(
|
|
||||||
struct fx_tree_node *node,
|
|
||||||
size_t at)
|
|
||||||
{
|
|
||||||
size_t i = 0;
|
|
||||||
struct fx_tree_node *cur = NODE_FIRST_CHILD(node);
|
|
||||||
|
|
||||||
while (i < at) {
|
|
||||||
if (!cur) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
cur = NODE_NEXT_SIBLING(cur);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return cur;
|
|
||||||
}
|
|
||||||
|
|
||||||
fx_iterator *fx_tree_begin(fx_tree *tree)
|
|
||||||
{
|
|
||||||
struct fx_tree_p *p = fx_object_get_private(tree, FX_TYPE_TREE);
|
|
||||||
return fx_tree_node_begin(p->t_root);
|
|
||||||
}
|
|
||||||
|
|
||||||
const fx_iterator *fx_tree_cbegin(const fx_tree *tree)
|
|
||||||
{
|
|
||||||
struct fx_tree_p *p = fx_object_get_private(tree, FX_TYPE_TREE);
|
|
||||||
return fx_tree_node_begin(p->t_root);
|
|
||||||
}
|
|
||||||
|
|
||||||
fx_iterator *fx_tree_node_begin(struct fx_tree_node *node)
|
|
||||||
{
|
|
||||||
fx_tree_iterator *it_obj = fx_object_create(FX_TYPE_TREE_ITERATOR);
|
|
||||||
struct fx_tree_iterator_p *it
|
|
||||||
= fx_object_get_private(it_obj, FX_TYPE_TREE_ITERATOR);
|
|
||||||
|
|
||||||
it->node = NODE_FIRST_CHILD(node);
|
|
||||||
it->i = 0;
|
|
||||||
it->depth = 0;
|
|
||||||
|
|
||||||
ITERATOR_UNSET_RECURSIVE(it);
|
|
||||||
|
|
||||||
if (!it->node) {
|
|
||||||
fx_iterator_set_status(it_obj, FX_ERR_NO_DATA);
|
|
||||||
}
|
|
||||||
|
|
||||||
return it_obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
const fx_iterator *fx_tree_node_cbegin(const struct fx_tree_node *node)
|
|
||||||
{
|
|
||||||
return fx_tree_node_begin((struct fx_tree_node *)node);
|
|
||||||
}
|
|
||||||
|
|
||||||
fx_iterator *fx_tree_node_begin_recursive(struct fx_tree_node *node)
|
|
||||||
{
|
|
||||||
fx_tree_iterator *it_obj = fx_object_create(FX_TYPE_TREE_ITERATOR);
|
|
||||||
struct fx_tree_iterator_p *it
|
|
||||||
= fx_object_get_private(it_obj, FX_TYPE_TREE_ITERATOR);
|
|
||||||
|
|
||||||
it->node = node;
|
|
||||||
it->i = 0;
|
|
||||||
it->depth = 0;
|
|
||||||
|
|
||||||
ITERATOR_SET_RECURSIVE(it);
|
|
||||||
|
|
||||||
if (!it->node) {
|
|
||||||
fx_iterator_set_status(it_obj, FX_ERR_NO_DATA);
|
|
||||||
}
|
|
||||||
|
|
||||||
return it_obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
const fx_iterator *fx_tree_node_cbegin_recursive(
|
|
||||||
const struct fx_tree_node *node)
|
|
||||||
{
|
|
||||||
return fx_tree_node_begin_recursive((struct fx_tree_node *)node);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*** VIRTUAL FUNCTIONS ********************************************************/
|
|
||||||
|
|
||||||
static void tree_init(fx_object *obj, void *priv)
|
|
||||||
{
|
|
||||||
struct fx_tree_p *tree = priv;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void tree_fini(fx_object *obj, void *priv)
|
|
||||||
{
|
|
||||||
struct fx_tree_p *tree = priv;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*** ITERATOR FUNCTIONS *******************************************************/
|
|
||||||
|
|
||||||
static enum fx_status iterator_move_next(const fx_iterator *obj)
|
|
||||||
{
|
|
||||||
struct fx_tree_iterator_p *it
|
|
||||||
= fx_object_get_private(obj, FX_TYPE_TREE_ITERATOR);
|
|
||||||
|
|
||||||
int depth_diff = 0;
|
|
||||||
const struct fx_tree_node *next
|
|
||||||
= next_node(it->node, ITERATOR_IS_RECURSIVE(it), &depth_diff);
|
|
||||||
|
|
||||||
if (next) {
|
|
||||||
it->depth += depth_diff;
|
|
||||||
it->i++;
|
|
||||||
} else {
|
|
||||||
it->depth = 0;
|
|
||||||
it->i = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
it->node = (struct fx_tree_node *)next;
|
|
||||||
return (it->node != NULL) ? FX_SUCCESS : FX_ERR_NO_DATA;
|
|
||||||
}
|
|
||||||
|
|
||||||
static enum fx_status iterator_erase(fx_iterator *obj)
|
|
||||||
{
|
|
||||||
struct fx_tree_iterator_p *it
|
|
||||||
= fx_object_get_private(obj, FX_TYPE_TREE_ITERATOR);
|
|
||||||
|
|
||||||
if (!it->node) {
|
|
||||||
return FX_ERR_OUT_OF_BOUNDS;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct fx_tree_node *parent = NODE_PARENT(it->node);
|
|
||||||
if (!parent) {
|
|
||||||
return FX_ERR_NOT_SUPPORTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
int d = 0;
|
|
||||||
struct fx_tree_node *n = it->node;
|
|
||||||
struct fx_tree_node *next = NODE_NEXT_SIBLING(n);
|
|
||||||
|
|
||||||
if (!next) {
|
|
||||||
next = NODE_FIRST_CHILD(n);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (!next) {
|
|
||||||
n = NODE_PARENT(n);
|
|
||||||
if (!n) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
d--;
|
|
||||||
next = NODE_NEXT_SIBLING(n);
|
|
||||||
}
|
|
||||||
|
|
||||||
remove_node(it->node);
|
|
||||||
reparent_children(it->node, parent);
|
|
||||||
|
|
||||||
return FX_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static fx_iterator_value iterator_get_value(fx_iterator *obj)
|
|
||||||
{
|
|
||||||
struct fx_tree_iterator_p *it
|
|
||||||
= fx_object_get_private(obj, FX_TYPE_TREE_ITERATOR);
|
|
||||||
|
|
||||||
if (!it->node) {
|
|
||||||
return FX_ITERATOR_VALUE_NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return FX_ITERATOR_VALUE_PTR(it->node);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const fx_iterator_value iterator_get_cvalue(const fx_iterator *obj)
|
|
||||||
{
|
|
||||||
struct fx_tree_iterator_p *it
|
|
||||||
= fx_object_get_private(obj, FX_TYPE_TREE_ITERATOR);
|
|
||||||
|
|
||||||
if (!it->node) {
|
|
||||||
return FX_ITERATOR_VALUE_NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return FX_ITERATOR_VALUE_CPTR(it->node);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*** CLASS DEFINITION *********************************************************/
|
|
||||||
|
|
||||||
// ---- fx_tree DEFINITION
|
|
||||||
FX_TYPE_CLASS_BEGIN(fx_tree)
|
|
||||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
|
||||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
|
||||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
|
||||||
|
|
||||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_iterable, FX_TYPE_ITERABLE)
|
|
||||||
FX_INTERFACE_ENTRY(it_begin) = fx_tree_begin;
|
|
||||||
FX_INTERFACE_ENTRY(it_cbegin) = fx_tree_cbegin;
|
|
||||||
FX_TYPE_VTABLE_INTERFACE_END(fx_iterable, FX_TYPE_ITERABLE)
|
|
||||||
FX_TYPE_CLASS_END(fx_tree)
|
|
||||||
|
|
||||||
FX_TYPE_DEFINITION_BEGIN(fx_tree)
|
|
||||||
FX_TYPE_ID(0x8d8fa36b, 0xc515, 0x4803, 0x8124, 0xfd704f01b8ae);
|
|
||||||
FX_TYPE_CLASS(fx_tree_class);
|
|
||||||
FX_TYPE_IMPLEMENTS(FX_TYPE_ITERABLE);
|
|
||||||
FX_TYPE_INSTANCE_PRIVATE(struct fx_tree_p);
|
|
||||||
FX_TYPE_INSTANCE_INIT(tree_init);
|
|
||||||
FX_TYPE_INSTANCE_FINI(tree_fini);
|
|
||||||
FX_TYPE_DEFINITION_END(fx_tree)
|
|
||||||
|
|
||||||
// ---- fx_tree_iterator DEFINITION
|
|
||||||
FX_TYPE_CLASS_BEGIN(fx_tree_iterator)
|
|
||||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
|
||||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
|
||||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
|
||||||
|
|
||||||
FX_TYPE_VTABLE_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_VTABLE_INTERFACE_END(fx_iterator, FX_TYPE_ITERATOR)
|
|
||||||
FX_TYPE_CLASS_END(fx_tree_iterator)
|
|
||||||
|
|
||||||
FX_TYPE_DEFINITION_BEGIN(fx_tree_iterator)
|
|
||||||
FX_TYPE_ID(0xb896e671, 0x84b2, 0x4892, 0xaf09, 0x407f305f4bf8);
|
|
||||||
FX_TYPE_EXTENDS(FX_TYPE_ITERATOR);
|
|
||||||
FX_TYPE_CLASS(fx_tree_iterator_class);
|
|
||||||
FX_TYPE_INSTANCE_PRIVATE(struct fx_tree_iterator_p);
|
|
||||||
FX_TYPE_DEFINITION_END(fx_tree_iterator)
|
|
||||||
Reference in New Issue
Block a user