From e836dfc4e2c4d89b3392d8314b964a564f696792 Mon Sep 17 00:00:00 2001 From: localhorst Date: Tue, 7 May 2019 23:04:36 +0200 Subject: [PATCH] nodes in own .c file --- src/nodes.c | 72 +++++++++++++++++++++++++++ src/routing4SITA | Bin 20936 -> 21288 bytes src/routing4SITA.c | 121 ++++++++------------------------------------- src/routing4SITA.h | 28 +++-------- 4 files changed, 99 insertions(+), 122 deletions(-) create mode 100644 src/nodes.c diff --git a/src/nodes.c b/src/nodes.c new file mode 100644 index 0000000..7df28ca --- /dev/null +++ b/src/nodes.c @@ -0,0 +1,72 @@ +#include +#include "routing4SITA.h" + +NODE_t* getStartNode() { + + static NODE_t* start; + static NODE_t* g; + static NODE_t* f; + static NODE_t* e; + static NODE_t* d; + static NODE_t* c; + static NODE_t* b; + static NODE_t* a; + static NODE_t* end; + + start = (NODE_t*) malloc(sizeof(NODE_t)); + a = (NODE_t*) malloc(sizeof(NODE_t)); + b = (NODE_t*) malloc(sizeof(NODE_t)); + c = (NODE_t*) malloc(sizeof(NODE_t)); + d = (NODE_t*) malloc(sizeof(NODE_t)); + e = (NODE_t*) malloc(sizeof(NODE_t)); + f = (NODE_t*) malloc(sizeof(NODE_t)); + g = (NODE_t*) malloc(sizeof(NODE_t)); + end = (NODE_t*) malloc(sizeof(NODE_t)); + + end->id = 8; + end->nodescount = 0; + + g->id = 7; + g->nodescount = 0; + + f->id = 6; + f->nodescount = 1; + f->nodesnext[0] = end; + f->nodescost[0] = 7; + + e->id = 5; + e->nodescount = 0; + + d->id = 4; + d->nodescount = 0; + + c->id = 3; + c->nodescount = 1; + c->nodesnext[0] = end; + c->nodescost[0] = 3; + + b->id = 2; + b->nodescount = 3; + b->nodesnext[0] = e; + b->nodescost[0] = 11; + b->nodesnext[1] = f; + b->nodescost[1] = 42; + b->nodesnext[2] = g; + b->nodescost[2] = 8; + + a->id = 1; + a->nodescount = 2; + a->nodesnext[0] = c; + a->nodescost[0] = 15; + a->nodesnext[1] = d; + a->nodescost[1] = 27; + + start->id = 0; + start->nodescount = 2; + start->nodesnext[0] = a; + start->nodescost[0] = 72; + start->nodesnext[1] = b; + start->nodescost[1] = 32; + + return start; +} diff --git a/src/routing4SITA b/src/routing4SITA index 2207e95fa79d0816a82f95abaf06ef42020fa855..cb3de3d1094f6ced8dc324aae13072d9f6e31b04 100755 GIT binary patch delta 2359 zcmZ8i3v3is6utA>ZM(G4-R`F)C1naVErphTXp2_p^y}2L&;}X_KU?VXiG)vSltf@b zKv~z4!c$|6fucqs5-E&EFiHiL)<9GYMl=zFgs_k%7O7f@?0D~cvm4o$%$#@6xxbzF z*`aroBkw7_c`VepKmY2uo&*r1CxNFah4w3oG_UYRr9wHvcPfYMb&`TQK8=0g-hPk2 zyy@p_`))2&-3cRme0NWLILipJH^3v^uReiSU;u*90Y?}5-EDHZA|Z}AJGGsKJ9aAa7K`U!O(#)cev)T z&0#*@Jc?O2viwan~O9)&pMdZcmBEhTs8z+g;>u(*rjKim3MJ zztoBC*BJnkxGssyQQ`+lT!<29C2=lF^h@G&lsF`b{wT3e67O4tA41zCb1>?%P7<#n zp$BdI5C(xh0vbEX(Bj39589p)QlgZWKP2fwqIJZmN-5DYqE&#F9`uwG1pF;YNM#BK z)yiZe3vAMRZ2JEz{!SK9eT@3?A!$HJaZ)-dC9C4QXko>#2?CU5Y4E#B(nDq2|kCV{MdQRr%_%zZ}c-$|Wn9}{{`rqo|23#XLD77$V-_45=H^lWV) zl)2Xm2UVBuOQb`m)G2qP&~sF&SE9A-%T=k9ccTsbH@7GKR4zc9-cvxhplR9-eb;bO z$hc=Ddp@=wQ1w=rw?SR++tRJB-_YsX44`DjRnj@8Wgq&(Gr)rtpyh zo$dA-j}@M0_T6~3(1_=UAJ6nKp!R7|0aQ!r;MFXhw-l@Py%u8=OmFc~hBs1W$u+ja z%d<)|$eLa1W6fTEsPvJ^KFiy!w6SgARu;1D_-tMItExfik?=8MPhX2Xp*TnEwEq-GRe?#(1U`vcJYz6Fy;qO}f z-WdMA#r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m87B iQ{#FZuWC56XS2f|5&&5b-|ne#mhQ5$7bXJsOTJvH6 diff --git a/src/routing4SITA.c b/src/routing4SITA.c index 9f8e14d..f736a66 100644 --- a/src/routing4SITA.c +++ b/src/routing4SITA.c @@ -1,4 +1,3 @@ - #include #include #include @@ -10,131 +9,51 @@ void *Search(void* arguments); int main() { printf("hello world!\n"); - - NODE_t end; - end.id = 8; - end.nodescount = 0; - NODE_t g; - g.id = 7; - g.nodescount = 0; - - NODE_t f; - f.id = 6; - f.nodescount = 1; - f.nodesnext[0] = &end; - f.nodescost[0] = 7; - - NODE_t e; - e.id = 5; - e.nodescount = 0; - - NODE_t d; - d.id = 4; - d.nodescount = 0; - - NODE_t c; - c.id = 3; - c.nodescount = 1; - c.nodesnext[0] = &end; - c.nodescost[0] = 3; - - NODE_t b; - b.id = 2; - b.nodescount = 3; - b.nodesnext[0] = &e; - b.nodescost[0] = 11; - b.nodesnext[1] = &f; - b.nodescost[1] = 42; - b.nodesnext[2] = &g; - b.nodescost[2] = 8; - - NODE_t a; - a.id = 1; - a.nodescount = 2; - a.nodesnext[0] = &c; - a.nodescost[0] = 15; - a.nodesnext[1] = &d; - a.nodescost[1] = 27; - - NODE_t start; - start.id = 0; - start.nodescount = 2; - start.nodesnext[0] = &a; - start.nodescost[0] = 72; - start.nodesnext[1] = &b; - start.nodescost[1] = 32; - - - pthread_t startThread; - THREAD_DATA_t* data; - data = (THREAD_DATA_t*) malloc(sizeof(THREAD_DATA_t)); - - data->node = &start; + data->node = getStartNode(); data->cost = 0; - + pthread_create(&startThread, NULL, Search, data); - - //pthread_join(startThread,NULL); - - for(;;){ - + + for(;;) { + } - + return 0; } -void *Search(void* arguments){ - - +void *Search(void* arguments) { + THREAD_DATA_t *data = (THREAD_DATA_t*) arguments; - - printf("Number: %i\n", data->node->id); printf("Cost to this node: %i\n", data->cost); - - if(data->node->id == 8){ - printf("End found! Cost: %i\ns", data->cost); + + if(data->node->id == 8) { + printf("End found! Cost: %i\n", data->cost); return NULL; } - - if(data->node->nodescount == 0){ + + if(data->node->nodescount == 0) { printf("No next nodes\n"); return NULL; } - + pthread_t threads[data->node->nodescount]; - for(int i = 0; i < data->node->nodescount; i++){ - - THREAD_DATA_t* nextdata; - - nextdata = (THREAD_DATA_t*) malloc(sizeof(THREAD_DATA_t)); - - nextdata->node = (data->node->nodesnext[i]); - - nextdata->cost = data->node->nodescost[i] + data->cost; - - //nextdata->cost = 42; - - pthread_create(&threads[i], NULL, Search, nextdata); - - } - - /* for(int i = 0; i < data->node->nodescount; i++) { - pthread_join(threads[i],NULL); + THREAD_DATA_t* nextdata; + nextdata = (THREAD_DATA_t*) malloc(sizeof(THREAD_DATA_t)); + nextdata->node = (data->node->nodesnext[i]); + nextdata->cost = data->node->nodescost[i] + data->cost; + pthread_create(&threads[i], NULL, Search, nextdata); } - */ - - + return NULL; - } diff --git a/src/routing4SITA.h b/src/routing4SITA.h index eca658c..338dd04 100644 --- a/src/routing4SITA.h +++ b/src/routing4SITA.h @@ -1,18 +1,18 @@ #ifndef ROUTING4SITA_H -#define ROUTING4SITA_H - +#define ROUTING4SITA_H #define MAX_CHILDREN 3 - typedef struct node NODE_t; typedef struct threadData THREAD_DATA_t; +extern NODE_t* getStartNode(); + struct node { - int id; - int nodescount; - NODE_t* nodesnext[MAX_CHILDREN]; - int nodescost[MAX_CHILDREN]; + int id; + int nodescount; + NODE_t* nodesnext[MAX_CHILDREN]; + int nodescost[MAX_CHILDREN]; }; @@ -21,18 +21,4 @@ struct threadData { int cost; }; - - - - - - - - - - - - - - #endif /* ROUTING4SITA_H */