summaryrefslogtreecommitdiff
path: root/src/ipcpd/normal/graph.c
diff options
context:
space:
mode:
authorSander Vrijders <sander.vrijders@ugent.be>2017-03-29 16:20:06 +0000
committerdimitri staessens <dimitri.staessens@ugent.be>2017-03-29 16:20:06 +0000
commit489b6be608ce40d5249d95f77815be9b422995d5 (patch)
treee5de4d3cdc559a163455d383fac808080ed2f651 /src/ipcpd/normal/graph.c
parent3bc188d9ee4cc0fd70e5c1bd579f805df3359b60 (diff)
parentd90c66cc6beba511f6bcc48a3ea3fc4e774b5ab8 (diff)
downloadouroboros-489b6be608ce40d5249d95f77815be9b422995d5.tar.gz
ouroboros-489b6be608ce40d5249d95f77815be9b422995d5.zip
Merged in sandervrijders/ouroboros/be-unidirected-graph (pull request #432)
Be unidirected graph
Diffstat (limited to 'src/ipcpd/normal/graph.c')
-rw-r--r--src/ipcpd/normal/graph.c38
1 files changed, 32 insertions, 6 deletions
diff --git a/src/ipcpd/normal/graph.c b/src/ipcpd/normal/graph.c
index 5fd6fcb6..5de7c15b 100644
--- a/src/ipcpd/normal/graph.c
+++ b/src/ipcpd/normal/graph.c
@@ -1,7 +1,7 @@
/*
* Ouroboros - Copyright (C) 2016 - 2017
*
- * Graph structure
+ * Undirected graph structure
*
* Dimitri Staessens <dimitri.staessens@ugent.be>
* Sander Vrijders <sander.vrijders@ugent.be>
@@ -205,6 +205,7 @@ int graph_update_edge(struct graph * graph,
struct vertex * v;
struct edge * e;
struct vertex * nb;
+ struct edge * nb_e;
assert(graph);
@@ -237,9 +238,9 @@ int graph_update_edge(struct graph * graph,
e = add_edge(v, nb);
if (e == NULL) {
if (list_is_empty(&v->edges))
- del_vertex(graph, v);
+ del_vertex(graph, v);
if (list_is_empty(&nb->edges))
- del_vertex(graph, v);
+ del_vertex(graph, nb);
pthread_mutex_unlock(&graph->lock);
log_err("Failed to add edge.");
return -ENOMEM;
@@ -248,6 +249,23 @@ int graph_update_edge(struct graph * graph,
e->qs = qs;
+ nb_e = find_edge_by_addr(nb, s_addr);
+ if (nb_e == NULL) {
+ nb_e = add_edge(nb, v);
+ if (nb_e == NULL) {
+ del_edge(e);
+ if (list_is_empty(&v->edges))
+ del_vertex(graph, v);
+ if (list_is_empty(&nb->edges))
+ del_vertex(graph, nb);
+ pthread_mutex_unlock(&graph->lock);
+ log_err("Failed to add edge.");
+ return -ENOMEM;
+ }
+ }
+
+ nb_e->qs = qs;
+
pthread_mutex_unlock(&graph->lock);
return 0;
@@ -260,6 +278,7 @@ int graph_del_edge(struct graph * graph,
struct vertex * v;
struct edge * e;
struct vertex * nb;
+ struct edge * nb_e;
assert(graph);
@@ -286,14 +305,21 @@ int graph_del_edge(struct graph * graph,
return -1;
}
+ nb_e = find_edge_by_addr(nb, s_addr);
+ if (nb_e == NULL) {
+ pthread_mutex_unlock(&graph->lock);
+ log_err("No such edge.");
+ return -1;
+ }
+
del_edge(e);
+ del_edge(nb_e);
/* Removing vertex if it was the last edge */
if (list_is_empty(&v->edges))
- del_vertex(graph, v);
-
+ del_vertex(graph, v);
if (list_is_empty(&nb->edges))
- del_vertex(graph, v);
+ del_vertex(graph, nb);
pthread_mutex_unlock(&graph->lock);