From 235e53d9b669342c65527c85c3870ef22fc92cc3 Mon Sep 17 00:00:00 2001 From: Saturneic Date: Mon, 30 Jul 2018 18:07:24 +0800 Subject: [PATCH] Fixed --- id/id.c | 17 +++++++++++++++++ id/id.h | 1 + list/list.c | 12 +++++------- list/list.h | 6 ++---- stack/stack.c | 6 ++---- stack/stack.h | 2 -- tree/tree.c | 16 +++++++--------- tree/tree.h | 6 ++---- 8 files changed, 36 insertions(+), 30 deletions(-) diff --git a/id/id.c b/id/id.c index e8a756d..0aa14fe 100644 --- a/id/id.c +++ b/id/id.c @@ -231,3 +231,20 @@ SID *asciiStringToS_id(const char *string){ } 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; +} diff --git a/id/id.h b/id/id.h index 894cd3c..57c8655 100644 --- a/id/id.h +++ b/id/id.h @@ -37,5 +37,6 @@ char *s_idToASCIIString(const SID *s_id); SID *asciiStringToS_id(const char *string); SID *initS_id(unsigned int deep_level); +int freeS_id(SID *s_id); #endif /* id_h */ diff --git a/list/list.c b/list/list.c index 96b45ac..7d2a6d4 100644 --- a/list/list.c +++ b/list/list.c @@ -82,7 +82,6 @@ int releaseAllForNode(void) { Node *initNode(void) { Node *p_node = (Node *)malloc(sizeof(Node)); Node *prec_node = NULL; - p_node->id = getId(); p_node->s_id = getS_id(LIST_NODE, 2); p_node->if_malloc = 0; p_node->next = NULL; @@ -101,7 +100,6 @@ Node *initNode(void) { List *initList(void) { Node *p_node; List *p_list = (List *)malloc(sizeof(List)); - p_list->id = getId(); p_list->s_id = getS_id(LIST, 1); p_list->head = NULL; p_list->tail = NULL; @@ -172,7 +170,7 @@ int releaseNode(Node *p_node) { p_node->next = NULL; p_node->type = VOID; p_node->value = NULL; - p_node->id = 0; + freeS_id(p_node->s_id); p_node->if_malloc = 0; free(p_node); return 0; @@ -196,7 +194,7 @@ int releaseList(List *p_list) { p_list->head = NULL; p_list->tail = NULL; p_list->length = 0; - p_list->id = 0; + freeS_id(p_list->s_id) free(p_list); return 0; } @@ -204,7 +202,7 @@ int releaseList(List *p_list) { int releaseListForSingle(List *p_list) { p_list->head = NULL; p_list->tail = NULL; - p_list->id = 0; + freeS_id(p_list->s_id); p_list->length = 0; free(p_list); return 0; @@ -424,7 +422,7 @@ int exchangeLocation(Node *p_node, Node *t_node) { Node *copyNode(Node *p_node) { 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->next = p_node->next; t_node->if_malloc = p_node->if_malloc; @@ -450,7 +448,7 @@ List *copyList(List *p_list) { } int releaseOnlyNode(Node *p_node) { - p_node->id = 0; + freeS_id(p_node->s_id); p_node->if_malloc = 0; p_node->last = NULL; p_node->next = NULL; diff --git a/list/list.h b/list/list.h index cef010e..152ec2f 100644 --- a/list/list.h +++ b/list/list.h @@ -9,8 +9,7 @@ #include "../id/id.h" typedef struct Node{ - unsigned long long id;//唯一标识符 - SID *s_id; + SID *s_id;//唯一标识符 void *value; _Bool if_malloc;//记录是否已经初始化值 _Bool if_sid; @@ -21,8 +20,7 @@ typedef struct Node{ typedef struct List{ - unsigned long long id;//唯一标识符 - SID *s_id; + SID *s_id;//唯一标识符 Node *head; Node *tail; unsigned long long length;//链表长度 diff --git a/stack/stack.c b/stack/stack.c index 9689f86..66580bd 100644 --- a/stack/stack.c +++ b/stack/stack.c @@ -2,7 +2,6 @@ Stack *initStack(void) { Stack *p_stack = (Stack *)malloc(sizeof(Stack)); - p_stack->id = getId(); p_stack->s_id = getS_id(STACK, 1); p_stack->length = 0; p_stack->top = NULL; @@ -11,7 +10,6 @@ Stack *initStack(void) { SNode *initSNode(void) { SNode *p_snode = (SNode *)malloc(sizeof(SNode)); - p_snode->id = getId(); p_snode->s_id = getS_id(STACK_NODE, 2); p_snode->if_malloc = 0; p_snode->next = NULL; @@ -45,7 +43,7 @@ int releaseStack(Stack *p_stack) { p_sndoe = p_sndoe->next; releaseSNode(pl_snode); } - p_stack->id = 0; + freeS_id(p_stack->s_id); p_stack->top = NULL; p_stack->length = 0; free(p_stack); @@ -53,7 +51,7 @@ int releaseStack(Stack *p_stack) { } int releaseSNode(SNode *p_snode) { - p_snode->id = 0; + freeS_id(p_snode->s_id); free(p_snode->value); p_snode->if_malloc = 0; p_snode->value = NULL; diff --git a/stack/stack.h b/stack/stack.h index 9581f5b..7990edf 100644 --- a/stack/stack.h +++ b/stack/stack.h @@ -5,7 +5,6 @@ #include "../list/list_expand.h" typedef struct stack_node{ - unsigned long long id; SID *s_id; _Bool if_malloc; _Bool if_sid; @@ -15,7 +14,6 @@ typedef struct stack_node{ } SNode; typedef struct stack{ - unsigned long long id; SID *s_id; unsigned long long length; SNode *top; diff --git a/tree/tree.c b/tree/tree.c index 519df76..e9b4c87 100644 --- a/tree/tree.c +++ b/tree/tree.c @@ -30,8 +30,7 @@ int safeModeForTree(int ifon) { TNode *initTNode(void) { Node *s_node; - TNode *p_tnode = (TNode *)malloc(sizeof(TNode)); - p_tnode->id = getId(); + TNode *p_tnode = (TNode *)malloc(sizeof(TNode)); p_tnode->s_id = getS_id(TREE_NODE, 2); p_tnode->child_num = 0; p_tnode->father = NULL; @@ -60,8 +59,7 @@ TNode *initTNode(void) { Tree *initTree(void) { Node *s_node; - Tree *p_tree = (Tree *)malloc(sizeof(Tree)); - p_tree->id = getId(); + Tree *p_tree = (Tree *)malloc(sizeof(Tree)); p_tree->s_id = getS_id(TREE, 1); p_tree->root = NULL; if (if_safeModeForTree) { @@ -270,7 +268,7 @@ unsigned long long getIndexByChild(TNode *f_tnode, TNode *c_tnode) { int m_index = 0; while (p_node != NULL) { 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; } m_index++; @@ -387,7 +385,7 @@ int releaseTNode(TNode *p_tnode) { } p_tnode->value = NULL; p_tnode->type = VOID; - p_tnode->id = 0; + freeS_id(p_tnode->s_id); p_tnode->if_malloc = 0; free(p_tnode); } @@ -397,7 +395,7 @@ int releaseTNode(TNode *p_tnode) { int releaseTree(Tree *p_tree) { TreeThroughUp(p_tree, _doreleaseTree); p_tree->root = NULL; - p_tree->id = 0; + freeS_id(p_tree->s_id); free(p_tree); return 0; } @@ -408,7 +406,7 @@ int _doreleaseTree(TNode *p_tnode, unsigned long long height) { } int releaseOnlyTree(Tree *p_tree) { - p_tree->id = 0; + freeS_id(p_tree->s_id); p_tree->root = NULL; free(p_tree); return 0; @@ -428,7 +426,7 @@ int releaseOnlyTNode(TNode *p_tnode) { } p_tnode->value = NULL; p_tnode->type = VOID; - p_tnode->id = 0; + freeS_id(p_tnode->s_id); p_tnode->if_malloc = 0; free(p_tnode); return 0; diff --git a/tree/tree.h b/tree/tree.h index 75afa5d..f230b57 100644 --- a/tree/tree.h +++ b/tree/tree.h @@ -5,8 +5,7 @@ #include "../list/list_expand.h" typedef struct tree_node -{ - unsigned long long id; +{ SID *s_id; List *home; struct tree_node *father; @@ -19,8 +18,7 @@ typedef struct tree_node }TNode; typedef struct tree -{ - unsigned long long id; +{ SID *s_id; _Bool if_sid; TNode *root;