toaruos/kernel/include/tree.h
2011-11-29 02:49:19 -06:00

35 lines
974 B
C

/* vim: tabstop=4 shiftwidth=4 noexpandtab
*
* General-purpose tree implementation
*/
#ifndef TREE_H
#define TREE_H
#include <system.h>
#include <list.h>
typedef struct tree_node {
void * value;
list_t * children;
struct tree_node * parent;
} tree_node_t;
typedef struct {
size_t nodes;
tree_node_t * root;
} tree_t;
tree_t * tree_create();
void tree_set_root(tree_t * tree, void * value);
void tree_node_destroy(tree_node_t * node);
void tree_destroy(tree_t * tree);
void tree_free(tree_t * tree);
tree_node_t * tree_node_create(void * value);
void tree_node_insert_child_node(tree_t * tree, tree_node_t * parent, tree_node_t * node);
tree_node_t * tree_node_insert_child(tree_t * tree, tree_node_t * parent, void * value);
tree_node_t * tree_node_find_parent(tree_node_t * haystack, tree_node_t * needle);
void tree_node_parent_remove(tree_t * tree, tree_node_t * parent, tree_node_t * node);
void tree_node_remove(tree_t * tree, tree_node_t * node);
#endif