diff options
author | EliasFleckenstein03 <eliasfleckenstein@web.de> | 2020-09-28 15:18:36 +0200 |
---|---|---|
committer | EliasFleckenstein03 <eliasfleckenstein@web.de> | 2020-09-28 15:18:36 +0200 |
commit | 8430394c9d903a9ac246c47a31da59f774f6ae19 (patch) | |
tree | 61128641af553c86b0cc83ca15f9dbed3c4b21be | |
parent | 543d104fbc7a8fc0853f5237b9fecf58990af5ee (diff) | |
download | libscout-8430394c9d903a9ac246c47a31da59f774f6ae19.tar.xz |
First Prototype (unfinished)
-rw-r--r-- | scout.c | 67 | ||||
-rw-r--r-- | scout.h | 25 |
2 files changed, 92 insertions, 0 deletions
@@ -0,0 +1,67 @@ +#include <stdlib.h> +#include "scout.h" + +typedef struct scnode scnode; +typedef struct scway scway; +typedef struct scwaypoint scwaypoint; + +scway *scaddway(scnode *from, const scnode *to, int len) +{ + scway *way = malloc(sizeof(scway)); + way->lto = to; + way->alt = NULL; + way->len = len; + scway *apar, *par = NULL; + for (apar = from->way; apar != NULL; par = apar, apar = apar->alt); + if (par) + par->alt = way; + else + from->way = way; + return way; +} + +scwaypoint *__scallocwayp(const scnode *node, scway *way) +{ + scwaypoint *wayp = malloc(sizeof(scwaypoint)); + wayp->nod = node; + wayp->way = way; + wayp->nxt = NULL; + wayp->len = 0; +} + +scwaypoint *__scstackfindgetend(scwaypoint *stack, scway *way) +{ + scwaypoint *asptr, *sptr; + for (asptr = stack; asptr != NULL; sptr = asptr, asptr = asptr->nxt) + if (asptr->nod == way->lto) + return NULL; + return sptr; +} + +void __scstackfree(scwaypoint *stack) +{ + for (scwaypoint *sptr = stack; sptr != NULL; sptr = sptr->nxt) + free(sptr); +} + +int __scstackgetlen(scwaypoint *stack) +{ + for (scwaypoitn) +} + +scwaypoint *scout(const scnode *from, const scnode *to, scwaypoint *stack) +{ + scwaypoint *wayp = NULL; + if (from == to) + return __scallocwayp(from, NULL); + for (scway *way = from->way; way != NULL; way = way->alt) { + scwaypoint *stackend; + if ((stackend = __scstackfindgetend(stack, way)) == NULL) + continue; + + if (wayp && wayp->len <= (tway->len = __scstackgetlen(tway))) + __scstackfree(wayp); + wayp = twayp; + } + return wayp; +} @@ -0,0 +1,25 @@ +#ifndef _LIBSCOUT_H_ +#define _LIBSCOUT_H_ + +struct scnode { + struct scway *way; + void *dat; +}; + +struct scway { + const struct scnode *lto; + struct scway *alt; + int len; +}; + +struct scwaypoint { + const struct scnode *nod; + const struct scway *way; + struct scwaypoint *nxt; + int len; +}; + +struct scway *scaddway(struct scnode *, const struct scnode *, int); +struct scwaypoint *scout(const struct scnode *, const struct scnode *, struct scwaypoint *); + +#endif |