From 6aa9b8d7084dd51f3f308c31c3db78242063432c Mon Sep 17 00:00:00 2001 From: Saturneic Date: Mon, 23 Jul 2018 12:59:16 +0800 Subject: [PATCH] Fix type type. --- graph/graph.h | 2 +- list/list.c | Bin 20546 -> 11900 bytes list/list.h | Bin 3934 -> 2325 bytes list/list_expand.c | 110 +++++++++++++++++++++---------------------- list/list_expand.h | Bin 3374 -> 2366 bytes stack/stack.c | Bin 2886 -> 1531 bytes stack/stack.h | Bin 1276 -> 624 bytes stack/stack_expand.c | 20 ++++---- stack/stack_expand.h | Bin 838 -> 401 bytes test.c | 5 +- test.h | 3 +- tree/tree.c | 61 ++++++++++++------------ tree/tree.h | 39 ++++++--------- tree/tree_expand.c | 50 ++++++++++---------- type/type.h | 21 +++++++++ 15 files changed, 159 insertions(+), 152 deletions(-) create mode 100644 type/type.h diff --git a/graph/graph.h b/graph/graph.h index 6a092c6..c1db03d 100644 --- a/graph/graph.h +++ b/graph/graph.h @@ -21,4 +21,4 @@ GNode *initGNode(void); Route *initRoute(void); -#endif \ No newline at end of file +#endif diff --git a/list/list.c b/list/list.c index 96a722a730d176cd9a70b8874d2419ba5730f28f..4afc44ddc7724056f9864a0058b01ed0a9d5fa7c 100644 GIT binary patch literal 11900 zcmdT~UvDHw5r6lm=mZhX`qsDc0}sg95~o~Zy{s7L z%ZWA5=h>pZdHnp^+M-VDY;3ZkHre!WkxuQa<;1>RR{QYJY?~Ligk=wgnDqi4AL3}B z?Z2_Nw`E47)5o8l{`Hg7KYjM(lV6>E`QFptzI*omcjt@{qfVA zYip=dL!X4yEQ^78d(FTno0=q>mWA2gHkeM}xA9q6yuWMijJv%FJG zB-1bWoOu;b-@J-twRtagPPkI}F`Kg3mnNr^}XBaL}b{yqZ<$Tx_nxhK~ra|HaoJG(C_uz9k>XKOflhMArPFxt)H z`WCK*uri2N2h5N2oJ(Nxpv)$c1*qJ#t7NPAv{`hlMoFj#l?8xRLmRykjq6EXxfEG8 zI|X7C7=*d3$ZGr+Es#h)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R9+y#L*AUU@3LCzDbPefx zDmEiZ14mdrl;MB#^bHIB)6&K+qd}p zo_kRFGni&~;NBz> zzj{~Dn^YLwE!{cMbDH-Ob8=O&|Fp8qf1%-bQ*)>4U#~35-0ybl_%3(}9+;zV3u_yC ggJxY{htype = "list"; + p_node->type = LIST; p_node->value = initList(); p_node->if_malloc = 1; return p_node; @@ -50,7 +50,7 @@ Node *findByIndexForNode(List *p_list, unsigned long long m_index) { return p_node; } -int listThrough(List *p_list, int(*p_func)(const char *, void *)) { +int listThrough(List *p_list, int(*p_func)(int, void *)) { Node *p_node = p_list->head; while (p_node != NULL) { if (p_node->if_malloc == 1) { @@ -70,22 +70,22 @@ int listThrough(List *p_list, int(*p_func)(const char *, void *)) { } int getByIntForNode(Node *p_node) { - if (!strcmp(p_node->type, "int")) return *(int *)(p_node->value); + if (p_node->type == INT) return *(int *)(p_node->value); else return -1; } char *getByStringForNode(Node *p_node) { - if (!strcmp(p_node->type, "string")) return (char *)(p_node->value); + if (p_node->type == STRING) return (char *)(p_node->value); else return NULL; } double getByDoubleForNode(Node *p_node) { - if (!strcmp(p_node->type, "double")) return *(double *)(p_node->value); + if (p_node->type == DOUBLE) return *(double *)(p_node->value); else return -1; } void *getByPointerForNode(Node *p_node) { - if (!strcmp(p_node->type, "pointer")) return (void *)(p_node->value); + if (p_node->type == POINTER) return (void *)(p_node->value); else return NULL; } @@ -115,19 +115,19 @@ void printList(List *p_list) { printf("["); while (p_node != NULL) { if (!if_nearLast && p_node->next == NULL) if_nearLast = 1; - if (!strcmp(p_node->type, "int")) { + if (p_node->type == INT) { printf("%d", *(int *)(p_node->value)); } - else if (!strcmp(p_node->type, "double")) { + else if (p_node->type == DOUBLE) { printf("%a", *(double *)(p_node->value)); } - else if (!strcmp(p_node->type, "string")) { + else if (p_node->type == STRING) { printf("%s", (char *)(p_node->value)); } - else if (!strcmp(p_node->type, "pointer")) { + else if (p_node->type == POINTER) { printf("%p", (char *)(p_node->value)); } - else if (!strcmp(p_node->type, "list")) { + else if (p_node->type == LIST) { printList((List *)p_node->value); } if (!if_nearLast) { @@ -144,23 +144,23 @@ void printNodeInfo(Node *p_node, int priority) { printf("#NODE(location:%p, id:%llu){\n", p_node, p_node->id); for (i = 0; i < priority + 1; i++) printf(" "); printf("NEXT->%p / LAST->%p / MALLOC:%d\n", p_node->next, p_node->last, p_node->if_malloc); - if (!strcmp(p_node->type, "int")) { + if (p_node->type == INT) { for (i = 0; i < priority + 1; i++) printf(" "); printf("VALUE(int):%d\n", *(int *)(p_node->value)); } - else if (!strcmp(p_node->type, "double")) { + else if (p_node->type == DOUBLE) { for (i = 0; i < priority + 1; i++) printf(" "); printf("VALUE(double):%a\n", *(double *)(p_node->value)); } - else if (!strcmp(p_node->type, "string")) { + else if (p_node->type == STRING) { for (i = 0; i < priority + 1; i++) printf(" "); printf("VALUE(string):%s\n", (char *)(p_node->value)); } - else if (!strcmp(p_node->type, "pointer")) { + else if (p_node->type == POINTER) { for (i = 0; i < priority + 1; i++) printf(" "); printf("VALUE(pointer):%s\n", (char *)(p_node->value)); } - else if (!strcmp(p_node->type, "list")) { + else if (p_node->type == LIST) { for (i = 0; i < priority + 1; i++) printf(" "); printf("VALUE(List):\n"); printListInfo((List *)p_node->value, priority + 2); @@ -173,26 +173,26 @@ void printNode(Node *p_node) { int i; printf("#NODE(location:%p, id:%llu){\n", p_node, p_node->id); printf(" "); - printf("NEXT->%p / LAST->%p\n", p_node->next, p_node->last, p_node->if_malloc); + printf("NEXT->%p / LAST->%p\n", p_node->next, p_node->last); for (i = 0; i < 1; i++) printf(" "); printf("ifMalloc: "); if (p_node->if_malloc) { printf("YES\n"); for (i = 0; i < 1; i++) printf(" "); - printf("Value(type: %s): ", p_node->type); - if (!strcmp(p_node->type, "int")) { + printf("Value(type: %d): ", p_node->type); + if (p_node->type == INT) { printf("%d", *(int *)(p_node->value)); } - else if (!strcmp(p_node->type, "double")) { + else if (p_node->type == DOUBLE) { printf("%a\n", *(double *)(p_node->value)); } - else if (!strcmp(p_node->type, "string")) { + else if (p_node->type == STRING) { printf("%s\n", (char *)(p_node->value)); } - else if (!strcmp(p_node->type, "pointer")) { - printf("%s\n", (char *)(p_node->value)); + else if (p_node->type == POINTER) { + printf("%p\n", (char *)(p_node->value)); } - else if (!strcmp(p_node->type, "list")) { + else if (p_node->type == LIST) { printList((List *)p_node->value); } } @@ -206,7 +206,7 @@ Node *findByIntForNode(List *p_list, int target) { Node *t_node; int *p_target = (int *)malloc(sizeof(int)); *p_target = target; - t_node = findByValue(p_list, "int", p_target); + t_node = findByValue(p_list, INT, p_target); free(p_target); return t_node; } @@ -215,7 +215,7 @@ Node *findByDoubleForNode(List *p_list, double target) { Node *t_node; double *p_target = (double *)malloc(sizeof(double)); *p_target = target; - t_node = findByValue(p_list, "double", p_target); + t_node = findByValue(p_list, DOUBLE, p_target); free(p_target); return t_node; } @@ -223,21 +223,21 @@ Node *findByDoubleForNode(List *p_list, double target) { Node *findByStringForNode(List *p_list, char *target) { Node *t_node; char *p_temp = (char *)malloc(sizeof(char)*(strlen(target) + 1)); - strcpy_s(p_temp, sizeof(p_temp), target); - t_node = findByValue(p_list, "string", p_temp); + strcpy(p_temp, target); + t_node = findByValue(p_list, STRING, p_temp); free(p_temp); return t_node; } Node *findByPointerForNode(List *p_list, void *target) { - Node *t_node = findByValue(p_list, "pointer", target); + Node *t_node = findByValue(p_list, POINTER, target); return t_node; } -int addValueForComplex(Node * p_node, char *type, void *value) { +int addValueForComplex(Node * p_node, int type, void *value) { List *c_list; Node *c_node; - if (!strcmp(p_node->type, "list")) { + if (p_node->type == LIST) { c_list = (List *)p_node->value; c_node = initNode(); initMallocValueForNode(c_node, type, value); @@ -248,38 +248,38 @@ int addValueForComplex(Node * p_node, char *type, void *value) { } int addIntForComplex(Node *p_node, int temp) { - if (!strcmp(p_node->type, "list")) { + if (p_node->type == LIST) { int *p_temp = (int *)malloc(sizeof(int)); *p_temp = temp; - addValueForComplex(p_node, "int", p_temp); + addValueForComplex(p_node, INT, p_temp); return 0; } return -1; } int addDoubleForComplex(Node *p_node, double temp) { - if (!strcmp(p_node->type, "list")) { + if (p_node->type == LIST) { double *p_temp = (double *)malloc(sizeof(double)); *p_temp = temp; - addValueForComplex(p_node, "double", p_temp); + addValueForComplex(p_node, DOUBLE, p_temp); return 0; } return -1; } int addStringForComplex(Node *p_node, char *temp) { - if (!strcmp(p_node->type, "list")) { + if (p_node->type == LIST) { char *p_temp = (char *)malloc(sizeof(strlen(temp) + 1)); - strcpy_s(p_temp, sizeof(p_temp), temp); - addValueForComplex(p_node, "string", p_temp); + strcpy(p_temp, temp); + addValueForComplex(p_node, STRING, p_temp); return 0; } return -1; } int addPointerForComplex(Node *p_node, void *temp) { - if (!strcmp(p_node->type, "list")) { - addValueForComplex(p_node, "pointer", temp); + if (p_node->type == LIST) { + addValueForComplex(p_node, POINTER, temp); return 0; } return -1; @@ -289,7 +289,7 @@ List *m_findByInt(List* p_list, int temp) { int *p_temp = (int *)malloc(sizeof(int)); List *t_list; *p_temp = temp; - t_list = mply_findByValue(p_list, "int", (void *)p_temp); + t_list = mply_findByValue(p_list, INT, (void *)p_temp); free(p_temp); return t_list; } @@ -298,7 +298,7 @@ List *m_findByDouble(List* p_list, double temp) { List *t_list; double *p_temp = (double *)malloc(sizeof(double)); *p_temp = temp; - t_list = mply_findByValue(p_list, "double", (void *)p_temp); + t_list = mply_findByValue(p_list, DOUBLE, (void *)p_temp); free(p_temp); return t_list; } @@ -306,14 +306,14 @@ List *m_findByDouble(List* p_list, double temp) { List *m_findByString(List* p_list, char *temp) { List *t_list; char *p_temp = (char *)malloc(sizeof(char)*(strlen(temp) + 1)); - strcpy_s(p_temp, sizeof(p_temp), temp); - t_list = mply_findByValue(p_list, "string", (void *)p_temp); + strcpy(p_temp, temp); + t_list = mply_findByValue(p_list, STRING, (void *)p_temp); free(p_temp); return t_list; } List *m_findByPointer(List* p_list, void *temp) { - List *t_list = mply_findByValue(p_list, "double", (void *)temp); + List *t_list = mply_findByValue(p_list, DOUBLE, (void *)temp); return t_list; } @@ -331,21 +331,21 @@ unsigned long long getIndexByNode(List *p_list, Node *p_node) { List *m_findByIntForNode(List* p_list, int temp) { int *p_temp = (int *)malloc(sizeof(int)); *p_temp = temp; - return mply_findByValue(p_list, "int", (void *)p_temp); + return mply_findByValue(p_list, INT, (void *)p_temp); } List *m_findByDoubleForNode(List* p_list, double temp) { double *p_temp = (double *)malloc(sizeof(double)); *p_temp = temp; - return mply_findByValue(p_list, "double", (void *)p_temp); + return mply_findByValue(p_list, DOUBLE, (void *)p_temp); } List *m_findByStringForNode(List* p_list, char *temp) { char *p_temp = (char *)malloc(sizeof(char) * (strlen(temp) + 1)); - strcpy_s(p_temp, sizeof(p_temp), temp); - return mply_findByValue(p_list, "string", (void *)p_temp); + strcpy(p_temp, temp); + return mply_findByValue(p_list, STRING, (void *)p_temp); } List *m_findByPointerForNode(List* p_list, void *temp) { - return mply_findByValue(p_list, "pointer", (void *)temp); + return mply_findByValue(p_list, POINTER, (void *)temp); } diff --git a/list/list_expand.h b/list/list_expand.h index e2f32e93f8cb09789ef0ab4230bd9d77b18a929c..a9d210f4e06f12ac35656ff86326c057b5e8acb8 100644 GIT binary patch literal 2366 zcmbW3T~FFj7=Z7a^glFuQwfg6&I1kB5*hDo7uj7$3)X-<#PJoIl1F zn|N!#Udh%g->|U<2RQq;v5~WKRb0Jp{Mv-mPR^8;eyz%)M0Y)D0I`Ah(dP7|f?{Gs zLn&Q|#21o6peNG?_Q`NogLTSDaY<98p>Ul`exfZVRC$>KduR8>!0+;Y^@D7L1xb3b zpr++#TCz=JdV&JEtY;E(P+$o!k^9Ir^~xVip=`b8?;E^vN{zILA*B2BdPXzVR-uYZ zht`i9{CU$leCtLsyFOIMw{Kc~!A!Id*pWUQxMkai?D&5mx$PgGG-)yug6D7<@Whum z4Ud-)2nuPGQesG!1XV*Zx*;_;PphU;s^1#cZOJ@2Hw!gZ7bdV1OXPW=pp}}d9b2mx zZb|)EwlxpVrR>2(TbG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SQ1KWyy!H=;1YZ#6~(PUo{ZhilmOr?NI&?BSu}GX{?w8q64+ST;rAbZH#~;UTAm Zaz26wf9{ofL(s@gP4v;Y;lduTf`7E@69xsMWUWZU|!{)Hg%k9Ia5`gg*(6Ol`?@wRGq0-n30u4wM<~yVj3vRsTVQK zxzyRFU9?5~YpB||%V$oC<}>(=G2pq%?Yc1Gc!SfpO0z4@?2(cwVlvDhbEcJ~e(YGy zHO^3qG$*3XFJi2A8fh6AIu+?LBz04Cn2ejixFO+dk2vve-@$PcsxakQg!|~N9b}R5 zn3FxvbE5C7_sTK99I?ew@j5fo{I=()gtB9F@5bEZh?SLiMY~irHS4r9lmUyq4jQ~D zCY;s!znx<^6{SrPx;Oq#Na1#?I;lQ-|Z znG{I9nUscWAC$q@a=a0uz=4z=pn1N%duZ=P5d$QBiI<{HSyl#pNL#DVt|L{B8zI7n z)6C$*aq2@ny8f*ttMsRUxF+&=Ag#byI?NlYIz1r;z@dHbjIsSC#e{QovZz3wIy2?O z9}SSC&!HAy&^$%Sdfm>yPF74BO@}bfJ`y*`U|mw;4x>`TCrBg=>AGdRSGCCKlxI^* zKD8UckE!1m?rLw33BAoVuJt^*9Wa*Xu!A2nh};Xgvu@VRCSoDGi3qNAlONZfck`4$ kW*sJE{81a-dA(MW85czA=eJoVDKse@ppyCfN062H1_^r2^Z)<= literal 1276 zcmbVMT}#725S(Yh{}AX)Euud_5kwF{^d;hJiRnjzu?_hsO7X9&Gj}~N*HEoeN-uk} zvopKfe0~g&V}TR}T1+rSgmctrcrJMJgcD@Az#$IISLhk>Le7Yd@qkNQ;TB`uY!LQN ztYYgU#MR&pCGQ=NDppjG@;5T|6P};Ry1>$))`mUetv)T|HMPu5l?fvSaSJ|oPdPKs zf;_2G1-TgG1qt(%nQq}y!zNV`?=s>lo<@AOxV}iG3{dU)7w|iz--}!y7YEBWq-rBNyg_9type, "int")) return *(int *)p_snode->value; + if (p_snode->type == INT) return *(int *)p_snode->value; else return -1; } double getValueByDoubleForSNode(SNode *p_snode) { - if (!strcmp(p_snode->type, "double")) return *(double *)p_snode->value; + if (p_snode->type == DOUBLE) return *(double *)p_snode->value; else return -1; } char *getValueByStringForSNode(SNode *p_snode) { - if (!strcmp(p_snode->type, "int")) return (char *)p_snode->value; + if (p_snode->type == STRING) return (char *)p_snode->value; else return NULL; } void *getValueByPointerForSNode(SNode *p_snode) { - if (!strcmp(p_snode->type, "int")) return (void *)p_snode->value; + if (p_snode->type == POINTER) return (void *)p_snode->value; else return NULL; -} \ No newline at end of file +} diff --git a/stack/stack_expand.h b/stack/stack_expand.h index 300b68efb06b1eb147a2e3b461a5e23cdbe412f2..ba739f79634f43b2fb56b830143985bf0aec42da 100644 GIT binary patch literal 401 zcmZvYK?=e!6h!wqMKGJ#MLmEbs8tl96e{Yj)aKU&%a63F=VDnR(0%VX8&} zHO&u;)xKDtvqhQ|Tf(fS5PoIC6jn_yfX+J8D!j&WK4_!Pl+`VkBSP|2TPW(#o|7_i zhlVROF0G7w!c7-1YEEmMx6}ex_|MwEUr!Z~(DydIfVVn;w=g+q}`O+rvMr tY>Kb@!u*T?>5GRvzb63t0R#9M79a@&6so3^h`Jvu;CU}m6p}_0@&;<>h1dW9 literal 838 zcma))!AiqW5Jk^g@E=0m#4hXyD1ur=5u^}NccGfJ6{Sji75#bj&P#+T4fO3Y;m(~q z=gsfW9?vX!;*}K@H5o^I5NP86IR`8_W|ti{m4m39s{1AC22uB~oypf6XYwq#<%Bb? zDLLnXiK-jMsxCY4R%ux*!#2ImDCF?gWgaTYva9ZuJSg>*{si*4M_`}BIB8qgSS~9b z#iLel<*HPN!qLmcX2Dc6Glt0-CYov_f-*Ep@fquC&BF+^nvA)0fjiBySFAbZyW9Rk zosA=vyKkS!@7eF?xum-K-TN|nQmLMvMW5$7yHwZqW@|C8MAa^Kr1#3)eV5|;#k&}r Mrqrt%zfruYKZPxbvH$=8 diff --git a/test.c b/test.c index 5347f93..210d23f 100644 --- a/test.c +++ b/test.c @@ -2,7 +2,6 @@ int list(void) { - int i; List *t_list, *m_list;; init_rand(); safeModeForNode(1); @@ -20,7 +19,7 @@ int list(void) { insertInTail(t_list,t_node); initMalllocValue(t_node,(void *)"there");*/ - for (i = 0; i < 12; i++) { + for (int i = 0; i < 12; i++) { insertInHead(t_list, nodeWithInt(i)); insertInTail(t_list, nodeWithInt(i)); } @@ -87,4 +86,4 @@ int main(int argc, char **argv) { tree(); getchar(); return 0; -} \ No newline at end of file +} diff --git a/test.h b/test.h index 3e171ce..eed9bbc 100644 --- a/test.h +++ b/test.h @@ -12,5 +12,4 @@ int stack(void); int list(void); int tree(void); -#endif // TEST_H - +#endif // TEST_H diff --git a/tree/tree.c b/tree/tree.c index bab8420..5171631 100644 --- a/tree/tree.c +++ b/tree/tree.c @@ -1,8 +1,8 @@ #include"tree.h" -unsigned long long target_id = 0; -TNode *target_value_id = NULL; -int if_safeModeForTree = 0; +static unsigned long long target_id = 0; +static TNode *target_value_id = NULL; +static int if_safeModeForTree = 0; int safeModeForTree(int ifon) { if (ifon == 1) { @@ -36,21 +36,21 @@ TNode *initTNode(void) { p_tnode->father = NULL; p_tnode->if_malloc = 0; p_tnode->value = NULL; - p_tnode->type = NULL; + p_tnode->type = VOID; p_tnode->home = initList(); p_tnode->room = NULL; if (if_safeModeForTree) { if (if_safeModeForNode) { if_safeModeForNode = 0; s_node = initNode(); - initMallocValueForNode(s_node, "pointer", (void *)p_tnode); + initMallocValueForNode(s_node, POINTER, (void *)p_tnode); insertInTail(tnode_list, s_node); if_safeModeForNode = 1; } else { s_node = initNode(); - initMallocValueForNode(s_node, "pointer", (void *)p_tnode); + initMallocValueForNode(s_node, POINTER, (void *)p_tnode); insertInTail(tnode_list, s_node); } } @@ -66,21 +66,21 @@ Tree *initTree(void) { if (if_safeModeForNode) { if_safeModeForNode = 0; s_node = initNode(); - initMallocValueForNode(s_node, "pointer", (void *)p_tree); + initMallocValueForNode(s_node, POINTER, (void *)p_tree); if_safeModeForNode = 1; insertInTail(tree_list, s_node); } else { s_node = initNode(); - initMallocValueForNode(s_node, "pointer", (void *)p_tree); + initMallocValueForNode(s_node, POINTER, (void *)p_tree); insertInTail(tree_list, s_node); } } return p_tree; } -int *initMallocValueForTNode(TNode *p_tnode, char *type, void *value) { +int *initMallocValueForTNode(TNode *p_tnode, int type, void *value) { p_tnode->type = type; p_tnode->value = value; p_tnode->if_malloc = 1; @@ -89,7 +89,7 @@ int *initMallocValueForTNode(TNode *p_tnode, char *type, void *value) { int addChildInLeft(TNode *f_tnode, TNode *c_tnode) { Node *p_node = initNode(); - initMallocValueForNode(p_node, "pointer", c_tnode); + initMallocValueForNode(p_node, POINTER, c_tnode); insertInHead(f_tnode->home, p_node); c_tnode->father = f_tnode; c_tnode->room = p_node; @@ -99,7 +99,7 @@ int addChildInLeft(TNode *f_tnode, TNode *c_tnode) { int addChildInRight(TNode *f_tnode, TNode *c_tnode) { Node *p_node = initNode(); - initMallocValueForNode(p_node, "pointer", c_tnode); + initMallocValueForNode(p_node, POINTER, c_tnode); insertInTail(f_tnode->home, p_node); c_tnode->father = f_tnode; c_tnode->room = p_node; @@ -155,8 +155,8 @@ TNode *getChildById(TNode *p_tnode, unsigned long long id) { return NULL; } -int _dogetChildById(const char *type, void *value) { - if (!strcmp(type, "pointer")) { +int _dogetChildById(int type, void *value) { + if (type == POINTER) { TNode *p_tode = (TNode *)value; if (p_tode->id == target_id) { target_value_id = p_tode; @@ -166,12 +166,11 @@ int _dogetChildById(const char *type, void *value) { return 0; } -char *target_type = NULL; -void *target_value = NULL; -TNode *target_value_value = NULL; -int _dogetChildByValue(const char *type, void *value); +static int target_type = VOID; +static void *target_value = NULL; +static TNode *target_value_value = NULL; -TNode *getChildByValue(TNode *p_tnode, char *type, void *value) { +TNode *getChildByValue(TNode *p_tnode, int type, void *value) { List *p_home = p_tnode->home; target_value = value; target_type = type; @@ -183,17 +182,17 @@ TNode *getChildByValue(TNode *p_tnode, char *type, void *value) { return NULL; } -int _dogetChildByValue(const char *type, void *value) { - if (!strcmp(type, target_type)) { +int _dogetChildByValue(int type, void *value) { + if (type == target_type) { TNode *p_tode = (TNode *)value; - if (!strcmp((char *)target_value, "int")) { + if (target_type == INT) { if (*(int *)p_tode->value == *(int *)target_value) { target_value_value = p_tode; return -1; } } - else if (!strcmp((char *)target_value, "double")) + else if (target_type == DOUBLE) { if (*(double *)p_tode->value == *(double *)target_value) { @@ -201,7 +200,7 @@ int _dogetChildByValue(const char *type, void *value) { return -1; } } - else if (!strcmp((char *)target_value, "string")) + else if (target_type == STRING) { if (!strcmp((char *)p_tode->value, (char *)target_value)) { @@ -209,7 +208,7 @@ int _dogetChildByValue(const char *type, void *value) { return -1; } } - else if (!strcmp((char *)target_value, "pointer")) + else if (target_type == POINTER) { if (p_tode->value == target_value) { @@ -235,7 +234,7 @@ int removeChildById(TNode *p_tnode, unsigned long long id) { return -1; } -int removeChildByValue(TNode *p_tnode, char *type, void *value) { +int removeChildByValue(TNode *p_tnode, int type, void *value) { TNode *t_tnode = getChildByValue(p_tnode, type, value); if (t_tnode != NULL) { TNode *p_fnode = t_tnode->father; @@ -376,8 +375,8 @@ int releaseTNode(TNode *p_tnode) { if (p_tnode->father != NULL) { removeChildById(p_tnode->father, p_tnode->id); } - if (strcmp(p_tnode->type, "pointer")) { - if (!strcmp(p_tnode->type, "list")) { + if (p_tnode->type != POINTER) { + if (p_tnode->type == LIST) { releaseList((List *)p_tnode->value); } else { @@ -385,7 +384,7 @@ int releaseTNode(TNode *p_tnode) { } } p_tnode->value = NULL; - p_tnode->type = NULL; + p_tnode->type = VOID; p_tnode->id = 0; p_tnode->if_malloc = 0; free(p_tnode); @@ -416,8 +415,8 @@ int releaseOnlyTree(Tree *p_tree) { int releaseOnlyTNode(TNode *p_tnode) { releaseList(p_tnode->home); if (p_tnode->if_malloc) { - if (strcmp(p_tnode->type, "pointer")) { - if (!strcmp(p_tnode->type, "list")) { + if (p_tnode->type != STRING) { + if (p_tnode->type == LIST) { releaseList((List *)p_tnode->value); } else { @@ -426,7 +425,7 @@ int releaseOnlyTNode(TNode *p_tnode) { } } p_tnode->value = NULL; - p_tnode->type = NULL; + p_tnode->type = VOID; p_tnode->id = 0; p_tnode->if_malloc = 0; free(p_tnode); diff --git a/tree/tree.h b/tree/tree.h index c978da4..c2d950f 100644 --- a/tree/tree.h +++ b/tree/tree.h @@ -1,18 +1,8 @@ -<<<<<<< HEAD -// -// tree.h -// ZE-Standard-Libraries -// -// Created by 胡一兵 on 2018/6/11. -// Copyright © 2018年 ZE. All rights reserved. -// +#ifndef TREE_H +#define TREE_H -#ifndef tree_h -#define tree_h #include #include "../list/list_expand.h" -#ifndef TREE_H -#define TREE_H typedef struct tree_node { @@ -21,7 +11,7 @@ typedef struct tree_node struct tree_node *father; Node *room; unsigned long long child_num; - char *type; + int type; void *value; int if_malloc; }TNode; @@ -38,7 +28,7 @@ int releaseAllForTree(void); TNode *initTNode(void); Tree *initTree(void); -int *initMallocValueForTNode(TNode *p_tnode, char *type, void *value); +int *initMallocValueForTNode(TNode *p_tnode, int type, void *value); int addChildInLeft(TNode *f_tnode, TNode *c_tnode); int addChildInRight(TNode *f_tnode, TNode *c_tnode); @@ -47,30 +37,30 @@ 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 *getChildByValue(TNode *p_tnode, int 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 removeChildByValue(TNode *p_tnode, int 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)); int TreeTravel(Tree *p_tree, int(*func)(TNode *, unsigned long long height)); -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)); +int _dogetChildById(int type, void *value); +int _dogetChildByValue(int type, void *value); +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)); int releaseTree(Tree *p_tree); int releaseOnlyTree(Tree *p_tree); -int releaseTNode(TNode *p_tnode); -static int releaseOnlyTNode(TNode *p_tnode); +int releaseTNode(TNode *p_tnode); +int releaseOnlyTNode(TNode *p_tnode); int setRoot(Tree *p_tree, TNode *p_tnode); -static char *target_type; +static int target_type; static void *target_value; static TNode *target_value_value; @@ -83,4 +73,3 @@ static int if_safeModeForTree; #endif ->>>>>>> 30b15314d8173f7cdfb24ab7f9250435ae2db90c diff --git a/tree/tree_expand.c b/tree/tree_expand.c index 353526a..0ef44a2 100644 --- a/tree/tree_expand.c +++ b/tree/tree_expand.c @@ -4,7 +4,7 @@ TNode *tnodeWithInt(int temp) { TNode *p_tnode = initTNode(); int *p_temp = (int *)malloc(sizeof(int)); *p_temp = temp; - initMallocValueForTNode(p_tnode, "int", p_temp); + initMallocValueForTNode(p_tnode, INT, p_temp); return p_tnode; } @@ -12,46 +12,46 @@ TNode *tnodeWithDouble(double temp) { TNode *p_tnode = initTNode(); double *p_temp = (double *)malloc(sizeof(double)); *p_temp = temp; - initMallocValueForTNode(p_tnode, "double", p_temp); + initMallocValueForTNode(p_tnode, DOUBLE, p_temp); return p_tnode; } TNode *tnodeWithString(char *temp) { TNode *p_tnode = initTNode(); char *p_temp = (char *)malloc(sizeof(temp)); - strcpy_s(p_temp, sizeof(p_temp), temp); - initMallocValueForTNode(p_tnode, "double", p_temp); + strcpy(p_temp, temp); + initMallocValueForTNode(p_tnode, STRING, p_temp); return p_tnode; } TNode *tnodeWithPointer(void *temp) { TNode *p_tnode = initTNode(); - initMallocValueForTNode(p_tnode, "pointer", temp); + initMallocValueForTNode(p_tnode, POINTER, temp); return p_tnode; } int getValueByIntForTree(TNode *p_tnode) { - if (!strcmp(p_tnode->type, "int")) { + if (p_tnode->type == INT) { return *(int *)p_tnode->value; } return -1; } double getValueByDoubleForTree(TNode *p_tnode) { - if (!strcmp(p_tnode->type, "double")) { + if (p_tnode->type == DOUBLE) { return *(double *)p_tnode->value; } return -1; } char *getValueByStringForTree(TNode *p_tnode) { - if (!strcmp(p_tnode->type, "string")) { + if (p_tnode->type == STRING) { return (char *)p_tnode->value; } return NULL; } void *getValueByPointerForTree(TNode *p_tnode) { - if (!strcmp(p_tnode->type, "pointer")) { + if (p_tnode->type == POINTER) { return p_tnode->value; } return NULL; @@ -70,17 +70,17 @@ int printTNode(TNode *p_tnode, int priority) { if (p_tnode->if_malloc) { printf("YES\n"); for (i = 0; i < priority + 1; i++) printf(" "); - printf("Value(type: %s): ", p_tnode->type); - if (!strcmp(p_tnode->type, "int")) { + printf("Value(type: %d): ", p_tnode->type); + if (p_tnode->type == INT) { printf("%d\n", *(int *)(p_tnode->value)); } - else if (!strcmp(p_tnode->type, "double")) { + else if (p_tnode->type == DOUBLE) { printf("%a\n", *(double *)(p_tnode->value)); } - else if (!strcmp(p_tnode->type, "string")) { + else if (p_tnode->type == STRING) { printf("%s\n", (char *)(p_tnode->value)); } - else if (!strcmp(p_tnode->type, "pointer")) { + else if (p_tnode->type == POINTER) { printf("%p\n", (char *)(p_tnode->value)); } } @@ -108,17 +108,17 @@ int printTNodeWithHome(TNode *p_tnode,int priority) { if (p_tnode->if_malloc) { printf("YES\n"); for (i = 0; i < priority + 1; i++) printf(" "); - printf("Value(type: %s): ", p_tnode->type); - if (!strcmp(p_tnode->type, "int")) { + printf("Value(type: %d): ", p_tnode->type); + if (p_tnode->type == INT) { printf("%d\n", *(int *)(p_tnode->value)); } - else if (!strcmp(p_tnode->type, "double")) { + else if (p_tnode->type == DOUBLE) { printf("%a\n", *(double *)(p_tnode->value)); } - else if (!strcmp(p_tnode->type, "string")) { + else if (p_tnode->type == STRING) { printf("%s\n", (char *)(p_tnode->value)); } - else if (!strcmp(p_tnode->type, "pointer")) { + else if (p_tnode->type == POINTER) { printf("%p\n", (char *)(p_tnode->value)); } } @@ -164,17 +164,17 @@ int printTNodeWithFamily(TNode *p_tnode, int priority) { if (p_tnode->if_malloc) { printf("YES\n"); for (i = 0; i < priority + 1; i++) printf(" "); - printf("Value(type: %s): ", p_tnode->type); - if (!strcmp(p_tnode->type, "int")) { + printf("Value(type: %d): ", p_tnode->type); + if (p_tnode->type == INT) { printf("%d\n", *(int *)(p_tnode->value)); } - else if (!strcmp(p_tnode->type, "double")) { + else if (p_tnode->type == DOUBLE) { printf("%a\n", *(double *)(p_tnode->value)); } - else if (!strcmp(p_tnode->type, "string")) { + else if (p_tnode->type == STRING) { printf("%s\n", (char *)(p_tnode->value)); } - else if (!strcmp(p_tnode->type, "pointer")) { + else if (p_tnode->type == POINTER) { printf("%p\n", (char *)(p_tnode->value)); } } @@ -211,4 +211,4 @@ int printTree(Tree *p_tree) { printf("Tree(id: %llu)",p_tree->id); printTNodeWithFamily(p_tree->root,0); return 0; -} \ No newline at end of file +} diff --git a/type/type.h b/type/type.h new file mode 100644 index 0000000..199e088 --- /dev/null +++ b/type/type.h @@ -0,0 +1,21 @@ +// +// type.h +// ZE-Standard-Libraries +// +// Created by 胡一兵 on 2018/7/23. +// Copyright © 2018年 ZE. All rights reserved. +// + +#ifndef type_h +#define type_h + +#define VOID 0 +#define INT 1 +#define DOUBLE 2 +#define STRING 3 +#define POINTER 4 +#define LIST 5 + + + +#endif /* type_h */