2018-07-23 04:59:16 +00:00
|
|
|
#ifndef TREE_H
|
|
|
|
#define TREE_H
|
2018-07-21 10:39:09 +00:00
|
|
|
|
2018-08-23 16:57:38 +00:00
|
|
|
#include <list/list_type.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
*超级树节点的管理及操作的结构
|
|
|
|
*/
|
|
|
|
typedef struct tree_node
|
|
|
|
{
|
|
|
|
SID *s_id;//超级树节点的ID
|
|
|
|
List *home;//超级树节点的子节点列表
|
|
|
|
struct tree_node *father;//超级树节点的父节点
|
|
|
|
Node *room;//超级树节点的父节点的子节点列表
|
|
|
|
unsigned long long child_num;//超级树节点的子节点数量
|
|
|
|
unsigned int type;//超级树节点的类型
|
|
|
|
void *value;//值指针
|
|
|
|
}TNode;
|
|
|
|
|
|
|
|
/*
|
|
|
|
*二叉树节点的管理及操作的结构
|
|
|
|
*/
|
|
|
|
typedef struct simple_tree_node{
|
|
|
|
void *value;//值指针
|
|
|
|
struct simple_tree_node *childs[2];//子节点
|
|
|
|
}s_TNode;
|
|
|
|
|
|
|
|
/*
|
|
|
|
*树的管理及操作的结构
|
|
|
|
*/
|
|
|
|
typedef struct tree
|
|
|
|
{
|
|
|
|
SID *s_id;//超级树的SID
|
|
|
|
TNode *root;//超级树根节点
|
|
|
|
s_TNode *s_root;//二叉树的根节点
|
|
|
|
}Tree;
|
2018-06-12 09:03:31 +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);
|
2018-07-30 09:45:33 +00:00
|
|
|
int *initMallocValueForTNode(TNode *p_tnode, unsigned int type, void *value);
|
2018-06-12 09:03:31 +00:00
|
|
|
|
|
|
|
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);
|
2018-07-30 09:45:33 +00:00
|
|
|
TNode *getChildById(TNode *p_tnode, const SID *s_id);
|
|
|
|
TNode *getChildByValue(TNode *p_tnode, unsigned int type, void *value);
|
2018-06-12 09:03:31 +00:00
|
|
|
TNode *getChildByIndex(TNode *p_tnode, unsigned long long index);
|
|
|
|
unsigned long long getIndexByChild(TNode *f_tnode, TNode *c_tnode);
|
2018-07-30 09:45:33 +00:00
|
|
|
int removeChildById(TNode *p_tnode, const SID *s_id);
|
2018-06-12 09:03:31 +00:00
|
|
|
int removeChildByIndex(TNode *p_tnode, unsigned long long index);
|
2018-07-30 09:45:33 +00:00
|
|
|
int removeChildByValue(TNode *p_tnode, unsigned int type, void *value);
|
2018-06-12 09:03:31 +00:00
|
|
|
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-08-07 04:10:55 +00:00
|
|
|
List *_dogetChildById(unsigned int type, void *value, List *er_list);
|
|
|
|
List *_dogetChildByValue(unsigned int type, void *value, List *er_list);
|
2018-07-23 04:59:16 +00:00
|
|
|
int _doreleaseTree(TNode *p_tnode, unsigned long long height);
|
|
|
|
int _doTreeThroughDown(TNode *p_tnode, int height, int(*func)(TNode *, unsigned long long height));
|
|
|
|
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);
|
2018-07-23 04:59:16 +00:00
|
|
|
int releaseTNode(TNode *p_tnode);
|
|
|
|
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-23 04:59:16 +00:00
|
|
|
static int target_type;
|
2018-07-18 04:44:13 +00:00
|
|
|
static void *target_value;
|
|
|
|
static TNode *target_value_value;
|
2018-06-12 09:57:23 +00:00
|
|
|
|
2018-07-30 09:45:33 +00:00
|
|
|
static SID *target_sid;
|
|
|
|
static TNode *target_value_sid;
|
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-07-21 10:43:06 +00:00
|
|
|
#endif
|