2018-06-12 09:03:31 +00:00
|
|
|
#include "../list/list_expand.h"
|
2018-06-12 11:07:12 +00:00
|
|
|
#ifndef TREE_H
|
|
|
|
#define TREE_H
|
2018-06-12 09:03:31 +00:00
|
|
|
|
|
|
|
typedef struct tree_node
|
|
|
|
{
|
|
|
|
unsigned long long id;
|
|
|
|
List *home;
|
|
|
|
struct tree_node *father;
|
|
|
|
Node *room;
|
|
|
|
unsigned long long child_num;
|
|
|
|
char *type;
|
|
|
|
void *value;
|
|
|
|
int if_malloc;
|
|
|
|
}TNode;
|
|
|
|
|
|
|
|
typedef struct tree
|
|
|
|
{
|
|
|
|
unsigned long long id;
|
|
|
|
TNode *root;
|
|
|
|
}Tree;
|
|
|
|
|
2018-06-13 08:04:51 +00:00
|
|
|
|
2018-06-12 09:57:23 +00:00
|
|
|
int safeModeForTree(int ifon);
|
|
|
|
int releaseAllForTree(void);
|
|
|
|
|
2018-06-12 09:03:31 +00:00
|
|
|
TNode *initTNode(void);
|
|
|
|
Tree *initTree(void);
|
|
|
|
int *initMallocValueForTNode(TNode *p_tnode, char *type, void *value);
|
|
|
|
|
|
|
|
int addChildInLeft(TNode *f_tnode, TNode *c_tnode);
|
|
|
|
int addChildInRight(TNode *f_tnode, TNode *c_tnode);
|
|
|
|
TNode *getBrotherInLeft(TNode *p_tnode);
|
|
|
|
TNode *getBrotherInRight(TNode *p_node);
|
|
|
|
int removeChildInLeft(TNode *p_tnode);
|
|
|
|
int removeChildInRight(TNode *p_tnode);
|
|
|
|
TNode *getChildById(TNode *p_tnode, unsigned long long id);
|
|
|
|
TNode *getChildByValue(TNode *p_tnode, char *type, void *value);
|
|
|
|
TNode *getChildByIndex(TNode *p_tnode, unsigned long long index);
|
|
|
|
unsigned long long getIndexByChild(TNode *f_tnode, TNode *c_tnode);
|
|
|
|
int removeChildById(TNode *p_tnode, unsigned long long id);
|
|
|
|
int removeChildByIndex(TNode *p_tnode, unsigned long long index);
|
|
|
|
int removeChildByValue(TNode *p_tnode, char *type, void *value);
|
|
|
|
int TreeThroughDown(Tree *p_tree, int(*func)(TNode *, unsigned long long height));
|
|
|
|
int TreeThroughUp(Tree *p_tree, int(*func)(TNode *, unsigned long long height));
|
2018-06-12 09:57:23 +00:00
|
|
|
int TreeTravel(Tree *p_tree, int(*func)(TNode *, unsigned long long height));
|
|
|
|
|
2018-07-18 04:44:13 +00:00
|
|
|
static int _dogetChildById(const char *type, void *value);
|
|
|
|
static int _dogetChildByValue(const char *type, void *value);
|
|
|
|
static int _doreleaseTree(TNode *p_tnode, unsigned long long height);
|
|
|
|
static int _doTreeThroughDown(TNode *p_tnode, int height, int(*func)(TNode *, unsigned long long height));
|
|
|
|
static int _doTreeThroughUp(TNode *p_tnode, int height, int(*func)(TNode *, unsigned long long height));
|
2018-06-12 11:07:12 +00:00
|
|
|
|
2018-06-12 09:57:23 +00:00
|
|
|
int releaseTree(Tree *p_tree);
|
|
|
|
int releaseOnlyTree(Tree *p_tree);
|
|
|
|
int releaseTNode(TNode *p_tnode);
|
2018-07-18 04:44:13 +00:00
|
|
|
static int releaseOnlyTNode(TNode *p_tnode);
|
2018-06-12 09:57:23 +00:00
|
|
|
|
2018-06-13 08:04:51 +00:00
|
|
|
int setRoot(Tree *p_tree, TNode *p_tnode);
|
|
|
|
|
2018-07-18 04:44:13 +00:00
|
|
|
static char *target_type;
|
|
|
|
static void *target_value;
|
|
|
|
static TNode *target_value_value;
|
2018-06-12 09:57:23 +00:00
|
|
|
|
2018-07-18 04:44:13 +00:00
|
|
|
static unsigned long long target_id;
|
|
|
|
static TNode *target_value_id;
|
2018-06-12 09:57:23 +00:00
|
|
|
|
2018-07-18 04:44:13 +00:00
|
|
|
static List *tree_list;
|
|
|
|
static List *tnode_list;
|
|
|
|
static int if_safeModeForTree;
|
2018-06-13 08:04:51 +00:00
|
|
|
|
2018-06-12 09:57:23 +00:00
|
|
|
|
2018-06-12 11:07:12 +00:00
|
|
|
#endif
|