-#include "adj.h"
-#include <stdlib.h>
+#include "graph/adj.h"
#include <errno.h>
+#include <stdlib.h>
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;
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;
{
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;
}