This commit is contained in:
Saturneic 2018-07-30 18:07:24 +08:00
parent 667e48801d
commit 235e53d9b6
8 changed files with 36 additions and 30 deletions

17
id/id.c
View File

@ -231,3 +231,20 @@ SID *asciiStringToS_id(const char *string){
} }
return s_id; return s_id;
} }
int freeS_id(SID *s_id){
if(s_id->value != NULL){
free(s_id->value);
s_id->value = NULL;
}
if(s_id->value_deeper != NULL){
free(s_id->value_deeper);
s_id->value_deeper = NULL;
}
if(s_id->value_deepest != NULL){
free(s_id->value_deepest);
s_id->value_deepest = NULL;
}
free(s_id);
return 0;
}

View File

@ -37,5 +37,6 @@ char *s_idToASCIIString(const SID *s_id);
SID *asciiStringToS_id(const char *string); SID *asciiStringToS_id(const char *string);
SID *initS_id(unsigned int deep_level); SID *initS_id(unsigned int deep_level);
int freeS_id(SID *s_id);
#endif /* id_h */ #endif /* id_h */

View File

@ -82,7 +82,6 @@ int releaseAllForNode(void) {
Node *initNode(void) { Node *initNode(void) {
Node *p_node = (Node *)malloc(sizeof(Node)); Node *p_node = (Node *)malloc(sizeof(Node));
Node *prec_node = NULL; Node *prec_node = NULL;
p_node->id = getId();
p_node->s_id = getS_id(LIST_NODE, 2); p_node->s_id = getS_id(LIST_NODE, 2);
p_node->if_malloc = 0; p_node->if_malloc = 0;
p_node->next = NULL; p_node->next = NULL;
@ -101,7 +100,6 @@ Node *initNode(void) {
List *initList(void) { List *initList(void) {
Node *p_node; Node *p_node;
List *p_list = (List *)malloc(sizeof(List)); List *p_list = (List *)malloc(sizeof(List));
p_list->id = getId();
p_list->s_id = getS_id(LIST, 1); p_list->s_id = getS_id(LIST, 1);
p_list->head = NULL; p_list->head = NULL;
p_list->tail = NULL; p_list->tail = NULL;
@ -172,7 +170,7 @@ int releaseNode(Node *p_node) {
p_node->next = NULL; p_node->next = NULL;
p_node->type = VOID; p_node->type = VOID;
p_node->value = NULL; p_node->value = NULL;
p_node->id = 0; freeS_id(p_node->s_id);
p_node->if_malloc = 0; p_node->if_malloc = 0;
free(p_node); free(p_node);
return 0; return 0;
@ -196,7 +194,7 @@ int releaseList(List *p_list) {
p_list->head = NULL; p_list->head = NULL;
p_list->tail = NULL; p_list->tail = NULL;
p_list->length = 0; p_list->length = 0;
p_list->id = 0; freeS_id(p_list->s_id)
free(p_list); free(p_list);
return 0; return 0;
} }
@ -204,7 +202,7 @@ int releaseList(List *p_list) {
int releaseListForSingle(List *p_list) { int releaseListForSingle(List *p_list) {
p_list->head = NULL; p_list->head = NULL;
p_list->tail = NULL; p_list->tail = NULL;
p_list->id = 0; freeS_id(p_list->s_id);
p_list->length = 0; p_list->length = 0;
free(p_list); free(p_list);
return 0; return 0;
@ -424,7 +422,7 @@ int exchangeLocation(Node *p_node, Node *t_node) {
Node *copyNode(Node *p_node) { Node *copyNode(Node *p_node) {
Node *t_node = initNode(); Node *t_node = initNode();
t_node->id = p_node->id; t_node->s_id = p_node->s_id;
t_node->last = p_node->last; t_node->last = p_node->last;
t_node->next = p_node->next; t_node->next = p_node->next;
t_node->if_malloc = p_node->if_malloc; t_node->if_malloc = p_node->if_malloc;
@ -450,7 +448,7 @@ List *copyList(List *p_list) {
} }
int releaseOnlyNode(Node *p_node) { int releaseOnlyNode(Node *p_node) {
p_node->id = 0; freeS_id(p_node->s_id);
p_node->if_malloc = 0; p_node->if_malloc = 0;
p_node->last = NULL; p_node->last = NULL;
p_node->next = NULL; p_node->next = NULL;

View File

@ -9,8 +9,7 @@
#include "../id/id.h" #include "../id/id.h"
typedef struct Node{ typedef struct Node{
unsigned long long id;//唯一标识符 SID *s_id;//唯一标识符
SID *s_id;
void *value; void *value;
_Bool if_malloc;//记录是否已经初始化值 _Bool if_malloc;//记录是否已经初始化值
_Bool if_sid; _Bool if_sid;
@ -21,8 +20,7 @@ typedef struct Node{
typedef struct List{ typedef struct List{
unsigned long long id;//唯一标识符 SID *s_id;//唯一标识符
SID *s_id;
Node *head; Node *head;
Node *tail; Node *tail;
unsigned long long length;//链表长度 unsigned long long length;//链表长度

View File

@ -2,7 +2,6 @@
Stack *initStack(void) { Stack *initStack(void) {
Stack *p_stack = (Stack *)malloc(sizeof(Stack)); Stack *p_stack = (Stack *)malloc(sizeof(Stack));
p_stack->id = getId();
p_stack->s_id = getS_id(STACK, 1); p_stack->s_id = getS_id(STACK, 1);
p_stack->length = 0; p_stack->length = 0;
p_stack->top = NULL; p_stack->top = NULL;
@ -11,7 +10,6 @@ Stack *initStack(void) {
SNode *initSNode(void) { SNode *initSNode(void) {
SNode *p_snode = (SNode *)malloc(sizeof(SNode)); SNode *p_snode = (SNode *)malloc(sizeof(SNode));
p_snode->id = getId();
p_snode->s_id = getS_id(STACK_NODE, 2); p_snode->s_id = getS_id(STACK_NODE, 2);
p_snode->if_malloc = 0; p_snode->if_malloc = 0;
p_snode->next = NULL; p_snode->next = NULL;
@ -45,7 +43,7 @@ int releaseStack(Stack *p_stack) {
p_sndoe = p_sndoe->next; p_sndoe = p_sndoe->next;
releaseSNode(pl_snode); releaseSNode(pl_snode);
} }
p_stack->id = 0; freeS_id(p_stack->s_id);
p_stack->top = NULL; p_stack->top = NULL;
p_stack->length = 0; p_stack->length = 0;
free(p_stack); free(p_stack);
@ -53,7 +51,7 @@ int releaseStack(Stack *p_stack) {
} }
int releaseSNode(SNode *p_snode) { int releaseSNode(SNode *p_snode) {
p_snode->id = 0; freeS_id(p_snode->s_id);
free(p_snode->value); free(p_snode->value);
p_snode->if_malloc = 0; p_snode->if_malloc = 0;
p_snode->value = NULL; p_snode->value = NULL;

View File

@ -5,7 +5,6 @@
#include "../list/list_expand.h" #include "../list/list_expand.h"
typedef struct stack_node{ typedef struct stack_node{
unsigned long long id;
SID *s_id; SID *s_id;
_Bool if_malloc; _Bool if_malloc;
_Bool if_sid; _Bool if_sid;
@ -15,7 +14,6 @@ typedef struct stack_node{
} SNode; } SNode;
typedef struct stack{ typedef struct stack{
unsigned long long id;
SID *s_id; SID *s_id;
unsigned long long length; unsigned long long length;
SNode *top; SNode *top;

View File

@ -30,8 +30,7 @@ int safeModeForTree(int ifon) {
TNode *initTNode(void) { TNode *initTNode(void) {
Node *s_node; Node *s_node;
TNode *p_tnode = (TNode *)malloc(sizeof(TNode)); TNode *p_tnode = (TNode *)malloc(sizeof(TNode));
p_tnode->id = getId();
p_tnode->s_id = getS_id(TREE_NODE, 2); p_tnode->s_id = getS_id(TREE_NODE, 2);
p_tnode->child_num = 0; p_tnode->child_num = 0;
p_tnode->father = NULL; p_tnode->father = NULL;
@ -60,8 +59,7 @@ TNode *initTNode(void) {
Tree *initTree(void) { Tree *initTree(void) {
Node *s_node; Node *s_node;
Tree *p_tree = (Tree *)malloc(sizeof(Tree)); Tree *p_tree = (Tree *)malloc(sizeof(Tree));
p_tree->id = getId();
p_tree->s_id = getS_id(TREE, 1); p_tree->s_id = getS_id(TREE, 1);
p_tree->root = NULL; p_tree->root = NULL;
if (if_safeModeForTree) { if (if_safeModeForTree) {
@ -270,7 +268,7 @@ unsigned long long getIndexByChild(TNode *f_tnode, TNode *c_tnode) {
int m_index = 0; int m_index = 0;
while (p_node != NULL) { while (p_node != NULL) {
TNode *p_tnode = (TNode *)p_node->value; TNode *p_tnode = (TNode *)p_node->value;
if (p_tnode->id == c_tnode->id) { if (p_tnode->s_id == c_tnode->s_id) {
return m_index; return m_index;
} }
m_index++; m_index++;
@ -387,7 +385,7 @@ int releaseTNode(TNode *p_tnode) {
} }
p_tnode->value = NULL; p_tnode->value = NULL;
p_tnode->type = VOID; p_tnode->type = VOID;
p_tnode->id = 0; freeS_id(p_tnode->s_id);
p_tnode->if_malloc = 0; p_tnode->if_malloc = 0;
free(p_tnode); free(p_tnode);
} }
@ -397,7 +395,7 @@ int releaseTNode(TNode *p_tnode) {
int releaseTree(Tree *p_tree) { int releaseTree(Tree *p_tree) {
TreeThroughUp(p_tree, _doreleaseTree); TreeThroughUp(p_tree, _doreleaseTree);
p_tree->root = NULL; p_tree->root = NULL;
p_tree->id = 0; freeS_id(p_tree->s_id);
free(p_tree); free(p_tree);
return 0; return 0;
} }
@ -408,7 +406,7 @@ int _doreleaseTree(TNode *p_tnode, unsigned long long height) {
} }
int releaseOnlyTree(Tree *p_tree) { int releaseOnlyTree(Tree *p_tree) {
p_tree->id = 0; freeS_id(p_tree->s_id);
p_tree->root = NULL; p_tree->root = NULL;
free(p_tree); free(p_tree);
return 0; return 0;
@ -428,7 +426,7 @@ int releaseOnlyTNode(TNode *p_tnode) {
} }
p_tnode->value = NULL; p_tnode->value = NULL;
p_tnode->type = VOID; p_tnode->type = VOID;
p_tnode->id = 0; freeS_id(p_tnode->s_id);
p_tnode->if_malloc = 0; p_tnode->if_malloc = 0;
free(p_tnode); free(p_tnode);
return 0; return 0;

View File

@ -5,8 +5,7 @@
#include "../list/list_expand.h" #include "../list/list_expand.h"
typedef struct tree_node typedef struct tree_node
{ {
unsigned long long id;
SID *s_id; SID *s_id;
List *home; List *home;
struct tree_node *father; struct tree_node *father;
@ -19,8 +18,7 @@ typedef struct tree_node
}TNode; }TNode;
typedef struct tree typedef struct tree
{ {
unsigned long long id;
SID *s_id; SID *s_id;
_Bool if_sid; _Bool if_sid;
TNode *root; TNode *root;