/*
* Tree data structure
*
* Copyright (C) 2017 Patrick McDermott
*
* This file is part of Marquee.
*
* Marquee is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Marquee is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Marquee. If not, see .
*/
#ifndef MQ_TREE_H
#define MQ_TREE_H
typedef struct _MqTree MqTree;
#include
G_BEGIN_DECLS
#define MQ_TREE(obj) ((MqTree *) (obj))
#define MQ_TREE_CONTINUE TRUE
#define MQ_TREE_STOP FALSE
struct _MqTree {
MqTree *root;
MqTree *parent;
MqTree *prev;
MqTree *next;
MqTree *first_child;
MqTree *last_child;
gint size;
gint position;
gpointer data;
};
MqTree *
mq_tree_insert_root_allocated(MqTree *node, gpointer data);
MqTree *
mq_tree_append_child_allocated(MqTree *node, MqTree *parent, gpointer data);
MqTree *
mq_tree_append_sibling_allocated(MqTree *node, MqTree *sibling, gpointer data);
void
mq_tree_remove_allocated(MqTree *node);
#define mq_tree_insert_root(data) \
mq_tree_insert_root_allocated(g_new0(MqTree, 1), data)
#define mq_tree_append_child(parent, data) \
mq_tree_append_child_allocated(g_new0(MqTree, 1), parent, data)
#define mq_tree_append_sibling(sibling, data) \
mq_tree_append_sibling_allocated(g_new0(MqTree, 1), sibling, data)
#define mq_tree_remove(node) \
G_STMT_START { \
mq_tree_remove_allocated(node); \
g_free(node); \
} G_STMT_END
#define mq_tree_size(node) ((node) ? (((MqTree *) (node))->size) : -1)
#define mq_tree_position(node) ((node) ? (((MqTree *) (node))->position) : -1)
#define mq_tree_root(node) ((node) ? (((MqTree *) (node))->root) : NULL)
#define mq_tree_previous(node) ((node) ? (((MqTree *) (node))->prev) : NULL)
#define mq_tree_next(node) ((node) ? (((MqTree *) (node))->next) : NULL)
#define mq_tree_first_child(node) \
((node) ? (((MqTree *) (node))->first_child) : NULL)
MqTree *
mq_tree_seek(MqTree *node, gint offset) G_GNUC_PURE;
void
mq_tree_foreach(MqTree *node, gboolean (*cb)(MqTree *node, gpointer user_data),
gpointer user_data);
void
mq_tree_foreach_from(MqTree *node,
gboolean (*cb)(MqTree *node, gpointer user_data), gpointer user_data);
G_END_DECLS
#endif /* MQ_TREE_H */