Massive graph performance boost by checking to see whether an edge already
authorDavid Given <dg@cowlark.com>
Fri, 16 Dec 2016 23:21:27 +0000 (00:21 +0100)
committerDavid Given <dg@cowlark.com>
Fri, 16 Dec 2016 23:21:27 +0000 (00:21 +0100)
exists in the hash table before trying to add it.

modules/src/data/bigraph.c

index 1e6a841..4499563 100644 (file)
@@ -130,10 +130,16 @@ void graph_add_edge(struct graph* g, void* data1, void* data2)
     struct vertex* v1 = find_or_add_vertex(g, data1);
     struct vertex* v2 = find_or_add_vertex(g, data2);
     struct edgenode* e;
+       struct edgenode template;
 
        if (v1 == v2)
                return;
 
+       template.this = v1;
+       template.other = v2;
+       if (hashtable_contains(&g->edges, &template))
+               return;
+
     add_edge(v1, v2);
     e = add_edge(v2, v1);