X-Git-Url: https://git.wirehaze.ovh/graph-theory.git/blobdiff_plain/9bd63c3cb2b06bddf6159fd4d233196057a3633d..8285b08b1ca5d40e691bdc6bcd0e0a6dfd904135:/graph/adj.c diff --git a/graph/adj.c b/graph/adj.c index ec9cd0c..e44f583 100644 --- a/graph/adj.c +++ b/graph/adj.c @@ -1,14 +1,17 @@ -#include "adj.h" -#include +#include "graph/adj.h" #include +#include struct graph * new_graph (unsigned int nv) { - struct graph *g; + struct graph *g; if (!nv) - return NULL; + { + errno = EINVAL; + return NULL; + } if (!(g = malloc (sizeof *g))) return NULL; @@ -30,10 +33,10 @@ new_arc (struct graph *g, unsigned int vi, unsigned int vj) struct edge *e; if (vi >= g->nv || vj >= g->nv) - return -EINVAL; + return -(errno = EINVAL); if (!(e = malloc (sizeof *e))) - return -ENOMEM; + return -errno; e->to = &g->v[vj]; e->next = g->v[vi].adj; @@ -47,11 +50,14 @@ new_edge (struct graph *g, unsigned int vi, unsigned int vj) { int err; + if (vi == vj) + return -(errno = EINVAL); + if ((err = new_arc (g, vi, vj))) return err; - if (vi != vj && (err = new_arc (g, vj, vi))) - return err; /* should delete the other arc but fuck it we ball */ + if ((err = new_arc (g, vj, vi))) + return err; return 0; }